The Fabl Manual
Function Index
Class Index
Globals Index
Libraries
Contents

Title Page
Introduction
Sample Code
Architecture
Syntax
Strong Typing
Polymorphism
Operators
Help
Errors
Configuration
RDF
Namespaces
Owl
Datatypes
Resources
Dot ops
Coercion
Type Casting
nil

Types
string
id
int
double
boolean
Literal
Containers
Functions
void

Home
Regarding
The Path
Classes
Delegation
Functional Values
Read/Write
Load/Store
Libraries
Imports
CGI
Functional Values

Functions, like types, are first class values in Fabl. An expression of the form

<function-name>[<Type1>,<Type2> ... <Typen>]

returns the function, if any, with name <function-name> and input types <Type1> ... <Typen> For example:

int function twice(int n){return n+n}
var fnv = twice[int];
fnv(4);
-->8

SeqOf(int) function mapOver(SeqOf(int) vls,Function(int,int) fn)
{
var SeqOf(int) rs,int ln,i;
ln = length(vls);
rs = new(SeqOf(int));
for (i=0;i<ln;i++) push(rs,fn(vls[i]));
return rs;
}

mapOver([1,2,3],fnv);
-->[2,4,6]

supplyArgument

The function

<SupFunType> supplyArgument(<FunType> fn,<Type0> val)

returns the function sfn that results from supplying val as the fixed value of the first argument to fn; sfn takes one fewer argument than fn. Here is an example:

install(namespace('geom'));
install(namespace('geom2d'));
install(namespace('libgeom2d'));
push(path,namespace('libgeom2d'));


var p0 = mkPoint(1,2);

var distanceFromP0 = supplyArgument(distance[geom2d:Point,geom2d:Point],p0);

distanceFromP0(mkPoint(3,2));
-->2

As of version 2.0.11, the supplyArgument primitive cannot be iterated. So, for example:

supplyArgument(distanceFromP0,mkPoint(4,5));
yields the message;
-->Not yet: iterated supplyArgument