I think you'll find that any of the loops below will work fine in a
context where "return" has a defined meaning: in particular, in a
deffunction or the RHS of a defrule. I could weasel out of this by
calling this "undefined behavior", as returning from a loop at the
prompt has no useful meaning -- there's no higher level to return to.
But thanks for the report -- return should just be equivalent to
"break" when called in a context like this, so this should be fixed.
On Jun 11, 2007, at 3:42 AM, Wolfgang Laun wrote:
Jess Version 7.0p1 12/21/2006
Using return to break a (for) or (foreach) is documented behaviour.
(It isn't for (while), but perhaps this is just an omission in the
documentation.)
However:
;; Using return to exit from a loop confuses Jess.
;; Loops won't work any more. A (clear) appears to remove the fault.
;; for + return
(for (bind ?i 0) (< ?i 5) (++ ?i)
(if (= ?i 3)
then (return huhu))
(printout t "i=" ?i crlf ) )
;; foreach + return
(foreach ?el (create$ 1 5 10 50 100)
(if (= ?el 10)
then (return huhu))
(printout t "el=" ?el crlf ))
;; while + return
(bind ?i 0)
(while (<= ?i 3)
do
(if (= ?i 2) then (return huhu))
(printout t "i=" ?i crlf )
(++ ?i) )
;; for instance:
Jess> (for (bind ?i 0) (< ?i 5) (++ ?i) (if (= ?i 3) then (return
huhu)) (printout t "i=" ?i crlf ) )
i=0
i=1
i=2
huhu
Jess> (for (bind ?i 0) (< ?i 5) (++ ?i) (if (= ?i 3) then (return
huhu)) (printout t "i=" ?i crlf ) )
huhu
Jess>
(clear)
Jess> (foreach ?el (create$ 1 5 10 100) (if (= ?el 10) then (return
huhu)) (printout t "el=" ?el crlf ) )
el=1
el=5
huhu
Jess> (foreach ?el (create$ 1 5 10 100) (if (= ?el 10) then (return
huhu)) (printout t "el=" ?el crlf ) )
huhu
Jess>
(clear)
Jess> (bind ?i 0)
0
Jess> (while (<= ?i 3) do (if (= ?i 2) then (return huhu))
(printout t "i=" ?i crlf ) (++ ?i) )
i=0
i=1
huhu
Jess> (bind ?i 0)
0
Jess> (while (<= ?i 3) do (if (= ?i 2) then (return huhu))
(printout t "i=" ?i crlf ) (++ ?i) )
huhu
Jess>
Kind regards
Wolfgang
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users
[EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify owner-jess-
[EMAIL PROTECTED]
--------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------