Currying: Difference between revisions

Content added Content deleted
m (Add to Category:Functions and subroutines)
m (→‎{{header|AppleScript}}: Updated primitive)
Line 25: Line 25:
The nearest thing to a first-class function in AppleScript is a 'script' in which a 'handler' (with some default or vanilla name like 'call' or 'lambda' is embedded). First class use of an ordinary 2nd class 'handler' function requires 'lifting' it into an enclosing script – a process which can be abstracted to a general mReturn function.
The nearest thing to a first-class function in AppleScript is a 'script' in which a 'handler' (with some default or vanilla name like 'call' or 'lambda' is embedded). First class use of an ordinary 2nd class 'handler' function requires 'lifting' it into an enclosing script – a process which can be abstracted to a general mReturn function.


<lang AppleScript>
<lang AppleScript>-- curry :: (Script|Handler) -> Script
-- curry :: (Script|Handler) -> Script
on curry(f)
on curry(f)
set mf to mReturn(f)
script
script
on lambda(a)
on lambda(a)
script
script
on lambda(b)
on lambda(b)
mf's lambda(a, b)
lambda(a, b) of mReturn(f)
end lambda
end lambda
end script
end script
Line 125: Line 123:
end repeat
end repeat
return lst
return lst
end range
end range</lang>
</lang>


{{Out}}
{{Out}}