Dave,

Why don't you just pass in the array?

<cfset positionalArgs = ['foo', 'bar', 42] />
<cfset myFunction(positionalArgs) />
<cffunction name="myFunction">
<cfargument name="positionalArgs" type="array">
<cfloop from="1" to="#arraylen(positionalArgs)#" index="x">
 <cfdump var="#x#: #positionalArgs[x]#"><br />
</cfloop>
</cffunction>


On Wed, Oct 6, 2010 at 12:38 PM, enigment <[email protected]> wrote:

>
> @Michael: What I'm looking for is the positional equivalent of
> argumentCollection. If it wasn't for that, you'd think the same about
> passing a structure of arguments -- any object you pass will be
> treated as a single argument. But argumentCollection trumps that. I
> even tried a structure with keys 1, 2, 3, and passing that as
> argumentCollection (unnamed arguments appear inside the function as 1,
> 2, and 3 if you dump arguments), no joy.
>
> @Jason: Clearly, calling a method three times, each time with one
> argument, is very different than calling it once with all three. Say
> they're search fields, lastName, FirstName, ZIP; you want the search
> to run with all three of them in place, not separately for each one.
> (Not sure why you went with an iterator rather than just indexing over
> the array, but it doesn't matter, not what I need to do.)
>
> Thanks for the ideas though. This just may not be possible.
>
> Dave
>
> On Wed, Oct 6, 2010 at 12:15 PM, Jason Durham <[email protected]> wrote:
> >
> > Whoops.. read the rest of the email below.
> >
> > var I = positionalArgs.iterator();
> > var arg = "";
> >
> > while( i.hasNext() ) {
> >        arg = i.next();
> >        SomeComponent.someMethod(arg);
> > }
> >
> > That will call someMethod() for each array value.  You could use a For
> loop
> > with "i LTE arrayLen(positionalArg)" if you don't want to use iterator().
> >
> > -----Original Message-----
> > From: enigment [mailto:[email protected]]
> > Sent: Wednesday, October 06, 2010 10:48 AM
> > To: cf-talk
> > Subject: Re: Positional argument collection
> >
> >
> > Thanks for chiming in Michael.
> >
> > Using ArrayToList would pass all three values as a single string. I'm
> > looking for a generic way to pass each array element as an individual
> > argument, regardless of how many there are. Take another look at the
> > examples I gave.
> >
> > Dave
> >
> > On Wed, Oct 6, 2010 at 11:02 AM, Michael Grant <[email protected]> wrote:
> >>
> >> I'm not exactly sure what you're asking but would some variation of
> >> this work for you?
> >>
> >> SomeComponent.someMethod(ArrayToList(positionalArgs));
> >>
> >> Of course you may need to qualify the list etc if you are passing
> >> strings, but I think that suits your example.
> >>
> >>
> >> On Wed, Oct 6, 2010 at 10:54 AM, enigment <[email protected]> wrote:
> >>
> >>>
> >>> Say I have an array of values, arbitrary length, that I want to pass
> >>> as the arguments to a method.
> >>>
> >>> For example, with this:
> >>>  positionalArgs = ['foo', 'bar', 42]; // this varies, may be any
> >>> length I want to make this call:
> >>>  SomeComponent.someMethod('foo', 'bar', 42);
> >>>
> >>> Is there a positional equivalent to argumentCollection, or some other
> >>> language construct that I don't know about to do this? If the
> >>> arguments were in a structure, I could pass it as the
> >>> argumentCollection, but I don't know how to do this by position in a
> >>> clean way.
> >>>
> >>> Only thing I thought of is a switch statement with some finite number
> >>> of cases, each of which calls the method with a specific number of
> >>> arguments, like this (partial):
> >>>   case 2:
> >>>      SomeComponent.someMethod(positionalArgs[1], positionalArgs[2]);
> >>>      break;
> >>>   case 3:
> >>>      SomeComponent.someMethod(positionalArgs[1], positionalArgs[2],
> >>> positionalArgs[3]);
> >>>      break;
> >>>   etc...
> >>>
> >>> Any thoughts? Thanks,
> >>>
> >>> Dave
> >>>
> >>>
> >>
> >>
> >
> >
> >
> >
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:337910
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to