Page 1 of 1

on dolist..

Posted: Fri Oct 12, 2012 6:49 am
by megera
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!

Re: on dolist..

Posted: Sat Oct 13, 2012 11:35 pm
by edgar-rft
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

Re: on dolist..

Posted: Sun Oct 14, 2012 1:27 am
by megera
thanks!

Re: on dolist..

Posted: Sun Oct 14, 2012 5:14 pm
by Paul
(if (listp x) t) doesn't terminate the loop; it just keeps looping, and eventually returns nil. Use (return t)

Re: on dolist..

Posted: Mon Oct 15, 2012 7:42 am
by megera
good, thanks ;)