Function composition: Difference between revisions

Content added Content deleted
(→‎{{header|RPL}}: actually composes 2 functions - previous version only evaluated them one after the other)
Line 2,869: Line 2,869:


=={{header|RPL}}==
=={{header|RPL}}==
{{works with|HP|48G}}
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 FCOMP
≪ ALOG ≫ ≪ COS ≫ <span style="color:blue">FCOMP</span>
≪ ALOG ≫ ≪ COS ≫ 'x' FCOMP
≪ ALOG ≫ ≪ COS ≫ <span style="color:blue">FCOMP</span> 0 EVAL
≪ ALOG ≫ ≪ COS ≫ <span style="color:blue">FCOMP</span> 'x' EVAL
{{out}}
{{out}}
<pre>
<pre>
3: ≪ COS ALOG ≫
2: 10
2: 10
1: 'ALOG(COS(x))'
1: 'ALOG(COS(x))'
</pre>
</pre>

=={{header|Ruby}}==
=={{header|Ruby}}==
This <tt>compose</tt> method gets passed two Method objects or Proc objects
This <tt>compose</tt> method gets passed two Method objects or Proc objects