[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

2nd to the funcall problem

thanks for the audience, i got the following replys:

Date: Mon, 28 Apr 1997 11:29:53 -0400
From: Ken Olum <kdo@ctpa01.mit.edu>
To: Peter.Wehner@Masch-Bau.Uni-Magdeburg.DE
Subject: Re: return value of FUNCALL

Is there any possibility that you have confused the return value of
DOLIST, printed by the read-eval-print loop, with something output
from PRINT?  I'd say 

(let ((i 0))
  (dolist (runner *LISTE*)
    (format t "~&Return value ~D is ~S" (incf i) (funcall runner))))

to be sure you know what is going on.
Date: Mon, 28 Apr 1997 10:28:02 -0500 (CDT)
From: David Gadbois <gadbois@cyc.com>
To: peter.wehner@Masch-Bau.Uni-Magdeburg.DE
Subject: Re: return value of FUNCALL

   Date: Mon, 28 Apr 97 15:35:44 +0200
   From: Peter Wehner <wehner@Masch-Bau.Uni-Magdeburg.DE>

   i was reading winston/horn and steele, but nothing was said
   about FUNCALL multiple return values, at least FUNCALL return

It does, but the functions you are calling on the results only pick
the first value.  You could, say, package up the values with
MULTIPLE-VALUE-LIST and pass them around that way.

--David Gadbois

but it does'nt help me further. however, i of course did'nt read
ALL of the mentioned literature. David, please give me some
hint where to look up the subject. i'm using winston/horn (book,
3rd ed., 1993) and steele (html, 2nd ed. from cmu ai repository).

ok, i prepared a small and self-containing example to present my
problem as clear as possible (i hope ...).
there might be no need for further explanations, please see the
code as follows:

(defun d1 () T)   ;; just return T when called
(defun d2 () NIL) ;; return NIL (the default (defun d2 () ) is the same)

;; given a list of function-names iterate over it in DOLIST -
;; when any of the functions returned T, setf FIRED to T - when FIRED
;; is T than try it one more time in LOOP until CYCLES is exceeded
(defun try (&rest rules)
 (let ((fired nil) (count 1) (cycles 2))
   (dolist (runner rules)
    (setf fired (or fired (print (funcall runner))))) ;; printed

   (unless (and fired (< count cycles)) (return)) ;; break the loop
                                                  ;; in case
   (setf fired nil)
   (format t "~%Finished Cycle ~A - Trying again ...~%"
    (- (incf count) 1)))
  (format t "~%[finished after cycle ~A]. ~%" count))

now try the following calls to (try). does'nt it seem that DOLIST
breaks whenever fired is set to T or whatever?

>(try #'d2 #'d2 #'d2 #'d1 #'d2 #'d1)
;; gives
Finished Cycle 1 - Trying again ...

[finished after cycle 2]. 

;; and

>(try #'d2 #'d1 #'d2 #'d1)
;; gives
Finished Cycle 1 - Trying again ...

[finished after cycle 2]. 

so what's going on? the RETURN should not influence
DOLIST but LOOP as far as i can see.

thats it, peter

Dipl.-Ing. Peter Wehner 
Institut fuer Mechanik   Otto-von-Guericke-Universitaet Magdeburg 
Universitaetsplatz 2     D-39106 Magdeburg
Tel. 0391/67-12296       Fax. 0391/67-12439
e-mail : peter.wehner@mb.uni-magdeburg.de
www: http://comserv.urz.uni-magdeburg.de/~wehner/