You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2000/12/29 14:20:32 UTC

speak now...

In VTL, you can create two kinds of array objects, an 'Object Array',
and a 'Range' :

#set( $foo = ["a","b","c"] )
#set( $foo = [1..5] )

and use them in #foreach() or pass them to a method or VM.

The current implementation is an Object[].  The downside of this is that
we can't find out the size of the array in VTL, because in VTL we don't
allow access to object fields, just methods. (This is not bad... this
isn't what I am getting at...)

What I want to do is change the implementation of ObjectArray and Range
from Object[] to ArrayList, so we can then access the size() member, and
also, it would be more convenient overall. Now, you might say "Why do I
need to get the size, since I just created the thing and can see it here
in my template?".  One answer is that when one of these is passed into a
VM, the VM author can't know what the size is.  (And I am sure there are
other answers... :)

The problem : when I do this, things will break.  Specifically, any
methods of classes that you currently call from VTL that currently
accept Object[] as an argument will have to change. I will take care of
cleaning up everything in Velocity, but I am sure there are things out
there that will break.

So the question is (assuming no one has a big problem with this) is when
and how?  I can do it to the Range object easily enough as no one uses
that yet, but want to do both together for consistency.

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity

Re: speak now...

Posted by Jon Stevens <jo...@latchkey.com>.
on 1/2/2001 4:53 AM, "Christoph Reck" <Ch...@dlr.de> wrote:

> What happens with a:
> #set( $foo = [] )
> Will this be an empty ArrayList ?

+1

> I would also vote in favour of a #set( $foo = {} ) usable to create
> a Map that can be populated via #set( $foo.KEY1 = "xyz" )... but this
> seems to be another issue :)

Strongly -1. You have things like potential synchronization issues and
exceptions to worry about. Two things that VTL has no concept of.

-jon


Re: speak now...

Posted by Christoph Reck <Ch...@dlr.de>.
I am all +1 for this!

> In VTL, you can create two kinds of array objects, an 'Object Array',
> and a 'Range' :
> 
> #set( $foo = ["a","b","c"] )
> #set( $foo = [1..5] )
> 
>[snip]
> What I want to do is change the implementation of ObjectArray and Range
> from Object[] to ArrayList, so we can then access the size() member, and


What happens with a:
  #set( $foo = [] )
Will this be an empty ArrayList ?


I would also vote in favour of a #set( $foo = {} ) usable to create
a Map that can be populated via #set( $foo.KEY1 = "xyz" )... but this
seems to be another issue :) 

Some of you have strong feelings against allowing the ASTSetDirective 
checking for a put method (ASTIdentifyer already has th notion of the 
get method!). Anyone in favour of adding the put notion to ASTSetDirective? 


:) Christoph