4.20 Procedures
The Racket Reference
Language Model
Notation for Documentation
Syntactic Forms
Datatypes
Structures
Classes and Objects
Units
Contracts
Pattern Matching
10
Control Flow
11
Concurrency and Parallelism
12
Macros
13
Input and Output
14
Reflection and Security
15
Operating System
16
Memory Management
17
Unsafe Operations
18
Running Racket
Bibliography
Index
Datatypes
4.1
Equality
4.2
Booleans
4.3
Numbers
4.4
Strings
4.5
Byte Strings
4.6
Characters
4.7
Symbols
4.8
Regular Expressions
4.9
Keywords
4.10
Pairs and Lists
4.11
Mutable Pairs and Lists
4.12
Vectors
4.13
Stencil Vectors
4.14
Boxes
4.15
Hash Tables
4.16
Treelists
4.17
Sequences and Streams
4.18
Dictionaries
4.19
Sets
4.20
Procedures
4.21
Void
4.22
Undefined
4.20
Procedures
4.20.1
Keywords and Arity
4.20.2
Reflecting on Primitives
4.20.3
Additional Higher-
Order Functions
On this page:
procedure?
apply
compose
compose1
procedure-
rename
procedure-
realm
procedure-
>method
procedure-
closure-
contents-
eq?
4.20.1
Keywords and Arity
keyword-
apply
procedure-
arity
procedure-
arity?
procedure-
arity-
mask
procedure-
arity-
includes?
procedure-
reduce-
arity
procedure-
reduce-
arity-
mask
procedure-
keywords
procedure-
result-
arity
make-
keyword-
procedure
procedure-
reduce-
keyword-
arity
procedure-
reduce-
keyword-
arity-
mask
arity-
at-
least
prop:
procedure
procedure-
struct-
type?
procedure-
extract-
target
prop:
arity-
string
prop:
checked-
procedure
checked-
procedure-
check-
and-
extract
procedure-
specialize
4.20.2
Reflecting on Primitives
primitive?
primitive-
closure?
primitive-
result-
arity
4.20.3
Additional Higher-
Order Functions
identity
const
const*
thunk
thunk*
negate
conjoin
disjoin
curry
curryr
normalized-
arity?
normalize-
arity
arity=?
arity-
includes?
Racket
top
contents
← prev
up
next →
4.20
Procedures
procedure
procedure?
boolean?
any/c
Returns
#t
if
is a procedure,
#f
otherwise.
procedure
apply
proc
...
lst
#:
kw-arg
...
any
proc
procedure?
any/c
lst
list?
kw-arg
any/c
The
apply
Function
in
The Racket Guide
introduces
apply
Applies
proc
using the content of
list*
...
lst
as the (by-position) arguments. The
#:
kw-arg
sequence is
also supplied as keyword arguments to
proc
, where
#:
stands for any keyword.
The given
proc
must accept as many arguments as the number of
s plus length of
lst
, it must accept the supplied
keyword arguments, and it must not require any other keyword
arguments; otherwise, the
exn:fail:contract
exception is raised. The given
proc
is called in tail position with respect to the
apply
call.
Examples:
apply
apply
apply
apply
sort
list
list
#:key
car
'((1) (2))
procedure
compose
proc
...
procedure?
proc
procedure?
procedure
compose1
proc
...
procedure?
proc
procedure?
Returns a procedure that composes the given functions, applying the last
proc
first and the first
proc
last. The
compose
function
allows the given functions to consume and produce any number of values, as
long as each function produces as many values as the preceding function
consumes, while
compose1
restricts the internal value passing to
a single value. In both cases, the input arity of the last function and
the output arity of the first are unrestricted, and they become the
corresponding arity of the resulting composition (including keyword
arguments for the input side).
When no
proc
arguments are given, the result is
values
. When exactly one is given, it is returned.
Examples:
compose1
sqrt
10
-3.1622776601683795
compose1
sqrt
10
0.0+3.1622776601683795i
compose
list
split-path
bytes->path
#"/a"
unix
'(# # #f)
Note that in many cases,
compose1
is preferred. For example,
using
compose
with two library functions may lead to problems
when one function is extended to return two values, and the preceding
one has an optional input with different semantics. In addition,
compose1
may create faster compositions.
procedure
procedure-rename
proc
name
realm
procedure?
proc
procedure?
name
symbol?
realm
symbol?
racket
Returns a procedure that is like
proc
, except that its name
as returned by
object-name
(and as printed for debugging) is
name
and its
realm
(potentially used for adjusting
error messages) is
realm
The given
name
and
realm
are used for printing and adjusting
an error message if the
resulting procedure is applied to the wrong number of arguments. In
addition, if
proc
is an
accessor
or
mutator
produced by
struct
make-struct-field-accessor
, or
make-struct-field-mutator
, the resulting procedure also uses
name
when its (first) argument has the wrong type. More
typically, however,
name
is not used for reporting errors,
since the procedure name is typically hard-wired into an internal
check.
Changed in version 8.4.0.2 of package
base
: Added the
realm
argument.
procedure
procedure-realm
proc
symbol?
proc
procedure?
Reports the
realm
of a procedure, which can depend on the
module where the procedure was created, the
current-compile-realm
value when the procedure’s code was
compiled, or a realm explicitly assigned through a function like
procedure-rename
Added in version 8.4.0.2 of package
base
procedure
procedure->method
proc
procedure?
proc
procedure?
Returns a procedure that is like
proc
except that, when applied
to the wrong number of arguments, the resulting error hides the first
argument as if the procedure had been compiled with the
method-arity-error
syntax property.
procedure
procedure-closure-contents-eq?
proc1
proc2
boolean?
proc1
procedure?
proc2
procedure?
Compares the contents of the closures of
proc1
and
proc2
for equality by comparing closure elements pointwise using
eq?
4.20.1
Keywords and Arity
procedure
keyword-apply
proc
kw-lst
kw-val-lst
...
lst
#:
kw-arg
...
any
proc
procedure?
kw-lst
listof
keyword?
kw-val-lst
list?
any/c
lst
list?
kw-arg
any/c
The
apply
Function
in
The Racket Guide
introduces
keyword-apply
Like
apply
, but
kw-lst
and
kw-val-lst
supply by-keyword arguments in addition to the by-position arguments
of the
s and
lst
, and in addition to the directly
supplied keyword arguments in the
#:
kw-arg
sequence,
where
#:
stands for any keyword.
The given
kw-lst
must be sorted using
keyword. No
keyword can appear twice in
kw-lst
or both in
kw-lst
and as a
#:
, otherwise, the
exn:fail:contract
exception is raised. The given
kw-val-lst
must have
the same length as
kw-lst
, otherwise, the
exn:fail:contract
exception is raised. The given
proc
must accept all
of the keywords in
kw-lst
plus the
#:
s, it must
not require any other keywords, and it must accept as many by-position
arguments as supplied via the
s and
lst
; otherwise,
the
exn:fail:contract
exception is raised.
Examples:
define
#:y
#:z
10
list
keyword-apply
#:y
'(1 2 10)
keyword-apply
#:y
#:z
'(1 2 3)
keyword-apply
#:z
#:y
'(1 2 7)
procedure
procedure-arity
proc
normalized-arity?
proc
procedure?
Returns information about the number of by-position arguments accepted
by
proc
. See also
procedure-arity?
normalized-arity?
, and
procedure-arity-mask
procedure
procedure-arity?
boolean?
any/c
A valid arity
is one of the following:
An exact non-negative integer, which means that the procedure
accepts
arguments, only.
arity-at-least
instance, which means that the
procedure accepts
arity-at-least-value
or more
arguments.
A list containing integers and
arity-at-least
instances, which means that the procedure accepts any number of
arguments that can match one of the elements of
The result of
procedure-arity
is always normalized in the sense of
normalized-arity?
Examples:
procedure-arity
cons
procedure-arity
list
(arity-at-least 0)
arity-at-least?
procedure-arity
list
#t
arity-at-least-value
procedure-arity
list
arity-at-least-value
procedure-arity
lambda
procedure-arity
case-lambda
'(1 2)
procedure
procedure-arity-mask
proc
exact-integer?
proc
procedure?
Returns the same information as
procedure-arity
, but encoded
differently. The arity is encoded as an exact integer
mask
where
bitwise-bit-set?
mask
returns true if
proc
accepts
arguments.
The mask encoding of an arity is often easier to test and manipulate,
and
procedure-arity-mask
is sometimes faster than
procedure-arity
while always being at least as fast.
Added in version 7.0.0.11 of package
base
procedure
procedure-arity-includes?
proc
kws-ok?
boolean?
proc
procedure?
exact-nonnegative-integer?
kws-ok?
any/c
#f
Returns
#t
if the procedure can accept
by-position
arguments,
#f
otherwise. If
kws-ok?
is
#f
the result is
#t
only if
proc
has no required
keyword arguments.
Examples:
procedure-arity-includes?
cons
#t
procedure-arity-includes?
display
#f
procedure-arity-includes?
lambda
#:y
#f
procedure-arity-includes?
lambda
#:y
#t
#t
procedure
procedure-reduce-arity
proc
arity
name
realm
procedure?
proc
procedure?
arity
procedure-arity?
name
or/c
symbol?
#f
#f
realm
symbol?
racket
Returns a procedure that is the same as
proc
(including
the same name returned by
object-name
), but that accepts
only arguments consistent with
arity
. In particular,
when
procedure-arity
is applied to the generated
procedure, it returns a value that is
equal?
to
the normalized form of
arity
If the
arity
specification allows arguments that are not in
procedure-arity
proc
, the
exn:fail:contract
exception is raised. If
proc
accepts keyword argument, either the keyword arguments
must be all optional (and they are not accepted in by the
arity-reduced procedure) or
arity
must be the empty list
(which makes a procedure that cannot be called); otherwise, the
exn:fail:contract
exception is raised.
If
name
is not
#f
, then
object-name
of the
result procedure produces
name
, and
procedure-realm
of the result produced produces
realm
. Otherwise,
object-name
and
procedure-realm
of the result procedure
produce the same result as for
proc
Examples:
define
my+
procedure-reduce-arity
my+
my+
+: arity mismatch;
the expected number of arguments does not match the given
number
expected: 2
given: 3
define
also-my+
procedure-reduce-arity
also-my+
also-my+
also-my+: arity mismatch;
the expected number of arguments does not match the given
number
expected: 2
given: 3
Changed in version 7.0.0.11 of package
base
: Added the optional
name
argument.
Changed in version 8.4.0.2: Added the
realm
argument.
procedure
procedure-reduce-arity-mask
proc
mask
name
realm
procedure?
proc
procedure?
mask
exact-integer?
name
or/c
symbol?
#f
#f
realm
symbol?
racket
The same as
procedure-reduce-arity
, but using the
representation of arity described with
procedure-arity-mask
The mask encoding of an arity is often easier to test and manipulate,
and
procedure-reduce-arity-mask
is sometimes faster than
procedure-reduce-arity
while always being at least as fast.
Added in version 7.0.0.11 of package
base
Changed in version 8.4.0.2: Added the
realm
argument.
procedure
procedure-keywords
proc
listof
keyword?
or/c
listof
keyword?
#f
proc
procedure?
Returns information about the keyword arguments required and accepted
by a procedure. The first result is a list of distinct keywords (sorted by
keyword) that are required when applying
proc
. The
second result is a list of distinct accepted keywords (sorted by
keyword), or
#f
to mean that any keyword is
accepted. When the second result is a list, every element in the first
list is also in the second list.
Examples:
procedure-keywords
'()
'()
procedure-keywords
lambda
#:tag
#:mode
'(#:mode #:tag)
'(#:mode #:tag)
procedure-keywords
lambda
#:tag
#:mode
#f
'(#:tag)
'(#:mode #:tag)
procedure
procedure-result-arity
proc
or/c
#f
procedure-arity?
proc
procedure?
Returns the arity of the result of the procedure
proc
or
#f
if the number of results are not known, perhaps due to shortcomings
in the implementation of
procedure-result-arity
or
because
proc
’s behavior is not sufficiently simple.
Examples:
procedure-result-arity
car
procedure-result-arity
values
#f
procedure-result-arity
apply
values
let
loop
cond
zero?
random
10
else
cons
loop
#f
Added in version 6.4.0.3 of package
base
procedure
make-keyword-procedure
proc
plain-proc
procedure?
proc
listof
keyword?
list?
any/c
...
->
any
plain-proc
procedure?
lambda
args
apply
proc
null
null
args
Returns a procedure that accepts all keyword arguments (without
requiring any keyword arguments).
When the procedure returned by
make-keyword-procedure
is called with keyword arguments, then
proc
is called; the first argument is a list of distinct keywords sorted by
keyword, the second argument is a parallel list containing a
value for each keyword, and the remaining arguments are the
by-position arguments.
When the procedure returned by
make-keyword-procedure
is called without keyword arguments, then
plain-proc
is called—
possibly more efficiently than
dispatching through
proc
. Normally,
plain-proc
should have the same behavior as calling
proc
with empty lists as
the first two arguments, but that correspondence is in no way
enforced.
The result of
procedure-arity
and
object-name
on the
new procedure is the same as for
plain-proc
, if
plain-proc
is provided. Otherwise, the result of
object-name
is the same as for
proc
but the result of
procedure-arity
is derived from that of
proc
by reducing its arity by 2 (i.e., without the two prefix
arguments that handle keyword arguments). See also
procedure-reduce-keyword-arity
and
procedure-rename
Examples:
define
show
make-keyword-procedure
lambda
kws
kw-args
rest
list
kws
kw-args
rest
show
'(() () (1))
show
#:init
#:extra
'((#:extra #:init) (4 0) (1 2 3))
define
show2
make-keyword-procedure
lambda
kws
kw-args
rest
list
kws
kw-args
rest
lambda
args
list->vector
args
show2
'#(1)
show2
#:init
#:extra
'((#:extra #:init) (4 0) (1 2 3))
procedure
procedure-reduce-keyword-arity
proc
arity
required-kws
allowed-kws
name
realm
procedure?
proc
procedure?
arity
procedure-arity?
required-kws
listof
keyword?
allowed-kws
or/c
listof
keyword?
#f
name
or/c
symbol?
#f
#f
realm
symbol?
racket
Like
procedure-reduce-arity
, but constrains the keyword
arguments according to
required-kws
and
allowed-kws
which must be sorted using
keywordand contain no duplicates. If
allowed-kws
is
#f
, then the resulting procedure still accepts any
keyword, otherwise the keywords in
required-kws
must be a
subset of those in
allowed-kws
. The original
proc
must require no more keywords than the ones listed in
required-kws
, and it must allow at least the keywords in
allowed-kws
(or it must allow all keywords if
allowed-kws
is
#f
).
Examples:
define
orig-show
make-keyword-procedure
lambda
kws
kw-args
rest
list
kws
kw-args
rest
define
show
procedure-reduce-keyword-arity
orig-show
#:init
#:extra
#:init
show
#:init
#:extra
'((#:extra #:init) (4 0) (1 2 3))
show
arity mismatch;
the expected number of arguments does not match the given
number
expected: 3 plus an argument with keyword #:init plus an
optional argument with keyword #:extra
given: 1
arguments...:
show
#:init
#:extra
#:more
application: procedure does not expect an argument with
given keyword
procedure: #
given keyword: #:more
arguments...:
#:extra 4
#:init 0
#:more 7
Changed in version 8.4.0.2 of package
base
: Added the
realm
argument.
procedure
procedure-reduce-keyword-arity-mask
proc
mask
required-kws
allowed-kws
name
realm
procedure?
proc
procedure?
mask
exact-integer?
required-kws
listof
keyword?
allowed-kws
or/c
listof
keyword?
#f
name
or/c
symbol?
#f
#f
realm
symbol?
racket
The same as
procedure-reduce-keyword-arity
, but using the
representation of arity described with
procedure-arity-mask
Added in version 7.0.0.11 of package
base
Changed in version 8.4.0.2: Added the
realm
argument.
struct
struct
arity-at-least
value
#:extra-constructor-name
make-arity-at-least
value
exact-nonnegative-integer?
A structure type used for the result of
procedure-arity
See also
procedure-arity?
value
prop:procedure
struct-type-property?
structure type property
to identify structure types whose
instances can be applied as procedures. In particular, when
procedure?
is applied to the instance, the result will be
#t
, and when an instance is used in the function position of
an application expression, a procedure is extracted from the instance
and used to complete the procedure call.
If the
prop:procedure
property value is an exact non-negative integer, it
designates a field within the structure that should contain a
procedure. The integer must be between
(inclusive) and the
number of non-automatic fields in the structure type (exclusive, not
counting supertype fields). The designated field must also be
specified as immutable, so that after an instance of the structure is
created, its procedure cannot be changed. (Otherwise, the arity and
name of the instance could change, and such mutations are generally
not allowed for procedures.) When the instance is used as the
procedure in an application expression, the value of the designated
field in the instance is used to complete the procedure call. (This
procedure can be another structure that acts as a procedure; the
immutability of procedure fields disallows cycles in the procedure
graph, so that the procedure call will eventually continue with a
non-structure procedure.) That procedure receives all of the arguments
from the application expression. The procedure’s name (see
object-name
), arity (see
procedure-arity
), and
keyword protocol (see
procedure-keywords
) are also used for
the name, arity, and keyword protocol of the structure. If the value
in the designated field is not a procedure, then the instance behaves
like
case-lambda
(i.e., a procedure which does not accept
any number of arguments). See also
procedure-extract-target
Providing an integer
proc-spec
argument to
make-struct-type
is the same as both supplying the value with
the
prop:procedure
property and designating the field as
immutable (so that a property binding or immutable designation is
redundant and disallowed).
Examples:
struct
annotated-proc
base
note
#:property
prop:procedure
struct-field-index
base
define
plus1
annotated-proc
lambda
"adds 1 to its argument"
procedure?
plus1
#t
annotated-proc?
plus1
#t
plus1
10
11
annotated-proc-note
plus1
"adds 1 to its argument"
When the
prop:procedure
value is a procedure, it should
accept at least one non-keyword argument. When an instance of the
structure is used in an application expression, the property-value
procedure is called with the instance as the first argument. The
remaining arguments to the property-value procedure are the arguments
from the application expression (including keyword arguments). Thus,
if the application expression provides five non-keyword arguments, the
property-value procedure is called with six non-keyword arguments. The
name of the instance (see
object-name
) and its keyword
protocol (see
procedure-keywords
) are unaffected by the
property-value procedure, but the instance’s arity is determined by
subtracting one from every possible non-keyword argument count of the
property-value procedure. If the property-value procedure cannot
accept at least one argument, then the instance behaves like
case-lambda
Providing a procedure
proc-spec
argument to
make-struct-type
is the same as supplying the value with the
prop:procedure
property (so that a specific property binding
is disallowed).
Examples:
struct
fish
weight
color
#:mutable
#:property
prop:procedure
lambda
let
fish-weight
set-fish-weight!
define
wanda
fish
12
red
fish?
wanda
#t
procedure?
wanda
#t
fish-weight
wanda
12
for-each
wanda
fish-weight
wanda
18
If the value supplied for the
prop:procedure
property is not
an exact non-negative integer or a procedure, the
exn:fail:contract
exception is raised.
procedure
procedure-struct-type?
type
boolean?
type
struct-type?
Returns
#t
if instances of the structure type represented by
type
are procedures (according to
procedure?
),
#f
otherwise.
procedure
procedure-extract-target
proc
or/c
#f
procedure?
proc
procedure?
If
proc
is an instance of a structure type with property
prop:procedure
, and if the property value indicates a field
of the structure, and if the field value is a procedure, then
procedure-extract-target
returns the field value. Otherwise,
the result is
#f
When a
prop:procedure
property value is a procedure, the
procedure is
not
returned by
procedure-extract-target
. Such a procedure is different from
one accessed through a structure field, because it consumes an extra
argument, which is always the structure that was applied as a
procedure. Keeping the procedure private ensures that is it always
called with a suitable first argument.
value
prop:arity-string
struct-type-property?
structure type property
that is used for reporting arity-mismatch errors when a
structure type with the
prop:procedure
property is applied to
the wrong number of arguments. The value of the
prop:arity-string
property must be a procedure that takes a
single argument, which is the misapplied structure, and returns a
string. The result string is used after the word “expects,” and it
is followed in the error message by the number of actual arguments.
Arity-mismatch reporting automatically uses
procedure-extract-target
when the
prop:arity-string
property is not associated with a procedure structure type.
Examples:
struct
evens
proc
#:property
prop:procedure
struct-field-index
proc
#:property
prop:arity-string
lambda
"an even number of arguments"
define
pairs
evens
case-lambda
null
more
cons
cons
apply
pairs
more
pairs
'((1 . 2) (3 . 4))
pairs
arity mismatch;
the expected number of arguments does not match the given
number
expected: an even number of arguments
given: 1
arguments...:
value
prop:checked-procedure
struct-type-property?
structure type property
that is used with
checked-procedure-check-and-extract
, which is a hook to allow
the compiler to improve the performance of keyword arguments. The
property can only be attached to a
structure type
without a
supertype and with at least two fields.
procedure
checked-procedure-check-and-extract
type
proc
v1
v2
any/c
type
struct-type?
any/c
proc
any/c
any/c
any/c
->
any/c
v1
any/c
v2
any/c
Extracts a value from
if it is an instance of
type
, which must have the property
prop:checked-procedure
. If
is such an instance,
then the first field of
is extracted and applied to
v1
and
v2
; if the result is a true value, the result
is the value of the second field of
If
is not an instance of
type
, or if the first
field of
applied to
v1
and
v2
produces
#f
, then
proc
is applied to
v1
and
v2
, and its result is returned by
checked-procedure-check-and-extract
procedure
procedure-specialize
proc
procedure?
proc
procedure?
Returns
proc
or its equivalent, but provides a hint to the
run-time system that it should spend extra time and memory to
specialize the implementation of
proc
The hint is currently used when
proc
is the value of a
lambda
or
case-lambda
form that references variables
bound outside of the
lambda
or
case-lambda
, and when
proc
has not been previously applied.
Added in version 6.3.0.10 of package
base
4.20.2
Reflecting on Primitives
primitive procedure
is a built-in procedure that may be
implemented in a lower-level language. Not all procedures of
racket/base
are primitives, but many are. The
distinction between primitives and other procedures may be useful to
other low-level code.
procedure
primitive?
boolean?
any/c
Returns
#t
if
is a primitive procedure,
#f
otherwise.
procedure
primitive-closure?
boolean?
any/c
Returns
#t
if
is internally implemented as a
primitive closure rather than a simple primitive procedure,
#f
otherwise.
procedure
primitive-result-arity
prim
procedure-arity?
prim
primitive?
Returns the arity of the result of the primitive procedure
prim
(as opposed to the procedure’s input arity as returned
by
procedure-arity
). For most primitives, this procedure
returns
, since most primitives return a single value when
applied.
4.20.3
Additional Higher-Order Functions
require
racket/function
package:
base
The bindings documented in this section are provided by the
racket/function
and
racket
libraries, but not
racket/base
procedure
identity
any/c
any/c
Returns
procedure
const
procedure?
any/c
Returns a procedure that accepts any arguments (including keyword
arguments) and returns
Examples:
const
foo
'foo
const
foo
'foo
const
foo
#:c
'foo
procedure
const*
...
procedure?
any/c
Similar to
const
, except it returns
s.
Examples:
const*
const*
const*
#:c
const*
foo
'foo
const*
foo
'foo
const*
foo
#:c
'foo
const*
foo
foo
'foo
'foo
const*
foo
foo
'foo
'foo
const*
foo
foo
#:c
'foo
'foo
Added in version 8.7.0.5 of package
base
syntax
thunk
body
...+
syntax
thunk*
body
...+
The
thunk
form creates a nullary function that evaluates the
given body. The
thunk*
form is similar, except that the
resulting function accepts any arguments (including keyword arguments).
Examples:
define
th1
thunk
define
printf
"~a\n"
th1
th1
th1: arity mismatch;
the expected number of arguments does not match the given
number
expected: 0
given: 1
th1
#:y
application: procedure does not accept keyword arguments
procedure: th1
arguments...:
#:y 'z
define
th2
thunk*
define
printf
"~a\n"
th2
th2
th2
#:y
procedure
negate
proc
procedure?
proc
procedure?
Returns a procedure that is just like
proc
, except that it
returns the
not
of
proc
’s result.
Examples:
filter
negate
symbol?
'(1 2 3)
map
negate
'(#f #t #t)
procedure
((
conjoin
...
...
any
procedure?
any/c
Combines calls to each function with
and
. Equivalent to
and
...
...
Examples:
define
conjoin
exact?
integer?
#t
1.0
#f
1/2
#f
0.5
#f
conjoin
values
procedure
((
disjoin
...
...
any
procedure?
any/c
Combines calls to each function with
or
. Equivalent to
or
...
...
Examples:
define
disjoin
exact?
integer?
#t
1.0
#t
1/2
#t
0.5
#f
disjoin
values
procedure
curry
proc
procedure?
proc
procedure?
curry
proc
...+
any
proc
procedure?
any/c
The result of
curry
proc
is a procedure that is a curried
version of
proc
. When
the resulting procedure is first applied, unless it is given the
maximum number of arguments that it can accept according to
procedure-arity
proc
, the result is a
procedure to accept additional arguments.
Examples:
curry
list
#
curry
cons
#
curry
cons
'(1 . 2)
After the first application of the result of
curry
proc
, each
further application accumulates arguments until an acceptable number
of arguments according to
procedure-arity
proc
have been
accumulated, at which point the original
proc
is called.
Examples:
curry
list
'(1 2 3)
curry
list
'(1 3)
curry
foldl
define
foo
curry
lambda
list
foo
'(1 2 3)
foo
'(1 2 3)
A function call
curry
proc
...
is equivalent to
curry
proc
...
. In other words,
curry
itself
is curried.
Examples:
map
curry
10
'(11 12 13)
map
curry
10
'(11 12 13)
map
compose
curry
curry
10
'(22 24 26)
The
curry
function also supports functions with keyword arguments:
keyword arguments will be accumulated in the same way as positional arguments
until all required keyword arguments according to
procedure-keywords
proc
have been supplied.
Examples:
define
#:a
#:b
#:c
list
curry
#:a
#:b
#:c
'(1 2 3)
curry
#:b
#:c
#:a
'(3 1 2)
curry
#:a
#:c
#:b
'(1 3 2)
Changed in version 7.0.0.7 of package
base
: Added support for keyword arguments.
procedure
curryr
proc
procedure?
proc
procedure?
curryr
proc
...+
any
proc
procedure?
any/c
Like
curry
, except that the arguments are collected in the
opposite direction: the first step collects the rightmost group of
arguments, and following steps add arguments to the left of these.
Example:
map
curryr
list
foo
'((1 foo) (2 foo) (3 foo))
procedure
normalized-arity?
arity
boolean?
arity
any/c
A normalized arity has one of the following forms:
the empty list;
an exact non-negative integer;
an
arity-at-least
instance;
a list of two or more strictly increasing, exact non-negative integers;
or
a list of one or more strictly increasing, exact non-negative integers
followed by a single
arity-at-least
instance whose value is greater
than the preceding integer by at least 2.
Every normalized arity is a valid procedure arity and satisfies
procedure-arity?
. Any two normalized arity values that are
arity=?
must also be
equal?
Examples:
normalized-arity?
arity-at-least
#t
normalized-arity?
list
arity-at-least
#f
normalized-arity?
list
arity-at-least
#t
normalized-arity?
list
arity-at-least
#f
normalized-arity?
list
arity-at-least
#f
procedure
normalize-arity
arity
and/c
normalized-arity?
lambda
arity=?
arity
arity
procedure-arity?
Produces a normalized form of
arity
. See also
normalized-arity?
and
arity=?
Examples:
normalize-arity
normalize-arity
list
normalize-arity
arity-at-least
(arity-at-least 2)
normalize-arity
list
arity-at-least
(arity-at-least 2)
normalize-arity
list
arity-at-least
(arity-at-least 1)
normalize-arity
list
arity-at-least
(arity-at-least 1)
normalize-arity
list
arity-at-least
(arity-at-least 2)
normalize-arity
list
arity-at-least
(arity-at-least 2)
normalize-arity
list
arity-at-least
arity-at-least
(list 0 2 (arity-at-least 4))
procedure
arity=?
boolean?
procedure-arity?
procedure-arity?
Returns
#true
if procedures with arity
and
accept the same numbers of arguments, and
#false
otherwise.
Equivalent to both
and
arity-includes?
arity-includes?
and
equal?
normalize-arity
normalize-arity
Examples:
arity=?
#t
arity=?
list
#t
arity=?
list
#t
arity=?
arity-at-least
#f
arity=?
arity-at-least
#f
arity=?
arity-at-least
list
arity-at-least
#t
arity=?
list
arity-at-least
arity-at-least
#t
arity=?
arity-at-least
list
arity-at-least
#f
arity=?
list
arity-at-least
arity-at-least
#f
arity=?
list
arity-at-least
list
arity-at-least
#t
arity=?
list
arity-at-least
list
arity-at-least
#t
arity=?
list
arity-at-least
list
arity-at-least
#f
arity=?
list
arity-at-least
list
arity-at-least
#f
procedure
arity-includes?
boolean?
procedure-arity?
procedure-arity?
Returns
#true
if procedures with arity
accept any number of
arguments that procedures with arity
accept.
Examples:
arity-includes?
#t
arity-includes?
list
#t
arity-includes?
list
#t
arity-includes?
arity-at-least
#f
arity-includes?
arity-at-least
#t
arity-includes?
arity-at-least
list
arity-at-least
#t
arity-includes?
list
arity-at-least
arity-at-least
#t
arity-includes?
arity-at-least
list
arity-at-least
#t
arity-includes?
list
arity-at-least
arity-at-least
#f
arity-includes?
list
arity-at-least
list
arity-at-least
#t
arity-includes?
list
arity-at-least
list
arity-at-least
#t
arity-includes?
list
arity-at-least
list
arity-at-least
#f
arity-includes?
list
arity-at-least
list
arity-at-least
#t
top
contents
← prev
up
next →