Jump to content

Currying: Difference between revisions

1,451 bytes added ,  4 years ago
→‎{{header|TXR}}: Currying is not partial application. Also fix, cl-op link. Google Code is long dead.
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
(→‎{{header|TXR}}: Currying is not partial application. Also fix, cl-op link. Google Code is long dead.)
Line 1,732:
=={{header|TXR}}==
 
Note: many solutions for this task are conflating currying with partial application. Currying converts an N-argument function into a cascade of one-argument functions. The curry operator doesn't itself bind any arguments; no application is going on. The relationship between currying and partial application is that partial application occurs when the cascade is unraveled as arguments are applied to it: each successive one-argument call in the cascade binds an argument, and when all the arguments are bound, the value of the original function over those arguments is computed.
TXR Lisp has an operator called <code>op</code> for currying. Of course, currying is done with lambdas under the hood; the operator generates lambdas. Its name is inspired by the same-named operators featured in the Goo language, and in the Common Lisp library <i>cl-op</i>.
 
TXR Lisp has an operator called <code>op</code> for curryingpartial application. Of course, curryingpartial application is done with lambdas under the hood; the operator generates lambdas. Its name is inspired by the same-named operators featured in the Goo language, and in the Common Lisp library <i>cl-op</i>.
 
References:
Goo <code>op</code>: [http://people.csail.mit.edu/jrb/goo/manual.46/goomanual_15.html]
<i>cl-op</i>: [https://codecliki.google.com/pnet/cl-op/]
 
TXR's <code>op</code> is quite different in that it uses numbered arguments, has some additional features, and is accompanied by a "zoo" of related operators which share its curryingpartial application syntax, providing various useful derived behaviors.
 
A two-argument function which subtracts is arguments from 10, and then subtracts five:
 
<lang txrlisp>(op - 10 @1 @2 5)</lang>
 
TXR Lisp doesn't have a predefined function or operator for currying. A function can be manually curried. For instance, the three-argument named function: <code>(defun f (x y z) (* (+ x y) z))</code> can be curried by hand to produce a function <code>g</code> like this:
 
<lang txrlisp>(defun g (x)
(lambda (y)
(lambda (z)
(* (+ x y) z))))</lang>
 
Or, by referring to the definition of <code>f</code>:
 
<lang txrlisp>(defun g (x)
(lambda (y)
(lambda (z)
(f x y z))))</lang>
 
Since a three-argument function can be defined directly, and has advantages like diagnosing incorrect calls which pass fewer than three or more than three arguments, currying is not useful in this language. Similar reasoning applies as given in the "Why not real currying/uncurrying?" paragraph under the Design Rationale of Scheme's SRFI 26.
 
=={{header|Visual Basic .NET}}==
543

edits

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