LISP function fails and returns NIL when making a list of Nth items of other lists
I need to make a named function, which makes a new list from the 3rd item from three master lists. I made this code
(defun func (nth n))
(lambda (l1 l2 l3) '(H G (U J) (T R)) '(2 1 (+ 4 5)) '(TYPE CHAR REAL (H G)))
(write (func (lambda (l1 l2 l3) '(H G (U J) (T R)) '(2 1 (+ 4 5)) '(TYPE CHAR REAL (H G))) 2))
but it returns NIL. What do I do wrong?
Solution 1:
You need to indent and format your code. Otherwise it's an unreadable blob of characters.
Here is what you have:
Your function func
takes two arguments and does nothing. It always returns NIL.
Then there is a lambda expression which takes three arguments. It uses none of them. It has three body expressions. The first two are not used and the third is being returned.
The third expression calls the function func
, which always returns NIL. WRITE
then prints this NIL.
Your code, but formatted readably for humans, looks like this:
(defun func (nth n)
; no functionality, does nothing and returns NIL
)
(lambda (l1 l2 l3)
'(H G (U J) (T R))
'(2 1 (+ 4 5))
'(TYPE CHAR REAL (H G)))
(write (func (lambda (l1 l2 l3)
'(H G (U J) (T R))
'(2 1 (+ 4 5))
'(TYPE CHAR REAL (H G)))
2))
Hint: you would need to write actual functionality.