Add functions and function calls to your MSDscript implementation, including the parser, interpreter, and printer.
has_variable
method from your expression class, since it's not useful.print
, always put a _fun
expression in parentheses, include exactly one space around the outside of the parentheses for the argument, and include no space inside the parentheses. Never print a pair of parentheses around a function call (because it turns out that's not necessary), and include no space on the outside or inside edges of the parentheses around the argument in a function call.pretty_print
, if you have it, _fun
expressions need parentheses in the same contexts where _let
would need parentheses. Add a newline after the argument parentheses for _fun
and indent the body two spaces more than the column where _fun
starts. A function call never needs extra parentheses. As an example, the implementation of factorial below is correctly pretty-printed.Here's a program that you can try out on your interpreter to compute 10!, which is 3628800:
_let factrl = _fun (factrl)
_fun (x)
_if x == 1
_then 1
_else x * factrl(factrl)(x + -1)
_in factrl(factrl)(10)