First-class functions: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: Removed white space from many <math> tags - restoring visibility to Pi, fixing ill-formed HTML) |
(Lingo added) |
||
Line 1,503: | Line 1,503: | ||
0.500000 |
0.500000 |
||
</pre> |
</pre> |
||
=={{header|Lingo}}== |
|||
Lingo does not support functions as first-class objects. But with the limitations described under [[https://www.rosettacode.org/wiki/Function_composition#Lingo Function composition]] the task can be solved: |
|||
<lang lingo>A = [#sin, #cos, #square] |
|||
B = [#asin, #acos, #sqrt] |
|||
testValue = 0.5 |
|||
repeat with i = 1 to 3 |
|||
-- for implementation details of compose() see https://www.rosettacode.org/wiki/Function_composition#Lingo |
|||
f = compose(A[i], B[i]) |
|||
res = call(f, _movie, testValue) |
|||
put res = testValue |
|||
end repeat</lang> |
|||
{{out}} |
|||
<pre> |
|||
-- 1 |
|||
-- 1 |
|||
-- 1 |
|||
</pre> |
|||
User-defined arithmetic functions used in code above: |
|||
<lang lingo>on square (x) |
|||
return x*x |
|||
end |
|||
on asin (x) |
|||
res = atan(sqrt(x*x/(1-x*x))) |
|||
if x<0 then res = -res |
|||
return res |
|||
end |
|||
on acos (x) |
|||
return PI/2 - asin(x) |
|||
end</lang> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |