Preserve the case of cons cell data
Posted: Thu Mar 20, 2014 7:47 pm
I have a variable of a list of cons cells here?
Here is the function I use to parse through them
The issue is I would like the name variable at the bottom of the list of defun lookup-animal to preserve the case of the animal list for example, Cat should print Cat not CAT, and Bear should print as Bear not BEAR. I looked over the internet for 3 hours and got nada...I got uppercase, lowercase no preserve case..
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.
.so if anyone can help me in the code above preserve the case of the output of the final variable name in the function lookup-animal while keeping it the red color of a PRINC not the pinkish color of FORMAT..I would really grateful..
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)