Re-read my last post. If you know that the method will accept x number of
arguments. And your array may have anywhere from 1 to x possible values then
write a function to pad your array with (x - arraylen) null values.


Like this:

<cfset positionalArgs = ['foo', 'bar', 42]>

<cfset positionalArgs = padMyArray(positionalArgs,10) />

<cfset myFunction(positionalArgs[1], positionalArgs[2], positionalArgs[3],
positionalArgs[4], positionalArgs[5], positionalArgs[6], positionalArgs[7],
positionalArgs[8], positionalArgs[9], positionalArgs[10] )>

<cffunction name="padMyArray">
<cfargument name="arrIN" type="array" required="true">
 <cfargument name="arrLen" type="numeric" required="true">

<cfloop from="#arraylen(arrIN)#" to="#arrlen#" index="x">
<cfset ArrayAppend(arrIN,"")>
 </cfloop>
 <cfreturn arrIN />
</cffunction>

<cffunction name="myFunction">
<cfargument name="arg1" required="false" default="not defined">
 <cfargument name="arg2" required="false" default="not defined">
<cfargument name="arg3" required="false" default="not defined">
 <cfargument name="arg4" required="false" default="not defined">
<cfargument name="arg5" required="false" default="not defined">
 <cfargument name="arg6" required="false" default="not defined">
<cfargument name="arg7" required="false" default="not defined">
 <cfargument name="arg8" required="false" default="not defined">
<cfargument name="arg9" required="false" default="not defined">
 <cfargument name="arg10" required="false" default="not defined">
 <cfdump var="arg1: #arg1#">
<cfdump var="arg2: #arg2#">
 <cfdump var="arg3: #arg3#">
<cfdump var="arg4: #arg4#">
 <cfdump var="arg5: #arg5#">
<cfdump var="arg6: #arg6#">
 <cfdump var="arg7: #arg7#">
<cfdump var="arg8: #arg8#">
 <cfdump var="arg9: #arg9#">
<cfdump var="arg10: #arg10#">
</cffunction>



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

>
> Missing the point. The method already exists and has other callers,
> who pass separate arguments by name or position. I'm not redesigning
> its API to take an array of arguments. I want to generically pass in a
> set of ordered arguments to it.
>
> Dave
>
> On Wed, Oct 6, 2010 at 1:57 PM, Michael Grant <[email protected]> wrote:
> >
> > I gave you a perfectly viable, easy to implement solution.
> >
> >
> >
> >
> > On Wed, Oct 6, 2010 at 1:55 PM, enigment <[email protected]> wrote:
> >
> >>
> >> Imagine an SES URL processor somewhat analogous to what Django
> >> provides, with a regex match that captures specific segments of the
> >> incoming URL and passes them to the requested method. Yes I know about
> >> ColdCourse, and the related ColdBox plugin etc, I was just thinking
> >> about alternate approaches.
> >>
> >> So yes, maybe it's unusual, but not irrational, or due to lack of
> >> structure in my code.
> >>
> >> Please, can we not debate my motivation any more? If there are any
> >> actual answers to the original question, I'd be interested in hearing
> >> them, but frankly I doubt it. I've been doing CF for quite a while,
> >> and didn't know of one, so I thought I'd ask around, but this keeps
> >> focusing on "larger issues". That's a Good Thing in many cases, but
> >> actually not here. I'm asking if there's a language feature I'm not
> >> aware of to accomplish this, nothing more.
> >>
> >> Dave
> >>
> >>
> >> On Wed, Oct 6, 2010 at 1:34 PM, Michael Grant <[email protected]> wrote:
> >> >
> >> > It's also pretty unusual to not have any idea how many arguments you
> are
> >> > passing into a method. There are many more elegant approaches to your
> >> switch
> >> > suggestion. The primary one being writing code that has structure and
> >> passes
> >> > in the expected amount of arguments each time. Another one would be
> that
> >> > since you know how many arguments you are expecting in the method
> perhaps
> >> > write a function to loop over and pad your array with null values if
> they
> >> > aren't defined. Then your call to the method can always pass in the
> >> expected
> >> > amount of arguments.
> >> >
> >> >
> >> >
> >> >
> >> > On Wed, Oct 6, 2010 at 1:13 PM, enigment <[email protected]> wrote:
> >> >
> >> >>
> >> >> It's unusual for a method to take an array of its arguments, rather
> >> >> than individual ones. Situation is something like a dispatcher; the
> >> >> methods already have defined arguments, say
> Widgets.search(widgetName,
> >> >> widgetCategory, widgetID). It'd be pretty weird for it to take an
> >> >> array containing those three arguments. The layer I'm talking about
> >> >> wants to call that, but only has an array of argument values, in
> >> >> order.
> >> >>
> >> >> Not to be cranky, but while there's room for debate on why I want to
> >> >> do this, this isn't that conversation. If there's no more elegant
> >> >> approach than the switch strategy I mentioned, I'll probably ditch
> >> >> this entire route. I first wanted to check if anyone could think of a
> >> >> way to accomplish this in the CFML language, out of curiosity and to
> >> >> maybe learn something that might be useful some day, as well to get
> it
> >> >> done -- there's lots of smart and experienced folks out there. I
> >> >> didn't mean to discuss whether it's worth doing.
> >> >>
> >> >> Thanks,
> >> >> Dave
> >> >>
> >> >> On Wed, Oct 6, 2010 at 12:42 PM, Michael Grant <[email protected]>
> wrote:
> >> >> >
> >> >> > 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.
> >> >> >>
> >> >> >> Dav
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:337918
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to