This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

on dolist..

5 posts · 3797 views

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:
(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..

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

thanks!

Re: on dolist..

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

Re: on dolist..

good, thanks ;)