Question: Pgm3 Lisp Macros Code the macros listed below and use the specified test cases. Notes: You can only use the functions/macros we discussed in the

Pgm3 Lisp Macros

Code the macros listed below and use the specified test cases.

Notes:

You can only use the functions/macros we discussed in the LISP notes or ones you create for program 2 or program 3.

Load your code using (load "p3Lisp.txt" :echo T :print T). To execute on the test cases using the file I provided, (load "p3LispRun.txt" :echo T :print T)

Your functions must be executed on a fox server using the specified test cases.

1. Code the macro, -=, which is passed a variable which it decrements by the decrementValue and assigns the new value. The function value returned by -= should be the new value of numericVariable.

(-= numericVariable decrementValue)

Example:

> (setf x 5)

5

> (-= x 1)

4

> x

4

CLISP sometimes gives an error like the following when you LOAD a file with that macro definition:

# is locked

if you continue (by typing 'continue'): Ignore the lock and proceed

To ignore that message, simply type

CONTINUE

2. 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!