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

Discussion of Common Lisp

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

Postby 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)))
yougene
 
Posts: 23
Joined: Thu Jan 21, 2010 1:23 pm

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

Postby 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)
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

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

Postby yougene » Wed Feb 03, 2010 8:41 pm

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

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


Return to Common Lisp

Who is online

Users browsing this forum: Bing [Bot] and 6 guests