Functors
This chapter describes how to create, combine and use functors from the MAD
environment. Functors are objects that behave like functions with callable semantic, and also like readonly arrays with indexable semantic, where the index is translated as a unique argument into the function call. They are mainly used by the object model to distinguish them from functions which are interpreted as deferred expressions and evaluated automatically on reading, and by the Survey and Track tracking codes to handle (user-defined) actions.
Constructors
This module provides mostly constructors to create functors from functions, functors and any objects with callable semantic, and combine them all together.
- functor(f)
Return a functor that encapsulates the function (or any callable object)
f
. Calling the returned functor is like callingf
itself with the same arguments.
- compose(f, g)
Return a functor that encapsulates the composition of
f
andg
. Calling the returned functor is like calling \((f \circ g)(\dots)\). The operatorf ^ g
is a shortcut forcompose
iff
is a functor.
- chain(f, g)
Return a functor that encapsulates the calls chain of
f
andg
. Calling the returned functor is like calling \(f(\dots) ; g(\dots)\). The operatorf .. g
is a shortcut forchain
iff
is a functor.
- achain(f, g)
Return a functor that encapsulates the AND-ed calls chain of
f
andg
. Calling the returned functor is like calling \(f(\dots) \land g(\dots)\).
- ochain(f, g)
Return a functor that encapsulates the OR-ed calls chain of
f
andg
. Calling the returned functor is like calling \(f(\dots) \lor g(\dots)\).
- bind1st(f, a)
Return a functor that encapsulates
f
and bindsa
as its first argument. Calling the returned functor is like calling \(f(a,\dots)\).
- bind2nd(f, b)
Return a functor that encapsulates
f
and bindsb
as its second argument. Calling the returned functor is like calling \(f(a,b,\dots)\) wherea
may or may not be provided.
- bind3rd(f, c)
Return a functor that encapsulates
f
and bindsc
as its third argument. Calling the returned functor is like calling \(f(a,b,c,\dots)\) wherea
andb
may or may not be provided.
- bind2st(f, a, b)
Return a functor that encapsulates
f
and bindsa
andb
as its two first arguments. Calling the returned functor is like calling \(f(a,b,\dots)\).
- bind3st(f, a, b, c)
Return a functor that encapsulates
f
and bindsa
,b
andc
as its three first arguments. Calling the returned functor is like calling \(f(a,b,c,\dots)\).
- bottom()
Return a functor that encapsulates the identity function
ident
to define the bottom symbol of functors. Bottom is also available in the operator strings tableopstr
as"_|_"
.
Functions
- is_functor(a)
Return
true
ifa
is a functor,false
otherwise. This function is only available from the moduleMAD.typeid
.