-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial: Lines
sclin's program structure is rather strange. By default, the first line of each program runs; commands exist to allow programs to access and execute other lines.
Some examples - here, the first line runs and ends:
1 1+
2 2+
=> 2
Here, both lines run with the help of ;
, which executes the next line:
1 1+ ;
2 2+
=> 2 4
Basing program execution around lines enables some pretty cool abstractions. Program flow can weave between lines like so:
1 1+ ; 3 3+
2 2+
=> 2 4 6
Anonymous recursion is also effortless thanks to @
, which executes the current
line:
1;
dup 1+ @
=> 1 2 3 4 ...
HINT: Use the -v
("verbose") flag to see this stack grow recursively!
Same with mutual recursion, this time using ;;
to execute the previous line:
1 1+ ;
2 2+ ;;
=> 2 4 2 4 ...
I'm still not 100% sure why I kept this artifact of a design decision from lin, but I find it rather ergonomic to work with, and I find it to be a wonderful mechanic that meshes well with the sclin philosophy.
Made with ❤️ by Ben Pang (@molarmanful).