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

Discussion of Common Lisp
Post Reply
yougene
Posts: 23
Joined: Thu Jan 21, 2010 1:23 pm

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

Post by yougene » Wed Feb 03, 2010 8:05 pm

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

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

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

Post by nuntius » Wed Feb 03, 2010 8:23 pm

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)

yougene
Posts: 23
Joined: Thu Jan 21, 2010 1:23 pm

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

Post by yougene » Wed Feb 03, 2010 8:41 pm

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

edit: grammar

Post Reply