Skip to main content
WolfShade
Legend
July 23, 2019
Question

Question regarding function and arguments

  • July 23, 2019
  • 3 replies
  • 432 views

Hello, all,

This question is most likely for the Adobe Dev Team to answer, if any of them have time.  But if anyone else knows the answer, please respond.

I was doing some research into functions and arguments, and on the Adobe Help Center page for functions and arguments it states that if a function is created using CFFUNCTION, then an 'empty slot' is automatically created for each argument, in case any of them are optional.  However, if a function is created within CFSCRIPT, then no 'empty slots' are created, and if an argument is not supplied it will error out as undefined.

So, I'm curious as to why the two work differently from each other.  If, within a CFSCRIPT environment, I want arguments to be optional I have to param them.  But not in a CFFUNTION context.

Just curious.

V/r,

^ _ ^

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    July 24, 2019

    WolfShade  wrote

    ... if a function is created using CFFUNCTION, then an 'empty slot' is automatically created for each argument, in case any of them are optional.  However, if a function is created within CFSCRIPT, then no 'empty slots' are created, and if an argument is not supplied it will error out as undefined.

    I really don't understand. Please provide some code to illustrate.

    Community Expert
    July 24, 2019

    This doesn't really answer your question, but under the covers I think they're quite different. When you use CFFUNCTION, I seem to recall that the function actually gets compiled into a separate class. I don't think that happens when you create a function within CFSCRIPT. So I guess I'm surprised that they're as similar as they are, rather than that they work differently.

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC
    Charlie Arehart
    Community Expert
    Community Expert
    July 24, 2019

    So Wolf, that's an awfully convoluted set of code (defining functions in struct keys, and later calling them), and then too the two different methods (the cffunction-based one, and the cfscript-based one) do not do the same thing. More important (to demonstrating your concern), they don't take the same args, and most important, in the body of the script-one you refer to the args using named args while in the other you refer to them using unnamed args.

    In fact, if you change that "failing" line to this:

    func(arg1 = arg1, arg2 = arg2, arg3 = arguments[3]); 

    then your error goes away without the need of uncommenting the param. I haven't the bandwidth now to connect the dots as to why that failed without it, but perhaps this will be a clue to you or Dave or others to see the complete explanation.


    And if not, I think you'd help your cause (helping others help you) by creating a far simpler example that demonstrates this contention of yours (and demonstrating that in the fewest lines possible). I know that takes work and time, which you may not have either.

    Finally, Dave, in running the code to generate the error (I did it at cffiddle), we can see in the error output the reference to the class (file name of the class) being created for that specific script-based method, so that's not it. :-)

    /Charlie (troubleshooter, carehart. org)
    WolfShade
    WolfShadeAuthor
    Legend
    July 24, 2019

    Charlie,

    The 'convoluted' code is, I'm guessing, my dispatch table that I'm trying to use in place of switch/case statements, and I have not been able to get a dispatch table in CFCODE to work; I've only gotten them to work inside a CFSCRIPT tag.

    And, yes, I did use different nomenclature between the two, but I will give it another shot on cftry.com as you suggested.

    V/r,

    ^ _ ^

    Charlie Arehart
    Community Expert
    Community Expert
    July 24, 2019

    How about showing some simple code that demonstrates your point, rather than relying solely on the docs' assertion (or on us to create and confirm it). And do indicate in what version/s you confirm it.

    You can use Cffiddle.org or trycf.com to demo things, even offering a link to a saved cffiddle demo.

    I say all this to help, not to criticize.

    /Charlie (troubleshooter, carehart. org)
    WolfShade
    WolfShadeAuthor
    Legend
    July 24, 2019

    https://forums.adobe.com/people/Charlie+Arehart  wrote

    I say all this to help, not to criticize.

    Oh, I know, Charlie.    I'll use trycf.com because it offers what we are using, CF11, where cffiddle.org only offers 2016 and 2018.  I'll post a link as soon as I have it done.

    V/r,

    ^ _ ^