2 ms·
Stoical is an older forth with an interesting twist. 'string is a quoted string that is terminated by a space. Colon takes a string parameter, to avoid a lot of
by mikewarot 4y ago
Stoical is an older forth with an interesting twist. 'string is a quoted string that is terminated by a space. Colon takes a string parameter, to avoid a lot of "compile mode" nonsense.
To define the cube function
'cube : dup dup * * ;
- teddyh 4y ago> 'string is a quoted string that is terminated by a space. Sounds like LISP symbols, which have the same syntax, are also essentially strings, and are also used to refer to names of function and variables.
- kragen 4y agothis is a great idea, among other things because it puts the name you're defining in the left margin where it's easiest to scan to, but i don't see how it avoids any compile-mode nonsense. in this line of code, 'cube still has to push the string on the stack at compile time, and : has to consume it at compile time, while dup just has to compile some code into the colon definition, which at least strongly suggests that the interpreter is being run in a different mode that compiles things like dup instead of executing them? https://stoical.sourceforge.net/summary.php https://stoical.sourceforge.net/summary.php https://sourceforge.net/projects/stoical/files/stoical/0.1.8/ https://sourceforge.net/projects/stoical/files/stoical/0.1.8... some example code % %(var) 1+! % Increment the variable addressed by TOS. % % '1+! : dup @ 1+ swap ! ; % %(math) hex % Set radix to hexadecimal. % % 'hex : 16 radix ! ; % %(io) cr % Output a newline. % % 'cr : '\n = ; % %(io) space % Output a space. % % 'space : 32 put ; % ----- define the more traditional interface to flow control. % %(conditional) if (*) % "n IF ... then" % Conditionaly execute the instructions. The instructions following IF will be % executed if TOS is not FALSE upon invokation. % % 'if : () if{ exec ; immediate it seems to be dynamically-typed and garbage-collected?