Function composition: Difference between revisions

Line 373:
=={{header|ATS}}==
 
If I may state in greater detail what the task requires, it is this:
I assume from the description of the task that the mere application of two functions in succession is not the goal. That, instead, the composition of two closures or closure-like objects is ''required''.
 
That '''compose''' should return ''a new function'', which will exist independently of '''compose''' once created. A person should never have to call '''compose''' merely to get the result of the composed computation.
(In other words, the idea is "How can we compose two functions that have ''implicit'' environments and get a new function that has an ''implicit'' environment".)
 
Thus it is probably impossible, for instance, to satisfy the requirement in standard C, although there are system-dependent libraries that can create closures for C.
 
<lang ats>(*
Line 418 ⟶ 419:
val g = (lam x =<cloref1> char2i x - char2i char_zero)
val z = compose (f, g) ('5')
val fg = compose (f, g)
val w = fg ('7')
in
println! (z : double);
println! (w : double)
end</lang>
 
{{out}}
<pre>$ patscc -O2 -DATS_MEMALLOC_GCBDW function_composition.dats -lgc && ./a.out
105.000000</pre>
107.000000</pre>
 
=={{header|AutoHotkey}}==
1,448

edits