Common Lisp lambda expression error

后端 未结 1 1894
礼貌的吻别
礼貌的吻别 2021-01-29 01:50

I am trying to make a program, which will rewrite given row without duplicates in an output row. I am using this website as a compiler: https://www.tutorialspoint.com/execute_li

1条回答
  •  有刺的猬
    2021-01-29 02:31

    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)))))
    

    0 讨论(0)
提交回复
热议问题