curry - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


curry, rcurry

Generate a curried procedure

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

curry(p)

curry(p, rest)

rcurry(p)

rcurry(p, rest)

Parameters

p

-

procedure or name to be curried

rest

-

(optional) expression sequence of arguments to be curried over

Description

• 

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/)

Examples

> 

g≔curry⁡f:

> 

g⁡x,y,z

f⁡x,y,z

(1)
> 

g≔curry⁡f,1:

> 

g⁡y,z

f⁡1,y,z

(2)
> 

g≔curry⁡f,1,2:

> 

g⁡z

f⁡1,2,z

(3)
> 

g≔rcurry⁡f:

> 

g⁡x,y,z

f⁡x,y,z

(4)
> 

g≔rcurry⁡f,1:

> 

g⁡y,z

f⁡y,z,1

(5)
> 

g≔rcurry⁡f,1,2:

> 

g⁡z

f⁡z,1,2

(6)
> 

map⁡curry⁡`+`,1,1,2,3,4

2,3,4,5

(7)
> 

map⁡curry⁡`*`,2,1,2,3,4

2,4,6,8

(8)
> 

L≔2a,6b,24c:

> 

map⁡curry⁡applyop,ifactor,1,L

2a,2⁢3b,23⁢3c

(9)
> 

map⁡rcurry⁡op,a,b,c,1,2,3

a,b,c

(10)

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&colon;

> 

format≔%s\t%s\n&colon;

> 

zip⁡curry⁡printf&comma;format&comma;map⁡lhs&comma;t&comma;map⁡rhs&comma;t&colon;

'    .----.
(    -.--.-
)    -.--.-
,    --..--
-    -....-
.    .-.-.-
/    -..-.
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