Function composition: Difference between revisions

→‎{{header|RPL}}: actually composes 2 functions - previous version only evaluated them one after the other
(→‎{{header|RPL}}: actually composes 2 functions - previous version only evaluated them one after the other)
Line 2,869:
 
=={{header|RPL}}==
{{works with|Halcyon CalcHP|4.2.748G}}
RPL allows x to be a value or a variable. In this case, the function returns an expression.
« →STR SWAP →STR +
{{works with|Halcyon Calc|4.2.7}}
DUP "»«" POS " " REPL STR→
≪ SWAP EVAL SWAP EVAL ≫
» '<span style="color:blue">FCOMP</span>' STO <span style="color:grey">@ ''( « f » « g » → « f o g » )''</span>
'FCOMP' STO
≪ ALOG ≫ ≪ COS ≫ 0<span style="color:blue">FCOMP</span>
≪ ALOG ≫ ≪ COS ≫ 'x'<span style="color:blue">FCOMP</span> 0 EVAL
≪ ALOG ≫ ≪ COS ≫ <span style="color:blue">FCOMP</span> 'x' EVAL
{{out}}
<pre>
3: ≪ COS ALOG ≫
2: 10
1: 'ALOG(COS(x))'
</pre>
 
=={{header|Ruby}}==
This <tt>compose</tt> method gets passed two Method objects or Proc objects
1,150

edits