IN C Design a read eval print loop REPL that can print out i

IN C++, Design a read eval print loop (REPL) that can print out information about a job pipeline that a user has described as input.

Solution

(Notice that the expression (write (eval (read))) does things in the proper read-eval-print order, because the argument to each procedure call is computed before the actual call. In Scheme, as in most languages, nested procedure calls expressions are done \"from the inside out.\")

I\'ve coded the iteration recursively, rather than using a looping construct. The procedure is tail-recursive, since all it does at the end is call itself. Remember that Scheme is smart about this kind of recursion, and won\'t build up procedure activation information on the stack and cause a stack overflow. You can do tail recursion all day. Since nothing happens in a given call to the procedure after the tail-call, Scheme can avoid returning to it at all, and avoid saving any state to return to.

The above read-eval-print loop isn\'t very friendly, because it loops infinitely without giving you any chance to break out of it. Let\'s modify it to allow you to stop the tail recursion by typing in the symbol halt.

Notice that this is still tail recursive, because the branch that does the recursive call doesn\'t do anything else after that.

This read-eval-print loop could be improved a little. By using the symbol halt as the command to tell the loop to stop, we prevent people from being able to evaluate halt as an expression. We could get around this by ensuring that the halt command doesn\'t have the syntax of any expression in the language, but we won\'t bother right now.

Another improvement would be to make it possible to use different interpreters with the same read-eval-print loop. The rep-loop procedure above assumes that it should call a procedure named eval to evaluate an expression. We\'d like to write a rep-loop that works with different evaluators, so instead of having it call eval by name, we\'ll hand it an argument saying which evaluator to use. Since procedures are first class, we can just hand it a pointer to the evaluation procedure.

IN C++, Design a read eval print loop (REPL) that can print out information about a job pipeline that a user has described as input.Solution(Notice that the exp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site