curry, rcurry
Generate a curried procedure
Calling Sequence
Parameters
Description
Examples
curry(p)
curry(p, rest)
rcurry(p)
rcurry(p, rest)
p
-
procedure or name to be curried
rest
(optional) expression sequence of arguments to be curried over
The procedure curry returns a procedure derived from its first argument p by currying on the remaining arguments, if any, in procedure application.
Given a Maple expression f (usually a procedure or a name), the curried procedure curry( f, x1, x2, ..., xn ) is the procedure g for which g⁡t1,t2,...,tm=f⁡x1,x2,...,xn,t1,t2,...,tm. In the case in which n=0, currying on no arguments returns a procedure that calls f.
It is useful for producing a derived procedure from an existing one within the context of other commands such as map, zip, select, remove, and apply.
The procedure rcurry is similar to curry, but curries on the specified arguments from the right of the parameter list.
The definition of currying used here is adapted from "The Haskell 98 Report" ("The Haskell Language Report"), by Simon Peyton Jones, et. al. (http://haskell.org/onlinereport/)
g≔curry⁡f:
g⁡x,y,z
f⁡x,y,z
g≔curry⁡f,1:
g⁡y,z
f⁡1,y,z
g≔curry⁡f,1,2:
g⁡z
f⁡1,2,z
g≔rcurry⁡f:
g≔rcurry⁡f,1:
f⁡y,z,1
g≔rcurry⁡f,1,2:
f⁡z,1,2
map⁡curry⁡`+`,1,1,2,3,4
2,3,4,5
map⁡curry⁡`*`,2,1,2,3,4
2,4,6,8
L≔2a,6b,24c:
map⁡curry⁡applyop,ifactor,1,L
2a,2⁢3b,23⁢3c
map⁡rcurry⁡op,a,b,c,1,2,3
a,b,c
Suppose you want to print a table, specified as a list of equations, in a neat form.
morse≔-=-....-,.=.-.-.-,'=.----.,(=-.--.-,)=-.--.-,,=--..--,/=-..-.,0=-----,1=.----,2=..---,3=...--,4=....-,5=.....,6=-....,7=--...,8=---..,9=----.,:=---...,==-...-,?=..--..,a=.-,b=-...,c=-.-.,d=-..,e=.,f=..-.,g=--.,h=....,i=..,j=.---,k=-.-,l=.-..,m=--,n=-.,o=---,p=.--.,q=--.-,r=.-.,s=...,t=-,u=..-,v=...-,w=.--,x=-..-,y=-.--,z=--..:
t≔sort⁡morse,u,v↦lexorder⁡lhs⁡u,lhs⁡v:
format≔<tr><td>%s</td><td>%s</td></tr>\n:
format≔%s\t%s\n:
zip⁡curry⁡printf,format,map⁡lhs,t,map⁡rhs,t:
' .----. ( -.--.- ) -.--.- , --..-- - -....- . .-.-.- / -..-. 0 ----- 1 .---- 2 ..--- 3 ...-- 4 ....- 5 ..... 6 -.... 7 --... 8 ---.. 9 ----. : ---... = -...- ? ..--.. a .- b -... c -.-. d -.. e . f ..-. g --. h .... i .. j .--- k -.- l .-.. m -- n -. o --- p .--. q --.- r .-. s ... t - u ..- v ...- w .-- x -..- y -.-- z --..
See Also
apply
eval
function
lexorder
map
sort
type/function
zip
Download Help Document