Question: Implement an enum facility as a Common Lisp macro , defenum, to add functionality ( similar to Java's enum types.) Specfically, the following shows the
Implement an enum facility as a Common Lisp macro, defenum, to add functionality ( similar to Java's enum types.)
Specfically, the following shows the code expansion of the defenum macro with various arguments. Your defenum must macroexpand to exactly the same code expansion. For this assignment, you are not allowed to use any iteration constructs in your code.
(macroexpand '(defenum (day number) (Sunday 0) (Monday 1) (Tuesday 2) (Wednesday 3) (Thursday 4) (Friday 5) (Saturday 6))) (PROGN (DEFCONSTANT DAY->NUMBER->SUNDAY 0) (DEFCONSTANT DAY->NUMBER->MONDAY 1) (DEFCONSTANT DAY->NUMBER->TUESDAY 2) (DEFCONSTANT DAY->NUMBER->WEDNESDAY 3) (DEFCONSTANT DAY->NUMBER->THURSDAY 4) (DEFCONSTANT DAY->NUMBER->FRIDAY 5) (DEFCONSTANT DAY->NUMBER->SATURDAY 6) (LET ((DAY->NUMBER '((0 . SUNDAY) (1 . MONDAY) (2 . TUESDAY) (3 . WEDNESDAY) (4 . THURSDAY) (5 . FRIDAY) (6 . SATURDAY)))) (DEFUN DAY->NUMBER (NUMBER) (CDR (ASSOC NUMBER DAY->NUMBER)))))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
