Should be a lamba expression-LISP

天大地大妈咪最大 提交于 2019-12-11 19:50:06

问题


Just one function of my code:

(defun equalprev (x y)
  (cond ((or (atom x) (atom y))
         (if (not (null isLoop))
             t
           ((setq list1 (append list1 (list x)))
            (setq list2 (append list2 (list y)))
            (eql x y))))
        ((equalprev (car x) (car y))
         (equalprev (cdr x) (cdr y)))))

 

*** - SYSTEM::%EXPAND-FORM: (SETQ LIST1 (APPEND LIST1 (LIST X))) should be a lambda
expression
The following restarts are available:
ABORT          :R1      Abort main loop

Any help is appreciated


回答1:


The alternate expression for the 'if' expression is ((set! ...) ...). The first position needs to be either a function or a syntactic form. In this case you need progn as:

(progn
  (setq list1 ...)
  (setq list2 ...)
  (eql x y))



回答2:


Using de Morgan's laws you could construct your condition differently:

(not
 (when (null isLoop)
   (setq list1 (append list1 (list x)))
   (setq list2 (append list2 (list y)))
   (not (eql x y))))

avoiding the use of progn altogether (not that it's a bad thing, but it's often times frowned upon).



来源:https://stackoverflow.com/questions/10769861/should-be-a-lamba-expression-lisp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!