-
Notifications
You must be signed in to change notification settings - Fork 1
Syntax
Basic language syntax. This may change in the near future!
Like most programming languages, brackets are used in Sallied-Forth to define specific language features. These are defined in the base word-list and so could be redefined per application.
The current arrangement specifies that:
Anonymous functions are defined with fn{ and } as the delimiters. So, for instance,
99 fn{ dup + } exec .
would define a function that is then executed and printed out giving the result of '198'.
Arrays are defined using the square brackets [ & ]
[ 97 98 99 100 ]
which will result in a native JAvaScript Array being pushed on the stack.
This is a departure from other Forth based languages and is more in keeping with JavaScript and the like in the definition of sequential collections. As Sallied-Forth is a language to be used with JavaScript it is less confusing if the syntax characters behave similarly.
Objects are defined using the curly brackets { & }
{ a -99 b 27 }
which would produce a JavaScript Object on the stack as if you had defined one in JavaScript using:
var x = { a: -99, b: 27 };
again this syntax was chosen to closely mirror the JavaScript syntax and to provide less resistance in moving from one to the other.