Question
In LISP, code the macro, SELECT, which uses the following syntax: (select expr (when ( valueList1 ) ( stmt11 ) ... ( stmt1N ) )
In LISP, code the macro, SELECT, which uses the following syntax:
(select expr
(when (valueList1)
(stmt11)
...
(stmt1N) )
(when (valueList2)
(stmt21)
...
(stmt2N) )
...
(default
(stmtd1)
(stmtd2)
...
(stmtdN) ) )
Example:
(select grade
(when (A B)
(setf good (+ 1 good))
(print "doing well")
)
(when (C)
(print "average")
)
(when (D F)
(setf bad (+ bad 1))
(print "oh no")
)
(default
(print (list "unknown value=" grade))
)
)
If the value of expr matches a value in a valueList, each of the corresponding stmt expressions are executed (i.e., eval). The result of the select would be the last stmtn executed.
If the value of expr didn't match a value in any of the valueList and a default is provided, each of the stmt(s) corresponding to the default are executed. The result of the select would be the last stmtn executed.
If the value of expr didn't match a value in any of the valueList and a default is not provided, switch should return NIL.
Note that the values in each valueList are not evaluated.
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