mattbierner / atum

Javascript Interpreter in Functional-Style Javascript
MIT License
19 stars 2 forks source link

Support Expression of Semantics that effect state on creation. #136

Closed mattbierner closed 11 years ago

mattbierner commented 11 years ago

An additional layer should be added to support semantics that changed program state when they are created. An example would be labels. The label itself has no effect on running code but when the label is created, it introduces a block of labeled code into the program state.

The issue is that current attempts result in expressions that are evaluated on every run, not just once for creation:

var label = function(id, body) {
    return next(createLabel(id), body);
}; 

Really, the behavior is more:

var label = function(id, body) {
    return next(createLabel(id), just(body));
};

where the outer is run when label is initialized, producing the inner evaluation logic which is run later.

mattbierner commented 11 years ago

Supported although labels have not been added yet.

Also, the implementation is a bit ugly, requiring a first monad pass to create the actual program pipeline and then performing a bounce operation to dispatch into the actual program behavior (threading the value result of a monad onto itself).

Arrows seem like they offer some good ideas for this but they are far to general for this application.ew