Consider augmenting a RPN calculator with the ability to push functions onto the stack, not just values. What needs to be made available to make it a nice programmable calculator?
- Eval
- Function-make, a function that consumes a bunch of objects on the stack and squashes them into a lambda function that is pushed back onto the stack. This lambda can then be Eval'd, consuming values further up the stack. Tricky might be how function-make determines how many stack objects to consume. In Lisp, the end of a lambda is demarcated with a close parenthesis.
- A means to provide a function -- a local scope -- with a fresh bunch of registers, pushing the old registers onto a stack, probably a separate stack from the main stack. The function arguments can then be copied into the new registers and randomly accessed by register name within the function. Pop the old registers back when the function exits.
No comments :
Post a Comment