Partial function application: Difference between revisions

Content added Content deleted
Line 1,314: Line 1,314:
<lang txr>[(op mapcar (op * 2)) '(1 2 3)]</lang>
<lang txr>[(op mapcar (op * 2)) '(1 2 3)]</lang>


We could define names for these functions like the problem statement says, but that defeats much of the point of partial application:
We could define names for these functions like the problem statement says, but that defeats much of the point of partial application, which is to construct new functions anonymously, on the fly, in the middle of expressions. When we "farm out" the logic to a named function, we can dispense with some or perhaps all of the partial application.


<lang txr>(defun fsf1 (list)
<lang txr>(defun fsf1 (list)
[(op mapcar (op * 2)) '(1 2 3)]) ;; pointless: why don't we just call mapcar?</lang>
[(op mapcar (op * 2)) list]) ;; pointless complication of just (mapcar (op * 2) list) !</lang>

Moreover, if we had a named function <code>f1</code> which does <code>(op * 2)</code> we would just dispense with that partial evaluation also and just write <code>[mapcar f1 list]</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>:
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>: