tracker issue : CF-4205268

select a category, or use search below
(searches all categories and all time range)
Title:

Lambda/Fat Arrow expression requires block body syntax when returning a function

| View in Tracker

Status/Resolution/Reason: To Test//Fixed

Reporter/Name(from Bugbase): Abram A. / ()

Created: 09/26/2019

Components: Language

Versions: 2018

Failure Type:

Found In Build/Fixed In Build: 2018,0,05,315699 - hf201800-4205242.jar /

Priority/Frequency: Normal /

Locale/System: / Linux

Vote Count: 1

When you return a function from a Lambda/Fat Arrow function, ColdFusion requires that you use the "block body" syntax.  This makes the code very cumbersome and goes against how other standard languages behave.

Here's an example (also at https://trycf.com/gist/ab323ce1270f3caeb18c8454f06f268a/acf2018):

{code:java}
<cfscript>
say = (message)=>(to)=>()=>"#message# #to#";
sayHi = say("Hi");
sayHiToAdobe = sayHi("Adobe");
writeDump( sayHiToAdobe() );
</cfscript>
{code}

Expected Results: 
Hi Adobe

Actual Results:
Invalid CFML construct found error.

The above code works in Lucee and is pretty much how you'd write it in JavaScript:
JavaScript Example:
say = (message)=>(to)=>()=>`${message} ${to}`
sayHi = say("Hi");
sayHiToAdobe = sayHi("Adobe");
()=>`${message} ${to}`
sayHiToAdobe()
// "Hi Adobe"

This technique is common in functional style programming and makes composing, specializing functions, lazy evaluation and currying much more concise and easy to read and write.

Workaround:
You have to use the full function body expression syntax, which really defeats the purpose.
Example:
 say = (message)=>{ return (to)=>{return ()=>"#message# #to#"}};

Attachments:

Comments:

Can't edit bug after submitting, but just FYI the JavaScript example had a copy/paste error. The line "()=>`${message} ${to}`" was not part of the code, but rather output from the console per the line above it.
Comment by Abram A.
31411 | September 26, 2019 07:51:27 PM GMT
Hi All, This issue is fixed now. Please reach out to ColdFusion support @ [cfinstal@adobe.com|mailto:cfinstal@adobe.com] to get the patch. -Nimit
Comment by Nimit S.
31457 | September 29, 2019 05:37:21 PM GMT