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_lisp_online.php
And here is my code
(SETQ X (LIST 2 -3 (LIST 4 3 0 2) (LIST 4 -4) (LIST 2 (LIST 2 0 2))-3))'
(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))
)
)
)
)
(DEFUN REMDOUBLES (INPUT OUTPUT)
(
(COND
((NULL INPUT) NILL) ;recursion exit
(T ; funstion
(OR ; step into or go forward
(COND
((ATOM (CAR INPUT)) (COND
((NOT (SEARCHDEEP (CAR INPUT) OUTPUT)) (APPEND OUTPUT INPUT)) ;if this atom wasn't added => append
)
)
(T (REMDOUBLES (CAR INPUT) OUTPUT)) ; step into (car input => list
)
(REMDOUBLES (CRD INPUT) OUTPUT) ; go forward, car input is anatom
)
)
)
)
)
(SETQ OUT (QUOTE)) ;Empty row
(REMDOUBLES X OUT)
(PRINT OUT)
I have spent last 2 hours checking this code and other answers here, on stack, however I have no clue what am I missing here.
I am getting this error:
*** - SYSTEM::%EXPAND-FORM:
(COND ((NULL INPUT) NILL)(T(OR (COND ((ATOM (CAR INPUT)) (COND ((NOT (SEARCHDEEP (CAR INPUT) OUTPUT))(APPEND OUTPUT INPUT)))) (T (REMDOUBLES (CAR INPUT) OUTPUT))) (REMDOUBLES (CRD INPUT) OUTPUT)))) should be a lambda expression
Sorry for the formatting, I am novice in Functional Programming and Lisp, and I have no idea how it should be done properly.
Your code:
First line:
Second line: Can you explain what the single parentheses should do?
You remember the Lisp syntax for basic Lisp expressions?
It's not
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:
This is the formatted code:
But it would be even better written as: