[Bese-devel] Bug in UCW Examples: Add some numbers?

Larry D'Anna smoof-ra at elder-gods.org
Fri Aug 26 13:34:41 UTC 2005


* Marco Baringer (mb at bese.it) [050826 04:13]:
> this is another way to fix the problem. we're using ucw's backtracking
> mechanism to work around the fact that continuations don't undo side
> effects.
> 
> (defaction start ((s sum))
>   (loop
>      for how-many = (call 'read-a-number :label "How many numbers should we read?")
>      initially (backtrack (ucw::context.current-frame *context*) (make-place how-many))
>      do (loop
>            for count below how-many
>            initially (backtrack (ucw::context.current-frame *context*)
>                                 (make-place count))
>            sum (call 'read-a-number) into total
>            finally (call 'info-message
>                          :message (format nil "The sum is: ~D." total)))))
> 
> now that i think about it may be worth the effort, since we've already
> got the neccessary infrastructure, to have an action automatically
> backtrack all local variables. though this will help in a lot of casse
> it will still leave weird edge cases sucha s this one:
> 
> (let ((a (cons 1 2)))
>   (setf (car a) 'foo)
>   ;; the modification to the car of a is not backtracked
>   )
> 
> the only way to fix this would be to use deep copying of all
> backtracked places, this sounds like a _horrible_ idea.

Maybe we should have looping constructs that create new bindings at
each iteration, and encourage people to use those.  I don't think the
behavior ucw is exhibiting here is a bug at all.  The bug is only in
the example code that doesn't take into account the fact that it might 
be continued at the same point more than once.

      --larry 



More information about the bese-devel mailing list