on dolist..

Discussion of Common Lisp

on dolist..

Postby 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!
megera
 
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm

Re: on dolist..

Postby 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
edgar-rft
 
Posts: 147
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: on dolist..

Postby megera » Sun Oct 14, 2012 1:27 am

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

Re: on dolist..

Postby 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)
Paul
 
Posts: 106
Joined: Tue Jun 02, 2009 6:00 am

Re: on dolist..

Postby megera » Mon Oct 15, 2012 7:42 am

good, thanks ;)
megera
 
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 1 guest