Can an OS Run with Just 8 Lines of Hyperlambda?
This article explains how the Hyperlambda‑based Phosphorus Five operating system achieves dynamic module loading and initialization with only a handful of declarative commands, demonstrating a minimalist approach to building extensible, modular software that can be extended by simply adding folders and startup files.
Hyperlambda’s core idea is a modular operating system that only needs to dynamically load and initialise installed modules. Apart from this simple function, everything else in a traditional OS becomes unnecessary bloat for micro‑controller environments.
The minimal operating system can be realised with just five declarative commands:
list-folders:/modules/</code>
<code>list-files:x:/@list-folders/*?name</code>
<code>filter:startup.hl</code>
<code>load-file:x:/-/*?name</code>
<code>eval:x:/-/*These commands list all folders under /modules/, locate files named startup.hl inside each folder, load the listed files and then evaluate them. By copying a new module (a folder containing a startup.hl file) into /modules/, the OS instantly gains the module’s functionality, with typical start‑up times measured in a few hundred milliseconds.
Hyperlambda treats functions as simple strings (Active Events), allowing modules to call each other without static dependencies. New functions can replace existing ones without breaking existing code, and function signatures can be altered, providing polymorphic behaviour without inheritance, interfaces, or OOP.
Below is a more detailed initialisation script that evaluates all startup.hl files, ensuring that core modules such as “micro” and “desktop” are loaded first so other modules can rely on their features:
/* Initialises Phosphorus Five. */
/* Loading all "startup.hl" files from all modules in system. */
list-folders:/modules/
list-files:x:/@list-folders/*?name
filter:startup.hl
/* Evaluating all files from above result, to make sure we initialise all modules. */
/* 1. Micro's startup files */
/* 2. Desktop's startup files */
/* 3. All other startup files in undetermined order */
load-file:x:@"/@list-files/*(/"~/micro/"|/"~/desktop/")?name"
eval:x:/-/*
set:x:@"/@list-files/*(/"~/micro/"|/"~/desktop/")"
load-file:x:/@list-files/*?name
eval:x:/-/*Only three extra lines were added to the original five to explicitly load the “micro” and “desktop” modules, but these can be removed without breaking the core system, behaving like a function(){} call.
The same approach can be used to build web‑ or desktop‑level operating systems, even swapping simple C# assemblies for Hyperlambda code to create WinForms or Xamarin applications.
To create a new module, simply add a folder with a startup.hl file; this mirrors traditional library or COM module creation. Modules can also be stored in MySQL because Hyperlambda is just a file format, requiring only that the load-file call be swapped for a database‑load equivalent.
The entire OS can be found on GitHub (https://github.com/polterguy/phosphorusfive) and runs with only eight lines of code.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
