Common Lisp lambda expression error

感情迁移 提交于 2019-12-02 10:38:16

Your code:

First line:

(DEFUN REMDOUBLES (INPUT OUTPUT)

Second line: Can you explain what the single parentheses should do?

(

You remember the Lisp syntax for basic Lisp expressions?

(operator argument0 argument1 ... argumentn)

It's not

((operator argument0 argument1 ... argumentn))

Sorry for the formatting, i am novice in functional programming and LISP, and i have no idea how it should be done properly.

Download the introductory Lisp book from Touretzky: https://www.cs.cmu.edu/~dst/LispBook/

Then learn there how Lisp code looks like.

You can also use Lisp to format the code for you:

This is your unformatted code:

[4]> (pprint '(DEFUN SEARCHDEEP (WHAT WHERE) ;Function will find out if atom `WHAT`is in a row `WHERE` => works fine
(COND
    ((NULL WHERE) NIL)
    (T (OR 
            (COND 
                ((ATOM (CAR WHERE)) (EQUAL WHAT (CAR WHERE)))
                (T (SEARCHDEEP WHAT  (CAR WHERE)))
            )
            (SEARCHDEEP WHAT (CDR WHERE))
        )
    )
)
))

This is the formatted code:

(DEFUN SEARCHDEEP (WHAT WHERE)
 (COND ((NULL WHERE) NIL)
  (T
   (OR
    (COND ((ATOM (CAR WHERE)) (EQUAL WHAT (CAR WHERE)))
     (T (SEARCHDEEP WHAT (CAR WHERE))))
    (SEARCHDEEP WHAT (CDR WHERE))))))

But it would be even better written as:

(DEFUN SEARCHDEEP (WHAT WHERE)
  (WHEN WHERE
    (OR (IF (ATOM (CAR WHERE))
            (EQUAL WHAT (CAR WHERE))
          (SEARCHDEEP WHAT (CAR WHERE)))
        (SEARCHDEEP WHAT (CDR WHERE)))))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!