[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-dev
Subject:    Re: Poll: IteratorTool usage
From:       "Nathan Bubna" <nbubna () gmail ! com>
Date:       2007-11-20 18:57:34
Message-ID: 4d651da50711201057vd8af21ckb280b33ed5bf50 () mail ! gmail ! com
[Download RAW message or body]

On Nov 19, 2007 3:27 PM, Nathan Bubna <nbubna@gmail.com> wrote:
> On Nov 19, 2007 3:11 PM, Christopher Schultz
> <chris@christopherschultz.net> wrote:
> > Nathan,
> >
> > Nathan Bubna wrote:
> > > #foreach( $item in $loop.watch($items) )
> > > $item
> > > #if( $item eq 'some break condition' )$loop.break()#end
> > > #end
> >
> > If you're going to support "break", how about supporting "continue" as
> > well (restart loop from the top after iterator increment).
>
> again, i haven't implemented this, but break would be supported by
> having watch() return a custom Iterator that can be prematurely
> finished.   i can't see anyway to implement "continue" without
> modifying the core engine or a custom directive.

for the interested...  break() won't work either, for two reasons.
one, it's a reserved word in java; i can't name a method break().
two, it wouldn't really be a true break for much the same reason we
can't support continue here.  the LoopTool impl can't leave the
#foreach immediately, but can only keep it from looping again.  so,
the method will be called stop() and will simply prevent further
iterations and not exit the current one.

> > I wonder how this would jive with nested loops. Based upon the syntax
> > above, I wonder if it would be possible to break an inner loop without
> > breaking the outer loop (it looks like not). While IteratorTool does not
> > appear to directly support nested loops, I think such support would be a
> > great goal.
>
> i'm planning to keep references to the watched iterators in the tool
> within a stack.  should make it easy to support nested loops, as
> break() would just stop the iterator on top of the stack.  this might
> also support a breakAll() or even allow watch($list, 'label') ->
> break('label') without much effort.
>
> > -chris
> >
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic