<@U0BJDA84R> the docs here could stand some improv...
# documentation
a
@saghosh the docs here could stand some improvement: https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-m-r/querymap.html At no point does it mention that the callback needs to return a struct. This should be reflected in the function signature and the notes below. Also note it doesn't require a closure. Any UDF will work, eg:
Copy code
q = queryNew("col", "varchar", [["hi"]])

function mapper(row) { // not a closure
    return {col=row.col.reverse()}
}

mapped = q.map(mapper)

writeDump(mapped)
https://trycf.com/gist/306890bf29ba7837073583d525d00775/acf2021?theme=monokai
m
The parameter name
closure
isn't even correct. The parameter is called
callback
.
But I have noticed quite a bit that "closure" will be used instead of "function". Is there anything in ColdFusion that actually requires a closure?
Also regarding that page, there's a parameter named
template
that is not in the History, Syntax, or Examples sections. It's not clear how to use it.
a
Is there anything in ColdFusion that actually requires a closure?
I don't see how there could be, given any behavioural difference (whether one is using closure or not; whether one is using a function expression or a function defined via statement) would be in the user-land code anyhow.
I suspect it poor understanding of technical terminology coupled with a low level of attn to detail.
s
It's not helped by this sort of thing https://cfdocs.org/isclosure where the example is not a closure👀
And this talks about the difference being function "expression" VS function "statement" https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-in-k/isclosure.html
a
I would like to know when the information imparted by
isClosure
would ever be useful? "Ah well because the implementation of this UDF binds a variable from its defining scope, I need to do
x
. If it doesn't, I do
y
". What might
x
or
y
be here?
I think the example on cfdocs is OK though, cos I don't think
isClosure
is doing what it sounds like it does. It's just "via expression as opposed to via statement". Although, again, why that would ever matter is beyond me.
@saghosh (also cc @Mark Takata (Adobe)) what's an example of when
isClosure
might be used? Both if one is literal about the meaning of "closure" in a comp sci sense, or whether it really means defined via "expression" vs "statement" ?
Ugh although this example on cfdocs.org is not helpful:
Copy code
square = function(x) {
    return x * x;
};

squared = square(5);

writeDump(isClosure(squared));
It's be clearer if it just did
writeDump(isClosure(25));
, but even then... kinda missing the point. Lucee docs example https://docs.lucee.org/reference/functions/isclosure.html, although its use of "closure" vs "user defined function" is poor, given closures are UDFs. Everyone needs a venn diagram, I think. And maybe a dictionary.
Aaand... also seems to be a bug in Lucee too: https://trycf.com/gist/7931b0dbd93624a00f33541486f93b5b/lucee5?theme=monokai
Copy code
function f(){}
g = function(){}
h = ()=>{}

writeDump([
    "isClosure" = [
        "statement" = isClosure(f),
        "expression" = isClosure(g),
        "arrow function" = isClosure(h) // false on Lucee?
    ],
    "isCustomFunction" = [
        "statement" = isCustomFunction(f),
        "expression" = isCustomFunction(g),
        "arrow function" = isCustomFunction(h)
    ]
])