lisp - 不是数字原子 LISP

标签 lisp common-lisp

我想问一下为什么这个功能不起作用...

(defun nenum(ls)
  (cond
   ((null ls) nil)
   ((listp car(ls)) (nenum (rest ls))) 
   ((numberp car(ls)) (nenum (rest ls)))
   (t (cons (car ls) (nenum (rest ls))))))

示例:(nenum '(l 1 i (b) (5) s -2 p)) --> (li s p)

谢谢!

最佳答案

查看您在其中一个条件项中的谓词:

(listp car (ls))

因此应用带有两个参数 car 的函数 listp 和不带参数调用函数 ls 的结果。 carls 都需要是自由变量,listp 需要是与 defined in CLHS 不同的函数。因为它只需要一个参数。

也许您在编写 Algol 时有过这样的经历? Algol 函数调用看起来像 operator(operand) 但不是 CL。 CL 是一种 LISP 方言,我们在函数调用中采用这种形式:

(operand operator)

如果我们嵌套我们做同样的事情:

(operand (operand operator))

你在替代方案中做对了 (cons (car ls) (nenum (rest ls)))

关于lisp - 不是数字原子 LISP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30037411/

相关文章:

lisp - 使用 hunchentoot 和 sbcl 从网络获取 lisp 输入时遇到问题

compiler-construction - 是否有Lisp native 代码编译器?

functional-programming - xappings, xectors, xets

user-interface - Common Lisp 图形用户界面开发

emacs - Windows 7 上的史莱姆

lisp - 为什么将 "(null x)"替换为 "(null (cdr x))"会使此代码有效?

lisp - 在 Common Lisp 中连接两个列表

lisp - 用于过滤列表并将函数应用于未过滤元素的 Common Lisp 习惯用法?

lisp - Common Lisp 中最大的子列表

common-lisp - 如何理解:常见的Lisp defstruct中的print-function