所以我的导师给我的任务是制作一个小函数来返回你的十二生肖的描述,但我对星座描述的最终输出有问题,输出仍然在括号中,我不知道不知道如何把它们弄出来。
(defparameter *month-signs* '((January Capricorn Aquarius 19 nil)
(February Aquarius Pisces 18 nil)
....)))
(defparameter *sign-traits* '((Capricorn (You are a goat be happy!))
....)))
(defun cookie (month-signs sign-traits)
(format t "Please input your month of birth followed by return, and then your day of birth.
e.g january <ret> 22 <ret> Thank You. ~%")
(let* ((month (read t));reads in month of birth
(day (read t));reads in day of birth
(month-assoc (assoc month month-signs)))
(cond
((>=(cadddr month-assoc)day);checks if your sign is the first part of the month
(format t "You are ~D~%" (cadr month-assoc));if it is, prints your sign and signs description
(format t "Your sign description is: ~D~%" (cadr(assoc(cadr month-assoc) sign-traits))))
((< (cadddr month-assoc)22);same as above but for the other sign
(format t "You are ~D~%" (caddr month-assoc))
(format t "Your sign description is: ~D~%" (cadr(assoc(caddr month-assoc) sign-traits)))))))
除了这个“(cadr(assoc(caddr month-assoc) sign-traits)”,它返回我想要的但在括号中并且全部大写。
CL-USER> (cookie *month-signs* *sign-traits*)
Please input your month of birth followed by return, and then your day of birth.
e.g january <ret> 22 <ret> Thank You.
january
12
You are CAPRICORN
Your sign description is: (YOU ARE A GOAT BE HAPPY)
我真的很难弄清楚我需要什么来摆脱最后一点的 (YOU ARE A GOAT BE HAPPY)
,我希望它只打印“你的标志描述是:你是一只快乐的山羊。”这可能是我错过的显而易见的事情:\
还有一件事 .... 只是为了您着想,因为变量很大并且会占用大量页面空间,我将其精简了,因为它们的布局方式相同。
最佳答案
在列表'(January Capricorn Aquarius 19 nil)
中,前三个元素是symbols,由REPL以大写形式打印出来。符号不同于字符串。当您引用这样的列表时,文字将被视为符号,而不是字符串。
类似地,'(You are a goat be happy!)
是一个包含六个符号的列表。它作为大写符号列表(括在括号中)打印出来。
如果用字符串替换符号和列表:
(defparameter *month-signs* '((January "Capricorn" "Aquarius" 19 nil)...
(defparameter *sign-traits* '((Capricorn "You are a goat be happy!")...
你应该得到你想要的输出。
read
将输入作为符号,因此您想将关联键(January)保留为符号。
关于lisp - 如何从此文本中删除括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33949025/