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

Marco Baringer mb at bese.it
Sat Aug 27 10:58:39 UTC 2005


Larry D'Anna <smoof-ra at elder-gods.org> writes:

> 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.

there are a few different issues:

1)

(dolist (i my-list)
  (<:li (<ucw:a :action (do-stuff i))))

here we don't know whether dolist will create a new binding or not and
so we don't know if the links will each have their own binding or if
the same binding is modified. fortunetly this case (which is the more
common one) is easily solvable:

(dolist (i my-list)
  (let ((i i))
    (<ucw:a :action (do-stuff i))))

or use dolist* which, other than allowing destructuring of the
elements, also guarantees a fresh binding each time:

(dolist* (i my-list)
  (<ucw:a :action (do-stuff i)))

1a)

(loop 
  for i in my-list
  do (call 'foo-bar))

here we'd need a loop* macro which, like dolist vs. dolist* above,
guaranteed a fresh binding on each iteration. the solutions here are:
a) re implement loop (i'll accept a patch but i'm not about to do it);
b) use iterate, this would require first fixing iterate's use
macroexpand; c) don't use loop or wrap the (call 'foo-bar) form with
(let ((i i)).

for now (and probably for a long time) (c) is our best option.

2)

(loop
  repeat 5
  do (call 'foo-bar))

this is more problematic. we do _not_ want to create a new binding
here, if we don't modify the same biding then our loop won't
loop. however we want that modification to get magically undone when
we use the back button. fixing this would require a ucw:loop macro or
something which setup the internal counter for backtracking.

at least, i think these are the issues and the associated solutions,
i'd love to be proven wrong.

-- 
-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