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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!