Code Transformation by Desugaring
Subtraction; Code Transformation by Desugaring
- Since last week's class, you added some other binary arithmetic operators to your interpreter. Did you find a way to abstract over them to make your code tidier and more modular?
Our arithmetic operators are all binary; each one takes exactly two arguments.
(* 2 3)
If you check the Racket documentation you will see that many of these operators can take an arbitrary number of arguments.
> (* 2 3) 6 > (* 2 3 4) 24 > (* 2 3 4 5) 120 > (* 2) 2 > (*) 1 >
We could adapt our interpreter to accept such variadic operators in two ways.
- We could code this up in the basic interpreter.
- We could transform n-ary calls where \(n>2\) into a sequence of binary calls.