小编Adi*_*ala的帖子

LISP中的计数器变量

定义带有列表L和符号A的函数'occ',并计算L中符号A的出现.例如:(occ'(((s)o)d)'f) - > 0

到目前为止我得到了什么:

(defun occ(list a)
(setq counter 0)
  ;Checks if the given list is has an nested list
  (if (consp list)
    ; Breaking the list down atom by atom and recursing
    (or (occ a (car list))
        (occ a (cdr list)))
    ; checks if symbols are the same
    (if(eq a list)
        (setq counter(1+ counter)))))
Run Code Online (Sandbox Code Playgroud)

但是我的输出继续说Nil而不是显示计数器值.我不能使用任何更高级别的LISP功能.

lisp math common-lisp

1
推荐指数
1
解决办法
1214
查看次数

标签 统计

common-lisp ×1

lisp ×1

math ×1