Code: Select all
(defparameter lookup-animal '((Cat . kitten) (Bear . cub) (Cow . calf)))
Code: Select all
(defun lookup-animal (name type)
(if (eq type 'old)
(setf name (car (assoc name lookup-animal)))
(if (eq type 'young)
(setf name (cdr (assoc name lookup-animal)))))
name)
Code: Select all
I run (lookup-animal 'Cat 'old) and it would output > CAT
I run (lookup-animal 'Cat 'YOUNG) and it would output > KITTEN
Here is another try ...It just prints "NAME" instead of the data...I'll still could use help figuring out how to preserve the case of the cons cell data.
Code: Select all
(defun lookup (name language o)
(if (eq language 'lisp)
(setf name (car (assoc name lookup)))
(if (eq language 'C++)
(setf name (cdr (assoc name lookup)))))
(setf (readtable-case *readtable*) :preserve)
(SETF O (SYMBOL-NAME 'NAME))
(SETF (READTABLE-CASE *READTABLE*) :UPCASE)
o)