Getting values from a DEFCONSTANT in LISP -


there defconstant statement:

(defconstant *contant2* ’((allan 4) (zols 5) (milo 2) (judh 0))) 

i want take separated constant name , value associated name. how can that?

give taste scores:((name-1 score-1) ... (name-n score-n)) argument, lisp functions avare score , other generate word scores (9-10 verygood, 7-8 good). (defconstant contant2 ’((allan 4) (zols 5) (milo 2) (judh 0)))

i appreciate help! thanks.

to answer direct question:

? (mapcar #'car *cookie-scores*) (john mary mike jane) ? (mapcar #'cadr *cookie-scores*) (8 9 1 0) 

in loop, can use loop's destructuring:

for (name val) in 

other options available; here's 2 example implementations of required functions leave uncommented; please ask questions, or show code.

(defun average-score (lst)   (/ (reduce #'+ lst :key #'cadr) (length lst))))  ? (average-score *cookie-scores*) 9/2 

and

(defun word-scores (lst)   (loop      (name val) in lst     collect (list name                   (cond                    ((> val 8) 'excellent)                    ((> val 6) 'tasty)                    ((> val 0) 'terrible)                    (t         'garbage)))))  ? (word-scores *cookie-scores*) ((john tasty) (mary excellent) (mike terrible) (jane garbage)) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -