Question
2. Using LISP, code the macro, iterate , which is based on the following: ( iterate controlVariable beginValueExpr endValueExpr incrExpr bodyexpr1 bodyexpr2 ... bodyexprN )
2. Using LISP, code the macro, iterate, which is based on the following:
(iterate controlVariable beginValueExpr endValueExpr incrExpr bodyexpr1 bodyexpr2 ... bodyexprN)
iterate is passed a controlVariable which is used to count from beginValueExpr to endValueExpr (inclusive) by the specified increment.
For each iteration, it evaluates each of the one or more body expressions.
Since beginValueExpr, endValueExpr, and incrExpr are expressions, they must be evaluated.
The endValueExpr and incrExpr are evaluated before processing the rest of the macro. This means the code within the user's use of the macro cannot alter the termination condition nor the increment; however, it can change the value of the controlVariable.
The functional value of iterate will be T.
You can create an intermediate variable named endValue for the endValueExpr. You can create an intermediate variable named incValue for the incrExpr. For 2 points bonus, use gensym to generate the name of those two variables.
HERE ARE A FEW EXAMPLES OF WHAT IT WOULD NEED TO DO.
Examples:
1. > (iterate i 1 5 1
(print (list 'one i))
)
(one 1)
(one 2)
(one 3)
(one 4)
(one 5)
T
2. > (setf n 5)
5
> (iterate i 1 n 1
(print (list 'two i n))
(+= i 1)
)
(two 1 5)
(two 3 5)
(two 5 5)
T
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started