Jump to content

Partial function application: Difference between revisions

Line 1,314:
<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:, 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)
[(op mapcar (op * 2)) '(1 2 3)list]) ;; pointless: whycomplication don't weof just call (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>:
543

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.