cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <sylvain.wal...@anyware-tech.com>
Subject Re: accessing sitemap parameters in a flow script
Date Sat, 23 Aug 2003 11:50:09 GMT
Marc Portier wrote:

> Sylvain Wallez wrote:
>
>> Stefano Mazzocchi wrote:
>
> <snip />
>
>>> If we match by variable name rather than by position, it would work 
>>> anyway.
>>>
>>> ... but I have the feeling I'm missing a big point here. 
>>
>>
>> Yeah : the point is that parameters are passed as Object[] to a JS 
>> function. The names given both in the sitemap parameters and the JS 
>> function parameters are therefore unusable for parameter passing. 
>> Only their position counts. See 
>> FOM_JavaScriptInterpreter.callFunction (line 553) : "funArgs" is a 
>> Object[].
>>
>> Sylvain
>
>
> Yes,
>
> and it's quite logic since js doesn't have the notion of named 
> argument-passing in the first place:
>
> what I mean is that you can't have a
> function whatever( x,  y) {
>     return x - y;
> }
>
> and then call that with:
>
> someresult = whatever(y= 4, x= 5)
>
> while naming the arguments by how they are declared in the function, 
> and not deducing their role from their position
>
> there are some scripting languages that do this IIRC, but not js
>
> Going back to the origin of the discussion: we are calling this NOT 
> from another js code portion, but from our beloved sitemap and there 
> it is hard to see functional difference between
>
> <map:call function="whatever">
>   <map:parameter name="x" value="5" />
>   <map:parameter name="y" value="4" />
> </map:call>
>
> and
>
> <map:call function="whatever">
>   <map:parameter name="y" value="4" />
>   <map:parameter name="x" value="5" />
> </map:call>
>
> (although in strict XML infoset speak I guess there is a difference, 
> no? (order of elements is important)
>
> maybe it is just that other spots in the sitemap made us custom to 
> ignoring this fact?)
>
> One way to go about balancing of the technics and the sociologics in 
> this could be to pass in an argument-object-map rather then multiple 
> arguments:
>
> so thinking about this:
>
> function whatever(args) {
>   dosomething(args.x);
>   dosomething(args.y);
> }
>
> we get a more natural comparison between:
>
> someresult = whatever({y: 5, x: 4})
>
> and:
>
> <map:call function="whatever">
>   <map:arguments>
>     <map:parameter name="y" value="5" />
>     <map:parameter name="x" value="4" />
>   </map:arguments>
> </map:call>
>
>
> which the famous line 553 Sylvain just mentioned could easily map onto 
> a single element Object[] to pass...
>
>
> but all I did now is made some stuff more explicit...
>
> what do you guys think, some direction for a suitable compromise? 


There's already a "parameters" property in the "cocoon" object.

We can have :
function whatever() {
  doSomething(cocoon.parameters.x, cocoon.parameters.y);
}

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



Mime
View raw message