Partial function application: Difference between revisions

Content added Content deleted
Line 1,296: Line 1,296:
</pre>
</pre>


{{header|TXR}}
=={{header|TXR}}==


The <code>f1</code> function is just <code>mapcar</code>, or at least the oft-used special case thereof when there is only one list to process and the function takes one argument.
The <code>f1</code> function is just <code>mapcar</code>, or at least the oft-used special case thereof when there is only one list to process and the function takes one argument.
Line 1,319: Line 1,319:
[(op mapcar (op * 2)) '(1 2 3)]) ;; pointless: why don't we just call mapcar?</lang>
[(op mapcar (op * 2)) '(1 2 3)]) ;; pointless: why don't we just call mapcar?</lang>


Here is an <code>op</code> expressino that returns a function which squares the elements of a sequence, producing a new sequence. Since we use the multiplication function, we must repeat an argument and so we must use the <code>@number</code> syntax supported by <code>op</code>:
Here is an <code>op</code> expression that returns a function which squares the elements of a sequence, producing a new sequence. Since we use the multiplication function, we must repeat an argument and so we must use the <code>@number</code> syntax supported by <code>op</code>:


<lang txr>(op mapcar (op * @1 @1))</lang>
<lang txr>(op mapcar (op * @1 @1))</lang>