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

# Online Help

###### All Products    Maple    MapleSim

curry, rcurry

Generate a curried procedure

 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\left(\mathrm{t1},\mathrm{t2},...,\mathrm{tm}\right)=f\left(\mathrm{x1},\mathrm{x2},...,\mathrm{xn},\mathrm{t1},\mathrm{t2},...,\mathrm{tm}\right)$. 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≔\mathrm{curry}\left(f\right):$
 > $g\left(x,y,z\right)$
 ${f}{}\left({x}{,}{y}{,}{z}\right)$ (1)
 > $g≔\mathrm{curry}\left(f,1\right):$
 > $g\left(y,z\right)$
 ${f}{}\left({1}{,}{y}{,}{z}\right)$ (2)
 > $g≔\mathrm{curry}\left(f,1,2\right):$
 > $g\left(z\right)$
 ${f}{}\left({1}{,}{2}{,}{z}\right)$ (3)
 > $g≔\mathrm{rcurry}\left(f\right):$
 > $g\left(x,y,z\right)$
 ${f}{}\left({x}{,}{y}{,}{z}\right)$ (4)
 > $g≔\mathrm{rcurry}\left(f,1\right):$
 > $g\left(y,z\right)$
 ${f}{}\left({y}{,}{z}{,}{1}\right)$ (5)
 > $g≔\mathrm{rcurry}\left(f,1,2\right):$
 > $g\left(z\right)$
 ${f}{}\left({z}{,}{1}{,}{2}\right)$ (6)
 > $\mathrm{map}\left(\mathrm{curry}\left(\mathrm{+},1\right),\left[1,2,3,4\right]\right)$
 $\left[{2}{,}{3}{,}{4}{,}{5}\right]$ (7)
 > $\mathrm{map}\left(\mathrm{curry}\left(\mathrm{*},2\right),\left[1,2,3,4\right]\right)$
 $\left[{2}{,}{4}{,}{6}{,}{8}\right]$ (8)
 > $L≔\left[{2}^{a},{6}^{b},{24}^{c}\right]:$
 > $\mathrm{map}\left(\mathrm{curry}\left(\mathrm{applyop},\mathrm{ifactor},1\right),L\right)$
 $\left[{\left({2}\right)}^{{a}}{,}{\left(\left({2}\right){}\left({3}\right)\right)}^{{b}}{,}{\left({\left({2}\right)}^{{3}}{}\left({3}\right)\right)}^{{c}}\right]$ (9)
 > $\mathrm{map}\left(\mathrm{rcurry}\left(\mathrm{op},\left[a,b,c\right]\right),\left[1,2,3\right]\right)$
 $\left[{a}{,}{b}{,}{c}\right]$ (10)

Suppose you want to print a table, specified as a list of equations, in a neat form.

 > $\mathrm{morse}≔\left["-"="-....-","."=".-.-.-","\text{'}"=".----.","\left("="-.--.-","\right)"="-.--.-",","="--..--","/"="-..-.","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"="--.."\right]:$
 > $t≔\mathrm{sort}\left(\mathrm{morse},\left(u,v\right)→\mathrm{lexorder}\left(\mathrm{lhs}\left(u\right),\mathrm{lhs}\left(v\right)\right)\right):$
 > $\mathrm{format}≔"%s%s":$
 > $\mathrm{format}≔"%s %s":$
 > $\mathrm{zip}\left(\mathrm{curry}\left(\mathrm{printf},\mathrm{format}\right),\mathrm{map}\left(\mathrm{lhs},t\right),\mathrm{map}\left(\mathrm{rhs},t\right)\right):$
 '    .----. (    -.--.- )    -.--.- ,    --..-- -    -....- .    .-.-.- /    -..-. 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