<@U01EY27APNH> could you pls get someone on the de...
# adobe
a
@Mark Takata (Adobe) could you pls get someone on the dev team to comment on this code:
https://trycf.com/gist/01dd56cb570ebba4ead692889b2fee82/acf2021?theme=monokai
Copy code
unsorted = ["b","c","a","e","d"]

// EXPERIMENT 1

// CONTROL: using a callback
sorted = unsorted.sort((e1, e2) => compare(e1, e2))
writeDump(var=sorted, label="sorted by callback") // ["a","b","c","d","e"]

// TEST: is compare a first-class function? Maybe
sorted = unsorted.sort(compare)
writeDump(var=sorted, label="sorted by compare as a first-class function") // ["a","b","c","d","e"]



// EXPERIMENT 2

lowercase = ["a","b","c","d","e"]

// CONTROL: using a callback
uppercase = lowercase.map((s) => s.ucase())
writeDump(var=uppercase, label="upper-cased by callback") // ["A","B","C","D","E"]

// TEST: is ucase a first-class function? No
try {
    uppercase = lowercase.map(ucase)
} catch (any e) {
    writeDump(var=[e.detail], label="Error when using ucase as a first class function") // Cannot cast coldfusion.runtime.CFPageMethod to coldfusion.runtime.UDFMethod
}

// TEST: can we find any clue about the difference between compare and ucase? No

try {
    writeDump(compare.getClass().getName())
} catch (any e) {
    writeDump(var=[e.message], label="Error when getting classname of compare function") // Variable COMPARE is undefined
}

try {
    writeDump(ucase.getClass().getName())
} catch (any e) {
    writeDump(var=[e.message], label="Error when getting classname of ucase function") // Variable UCASE is undefined
}
My expectations are that if
compare
can be used as a first-class function, then so should other functions if they would "work" in the given situation. Also a first-class function should be able to be dumped and have methods called on it, etc. Why does
compare
behave differently from
ucase
here?