[Bese-devel] Bug in UCW Examples: Add some numbers?
Marco Baringer
mb at bese.it
Wed Aug 24 17:01:48 UTC 2005
"P. Joe Bootvong" <joe13x at hotmail.com> writes:
> Expected Result:
> There are two sensible behavior I can think of:
>
> 1.) UCW think I go back to edit the last value I have entered. So It
> should prompt me for another value. In addition to enter 10, then
> back to edit to 5, I should be asked for one more number.
this is what should happen.
the problem is this (in ucw/examples/sum.lisp):
(loop
repeat how-many
sum (call 'read-a-number) into total
finally (call 'info-message :message (format nil "The sum is: ~D." total)))
the repeat clause of loop does not play well with
continuations. basically repeat setups a local counter and medifies
that value each time through the loop. however since this is a
modification and not a fresh binding calling the contiunation does not
undo the modification (this is the way things should be (though i
damit that it looks wrong in this particular case)).
the only way to fix is to use recursion (which gets 'undone' when
stepping back to a previous continuation):
(defaction start ((s sum))
(let ((how-many (call 'read-a-number
:label "How many numbers should we read?")))
(labels ((sum-numbers (how-many sum)
(if (zerop how-many)
;; all done
(call 'info-message
:message (format nil "The sum is: ~D." sum))
;; more to go
(sum-numbers (1- how-many)
(+ sum (call 'read-a-number))))))
(sum-numbers how-many 0))))
NB: while writing this fix i discovered a bug in cc interpreter, local
function application was broken. UPDATE ARNESI.
> 2.) UCW think there is nothing in the page indicating that the value I
> went back and submit is first value. So it took the new value as the
> second number and add both result in, And return the result of 15.
>
> The current behavior is neither of this.
nope :(
--
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
-Leonard Cohen
More information about the bese-devel
mailing list