Printing


Instead of printing the tree, we now want to print the result of the evaluation. Therefore we need to pass the tree into our eval function, and print the result we get using printf and the specifier %li, which is used for long type.

We also need to remember to delete the output tree after we are done evaluating it.

  1. long result = eval(r.output);
  2. printf("%li\n", result);
  3. mpc_ast_delete(r.output);

If all of this is successful we should be able to do some basic maths with our new programming language!

  1. Lispy Version 0.0.0.0.3
  2. Press Ctrl+c to Exit
  3. lispy> + 5 6
  4. 11
  5. lispy> - (* 10 10) (+ 1 1 1)
  6. 97