on dolist..

Discussion of Common Lisp
Post Reply
megera
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm

on dolist..

Post by megera » Fri Oct 12, 2012 6:49 am

HI
I'm very newbie also in programming, and I'm trying to learn CL :D
ok, I have just a problem with this exercize that ask me : "define a function that takes a list as an argument and returns true if one of its elements is a list.

OK,I just studied dolist, then:

Code: Select all

(defun use_dol (lst)
	   (dolist (x lst)
	     (if (listp x)
		 t)))

(use_dol  '(a b '(c d) e))
but NIL raise...why? ther's a nested list in list arg for use_dol func... I can't understand why! :cry:
thanks in advance for help!

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: on dolist..

Post by edgar-rft » Sat Oct 13, 2012 11:35 pm

DOLIST returns NIL as long as there is no explicit RESULT-FORM defined. See the the examples on the DOLIST page what this means.

- edgar

megera
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm

Re: on dolist..

Post by megera » Sun Oct 14, 2012 1:27 am

thanks!

Paul
Posts: 106
Joined: Tue Jun 02, 2009 6:00 am

Re: on dolist..

Post by Paul » Sun Oct 14, 2012 5:14 pm

(if (listp x) t) doesn't terminate the loop; it just keeps looping, and eventually returns nil. Use (return t)

megera
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm

Re: on dolist..

Post by megera » Mon Oct 15, 2012 7:42 am

good, thanks ;)

Post Reply