Chaos is a very simple stack-based language designed mainly as a testbed for ColdStore.
In keeping with this, Chaos is able to generate calls to all of the elements of the ColdStore virtual protocol on the objects it creates. It could also function as a nanocode level programming environment for ColdStore.
Chaos has a very simple syntax:
Chaos' semantics are also simple.
Evaluates TOP as the name of a function, example
"func" 'fn
Evaluates TOP as a boolean, then evaluates one of UNDER or SWAP UNDER as a functional.
"expr-false" "expr-true" varname 'if
The stack is reduced by 3 elements.
Repeatedly evaluates TOP as a boolean, then evaluates UNDER as a functional
"body" varname 'while
The stack is reduced by 1 element, the body of the while is pushed back. Note that the body should regenerate a condition for the next iteration of 'while.
Evaluates TOP as a Chaos expression.
The stack is reduced by 1 element then modified as per the eval'd expression.
"'view" 'eval
Evaluates TOP as a Chaos expression in a new interpreter, with a new stack. When the expression has been evaluated, the resultant stack is pushed onto the current stack. Since stacks are ColdStore Lists, this affords one method of creating List objects.
"1 2 3 4" 'scope
The stack is reduced by 1 element then increased by the scoped interpreter.
Duplicate the TOP element of the stack
Reduce the stack by one, discarding TOP
Swap TOP and UNDER
Render the stack in human readable form.
Render the stack in detailed human readable form.
Push a copy of namespace containing variable definitions
BEWARE: if you 'dump or 'view while a 'names value is on the stack, Chaos *will* loop forever because the 'names entry contains a copy of Chaos, which contains a copy of the 'names entry. I've no idea how to stop it, short of SIGINT or letting it consume all available memory :)
However, you can use the fact that the value of the variable Chaos is always the main Chaos interpreter, which is also its Lexer and its stack (as a List), to do some useful introspection:
"Chaos" 'names 'slice 'length - should be the length of the stack.
It's not recommended to modify the value of Chaos.
Push the current Chaos interpreter (which may or may not be the same as the value of Chaos) onto itself. Again, it's unwise either to 'view the stack, or modify it.
Push the namespace containing all Registered Builtins
Replace TOP with its ColdStore truth value.
Replace TOP with a String representing its object type.
Replace TOP with a flattened sequence representation. This representation can be used as an argument to 'new to recreate the object.
Predicate: does TOP support the Sequence protocol?
Predicate: does TOP support the Iterator protocol?
The following operators have their usual ColdStore definition, and replace TOP, or TOP and UNDER, for
This will call the nominated Builtin with TOP as its argument. This will likely SigSegv.