Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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
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