I am working through a project as a means to better understand Scheme. The goal of my scheme project is to take the input on the left of the following arrow and produce the output that is on the right side:
(* (+ 1 a) (+ 1 a))
==>
(let* ((g128572 (+ 1 a)))
(* g128572 g128572))
To detail exactly what needs to happen within the program, a let* needs to be generated. The bindings of the let will be a series of randomly generated 'variable' strings which has a value associated with it. That value is derived from the left side of the input. Anything that appears more than once will appear within the let bindings. The body of the let will be the expression with the variable name inserted instead of the expression.
My question is the following:
Is it only possible to return it in the form that the following code returns?
(define (example)
(cons 'let* (cons '((g128572 (+ 1 a)))
(cons '(* g128572 g128572)
'()))))
Where the return value is '(let* ((g128572 (+ 1 a))) (* g128572 g128572))
, which is technically a list and would need to be in the form (eval '(let* ((g128572 (+ 1 a))) (* g128572 g128572)))
in order to actually evaluate, or can I actually return the function itself, where all I would need to have is (let* ((g128572 (+ 1 a))) (* g128572 g128572))
, which would successfully run and evaluate by itself?
Hopefully I am clear in what I am asking.
(+ a 1)
and(+ 1 a)
in your example? – rajashekar