Chapter 12
The BuiltIn Functions
Functional Operations
The following operations are used to create new functions from other functions or objects. Often the Dylan compiler will have special knowledge of these operations to allow for efficient inline compilation.
compose
[Function]
Returns the composition of one or more functions.
 Signature:

compose function1 #rest morefunctions
⇒function
 Arguments:

 function1
An instance of
<function>
. morefunctions
Instances of
<function>
.
 Values:

 function

An instance of
<function>
.
 Description:

When called with just a single argument,
compose
returns that argument.When called with two arguments,
compose
returns a function that applies the second function to its arguments and then applies the first function to the (single) result value.With three or more arguments,
compose
composes pairs of argument functions, until a single composite function is obtained. (It doesn't matter if the pairings are done from the left or from the right, as long as the order of application is preserved.)define constant numberofmethods = compose(size, genericfunctionmethods) define constant rootposition = compose(position, rootview)
complement
[Function]
Returns a function that expresses the complement of a predicate.
 Signature:

complement predicate
⇒function
 Arguments:

 predicate

An instance of
<function>
.
 Values:

 function

An instance of
<function>
.
 Description:

Returns a function that applies predicate to its arguments. If the predicate returns
#f
, the complement returns#t
; otherwise, the complement returns#f
. For example,odd?
could be defined ascomplement(even?)
.choose(complement(zero?), #(1, 3, 0, 4, 0, 0, 3)) ⇒ #(1, 3, 4, 3)
disjoin
[Function]
Returns a function that expresses the disjunction of one or more predicates.
 Signature:

disjoin predicate1 #rest morepredicates
⇒function
 Arguments:

 predicate1
An instance of
<function>
. morepredicates
Functions.
 Values:

 function

An instance of
<function>
.
 Description:

Returns a single function, termed the disjunction of its argument functions. The disjunction accepts any number of arguments and operates by applying the predicates, in order, to the arguments. If any of the predicates returns true, the remaining predicates (if any) are not applied, and the true result is returned. Otherwise, all the predicates will be applied, and
#f
returned.A disjunction is similar to an

expression of calls to the predicates.define constant nonzero? = disjoin(positive?, negative?); nonzero?(4)
⇒
#t
conjoin
[Function]
Returns a function that expresses the conjunction of one or more predicates.
 Signature:

conjoin predicate1 #rest morepredicates
⇒function
 Arguments:

 predicate1
An instance of
<function>
. morepredicates
Instances of
<function>
.
 Values:

 function

An instance of
<function>
.
 Description:

Returns a single function, termed the conjunction of its argument functions. The conjunction accepts any number of arguments and operates by applying the predicates, in order, to the arguments. If any of the predicates returns
#f
, the remaining predicates (if any) are not applied and#f
is immediately returned. Otherwise, all the predicates will be applied, and the result of the last application is returned.A conjunction is similar to an
&
expression of calls to the predicates.choose(conjoin(positive?, integral?), #(1, 3, 5, 3.7, 3.5, 7)) ⇒ #(5, 7)
curry
[Function]
Returns a function based on an existing function and a number of default initial arguments.
 Signature:

curry function #rest curriedargs
⇒newfunction
 Arguments:

 function
An instance of
<function>
. curriedargs
Instances of
<object>
.
 Values:

 newfunction

An instance of
<function>
.
 Description:

Returns a function that applies function to curriedargs plus its own arguments, in that order. For example
curry (\>, 6)
is a predicate that returns true for values less than 6;curry (\=, "x")
is a predicate that tests for equality with the string"x"
;curry (\+, 1)
is an incrementing function;curry (concatenate, "set")
is a function that concatenates the string"set"
to any additional sequences it is passed.define constant allodd? = curry(every?, odd?) allodd?(list(1, 3, 5))
⇒
#t define constant lessthan10? = curry(\>, 10) lessthan10?(4)⇒
#t
rcurry
[Function]
Returns a function based on an existing function and a number of default final arguments.
 Signature:

rcurry function #rest curriedargs
⇒newfunction
 Arguments:

 function
An instance of
<function>
. curriedargs
Instances of
<object>
.
 Values:

 newfunction

An instance of
<function>
.
 Description:

Returns a function that applies function to curriedargs plus its own arguments, with the curriedargs occurring last.
rcurry
("right" curry) operates just likecurry
, except it allows the rightmost arguments of function to be specified in advance, rather than the leftmost arguments. For example,rcurry (\>, 6)
is a predicate that returns true for values greater than 6.define constant number? = rcurry(instance?, <number>) number?(4)
⇒
#t number?("string")⇒
#f define constant greaterthan10? = rcurry(\>, 10) greaterthan10?(4)⇒
#f
always
[Function]
Returns a function that always returns a particular object.
 Signature:

always object
⇒function
 Arguments:

 object
An instance of
<object>
.
 Values:

 function

An instance of
<function>
.
 Description:

Returns a function that can be called with any number of arguments. The function ignores its arguments and always returns object.
define constant menu = always("spam!") menu("today")
⇒
"spam!" menu("tomorrow")⇒
"spam!" menu(4, 5, 6)⇒
"spam!"