Page 1 of 1

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

Posted: Wed Feb 03, 2010 8:05 pm
by yougene
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

Code: Select all

(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?

Posted: Wed Feb 03, 2010 8:23 pm
by nuntius
Is this what you want?

Code: Select all

(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?

Posted: Wed Feb 03, 2010 8:41 pm
by yougene
Yeah, that fixes it. I think I was putting my variables in parentheses.

edit: grammar