Skip to content
EricGebhart edited this page Aug 21, 2021 · 4 revisions

Eval

Because SPR code has no real syntax, it's easy for it to be data. Eval lets us execute data.

Because of that, we can create functions. Which, is a current pain point. That this works is just magical, it wasn't on purpose.

The pain, is and was on purpose. That every step must resolve to a do-list which ultimately boils down to python functions.

That means that something very specific like pop results foo would have to have a name like res-to-foo or something, cluttering up the namespace with a million one liners.

It would be much better to have a single symbol with 2 or more steps. so here we go. A Magical feature, just works.

For real.

So a little bit of rearranging, along with the addition of gensyms, we can now define functions using inline yaml syntax.

def foo "this is a test, to make a function with yaml"
'
- cli/msg hello
- cli/msg gooodbye

One weirdness, since the yaml sub parser looks for 2 blank lines to end, and the regular parser looks for one blank line, we need 3 blank lines between to keep the parser from sucking up the next thing. Great if you like whitespace..

def foo "this is a test, to make a function with yaml"
'
- cli/msg hello
- cli/msg gooodbye



def functest "We can make functions with yaml"
'
- cli/msg
- cli/msg Goodbye

Currently, the yaml will be stored in gensyms with a uuid, the defined symbol will have the gensym as it's function which will be looked up and executed at runtime. The current gensym/source code will show up in ls and show, as well as in help, with varying degrees of transparence.

Creating functions.

This is just some of the entertaining things that come about. it turns out, that because eval knows how to process a list of commands, and because we can easily create lists, we can then easily create a sequence of things to be done and do them. Our code is data, our data is code.

This session creates a dataspace/folder/dictionary at /foo and pushes it on the with stack. It then creates entries for msg, bar, and baz. Notice that bar is spr code, and baz is a yaml list of spr code.

with and show show what is there.

Then we get a bunch of messages, in different ways. De-referencing and executing the data.

SPR:> with /foo

SPR:> '
YAML...>msg: this is my message. Hello.
YAML...>bar: cli/msg /foo/msg
YAML...>baz:
YAML...>- cli/msg /foo/msg
YAML...>- cli/msg Hello from the middle
YAML...>- cli/msg /foo/msg
YAML...>- cli/msg Goodbye.
YAML...>

SPR:> with
/foo
-------------------------
    msg                           
    bar                           
    baz                           

SPR:> ls /
    config                        
    args                          
    defaults                      
    platform                      
    _with_                        
    _Root_                        
    device                        
    network                       
    markdown                      
    readme                        
    foo       

SPR:> show /foo
/foo
bar: cli/msg /foo/msg
baz:
- cli/msg /foo/msg
- cli/msg Hello
- cli/msg /foo/msg
- cli/msg Goodbye.
msg: this is my message.

SPR:> pop-with


# not in kansas anymore.
SPR:> with
/
-------------------------
    config                        
    args                          
    defaults                      
    platform                      
    _with_                        
    _Root_                        
    device                        
    network                       
    markdown                      
    readme                        
    foo     

# The same thing two ways...

SPR:> cli/msg /foo/msg
this is my message.
Press any key to continue;

SPR:> with /foo cli/msg
this is my message.
Press any key to continue;

SPR:> eval /foo/bar
this is my message.
Press any key to continue;

SPR:> eval /foo/baz
this is my message. 
Press any key to continue;
Hello
Press any key to continue;
this is my message.
Press any key to continue;
Goodbye.
Press any key to continue;

Clone this wiki locally