This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

How do I return a list without performing a function on it?

3 posts · 1154 views

If I want to return a list or nil how do I do that? If I just try to put the name of the list or nil on the last line, lisp tells me it's not a function. I've been using the print function but that isn't going to cut it anymore.

For example
(defun goalp (state)
           (let ((x state))
             (loop for i from 0 to 7 do
                   (if (not(equal (+ i 1) (nth i state)))
                       (setf x nil)
                       (print nil)))
             (print x)))

Re: How do I return a list without performing a function on it?

Is this what you want?
(defun goalp (state)
           (let ((x state))
             (loop for i from 0 to 7 do
                   (if (not(equal (+ i 1) (nth i state)))
                       (setf x nil)
                       (print nil)))
             x))

;; example run
;* (goalp (list 1 2 3 4 5 6 7 8 9))
;(1 2 3 4 5 6 7 8 9)

Re: How do I return a list without performing a function on it?

Yeah, that fixes it. I think I was putting my variables in parentheses.

edit: grammar