【发布时间】:2013-04-15 16:11:32
【问题描述】:
我正在尝试自学一些 LISP,虽然我了解其中的大部分内容,但我无法掌握 eval 函数。我知道它已经为我们做了它,而且它不好用(所以我听说),但是我如何制作一个只是添加的功能?
到目前为止,我一直在尝试/思考
(setf input-prompt "Enter addition epression: ")
(setf output-prompt "The value is: ")
(defun prompt-for-input (msg)
(format t msg))
(defun sum (expression)
(format t "Summing ~d and ~d.~%" x y)
(+ x y))
(defun add ()
(prompt-for-input input-prompt)
(let ((expression (read)))
((sum (expression)))
(add)))
不太确定在哪里进行此操作,感谢您提供任何帮助。
【问题讨论】:
-
你想做什么?听起来您想根据您阅读的表达式调用不同的函数,而不使用
eval。这基本上是在编写一个小型解释器,这是大多数 Lisp 书籍(Lisp Schemer 等)中涵盖的内容。但是,如果您能更清楚地描述您的问题,将会有所帮助。
标签: lisp common-lisp