Adam Cameron
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=monokaimtbrown
06/16/2023, 11:11 AMclosure
isn't even correct. The parameter is called callback
.mtbrown
06/16/2023, 11:15 AMmtbrown
06/16/2023, 11:17 AMtemplate
that is not in the History, Syntax, or Examples sections. It's not clear how to use it.Adam Cameron
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.
Adam Cameron
seancorfield
seancorfield
Adam Cameron
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?Adam Cameron
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.Adam Cameron
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" ?Adam Cameron
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.Adam Cameron
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)
]
])