Illinois FP User Manual

Domain of Objects

Objects in IFP are either atoms, sequences, or bottom. The latter is a special object which denotes an undefined value. Atoms are numbers, strings, or boolean values. Strings must be quoted when they look like another kind of atom of contain non-alphanumeric characters. Below is a table of some typical atoms:

banana string
"Bryn Mawr College" string (double quotes)
'hello world' string (single quotes)
7 number
3.1415 number
1e6 number (million)
"1.414" string
t boolean true
f boolean false
"f" string

Sequences are lists of zero or more objects surrounded by angle brackets. Sequences are written as:

<x1, x2, ..., x3>

Below is a table of some typical sequences:

<a, b, c>
<1 2 3 4 5 6>
< >
<<1 2 3> <brynmawr haverford swarthmore> t>

Either commas or spaces may be used to separate the elements of a sequence. The elements of the sequence may be any kind of object except "?", and do not have to be of the same type.

Functions

Primitive Functions

The following sets (types) are used in the definitions of functions:

A atoms
B boolean values
O objects
R real numbers
Z integers
S strings
T* sequences with element type T
T+ non-empty sequences with element type T
Tn sequences of length n with element type T
T[n,m] sequences of length m with element type Tn
[T1, T2] pair of types T1 and T2

A function returns "?" if its argument is not in its domain. The notation Xn denotes the nth element of a sequence X.

Structural Functions

Name Domain Definition
apndl [X, Y] belongs to [O, On] <X, y1, y2, ..., yn>
apndr [X, Y] belongs to [Om, O] <x1, x2, ..., xm, Y>
cat X belongs to Onm

catenate subsequences, e.g.

<<a b> <x> <3 5>> -> <a b x 3 5>

distl [X, Y] belongs to [O, On] <<X, y1><X, y2>, ..., <X, yn>>
distr [X, Y] belongs to [Om, O] <<x1, Y><x2, Y>...<xm, Y>>
dropl [X, K] belongs to [On, 0<=Z<=n] <xk+1, xk+2, ...xn>
dropr [X, K] belongs to [On, 0<=Z<=n] <x1, x2, ..., xn-k>
iota n belongs to Z>=0 <1, 2, ..., n>
length Z belongs to On n
pick [X, K] belongs to [On, 0<Z<=n] Xk
repeat [X, K] belongs to [O, 0<=Z] sequence <x, x, ..., x> of length K
reverse X belongs to On <xn, xn-1, ..., x1>
takel [X, K] belongs to [On, 0 <=Z<=n] <x1, x2, ..., xk>
taker [X, K] belongs to [On, 0 <=Z<=n] <xn-k+1, xn-k+2, ..., xn>
tl X belongs to Om, m > 0 <x2, x3, ..., xm>
tlr X belongs to Om, m > 0 <x1, x2, ..., xm-1>
trans X belongs to O[n, m]

transpose matrix, e.g.

<<a 1><b 2><c 3>> -> <<a b c><1 2 3>>

Math Functions

Name Domain Definition
+ [X, Y] belongs to [R, R] X + Y
- ... X - Y
* ... X * Y
% ... X / Y
add1 X belongs to R X + 1
arcsin X belongs to R, -1 <= X <= 1 arcsin(X)
arccos ... arccos(X)
arctan X belongs to R arctan(X)
cos ... cos(X)
div [X, Y] belongs to [R, R<>0] X div Y
exp X elongs to R e^X
ln X belongs to R > 0 loge(X)
max [X, Y] belongs to [R, R] max(X, Y)
min [X, Y] belongs to [R, R] min(X, Y)
minus X belongs to R -X
mod [X, Y] belongs to [R, R] X mod Y
power [X, Y] belongs to [R>=0, R] X^Y
sin X belongs to R sin(X)
sqrt X belongs to R > 0 sqrt(X)
sub1 X belongs to R X - 1
sum X belongs to R* x1+x2+...+xn
tan X belongs to R tan(X)

Logic Functions

Name Domain Definition
= [X, Y] belongs to [O, O] X = Y
~= ... X <> Y
< [X, Y] belongs to [R, R]+[S, S] X < Y
<= ... X <= Y
>= ... X >= Y
> ... X > Y
~ X belongs to B ~X
and [X, Y] belongs to [B, B] X and Y
all X belongs to B* x1 and x2 and x3....and xn
any ... x1 or x2.....or xn
atom X belongs to O X belongs to A
boolean X belongs to O X belongs to B
false X belongs to O X = f
imply [X, Y] belongs to [B, B] ~XvY
longer [X, Y] belongs to [Om, On] m > n
member [X, Y] belongs to [O*, O] Y belongs to X
null X belongs to O* X = <>
numeric X belongs to O X belongs to R
odd X belongs to Z X is odd
or [X, Y] belongs to [B, B] XvY
pair X belongs to O X belongs to [O, O]
shorter [X, Y] belongs to [Om, On] m < n
xor [X, Y] belongs to [B, B] X xor Y

String Functions

Name Domain Definition
explode X belongs to S sequence of charatcters in X
implode X belongs to S* string made by catenating strings in X
patom X belongs to A

string representation of X, e.g.

123 : patom -> "123"

Miscellaneous functions

Name Domain Definition
apply [X, F] belongs to [O, S*]

apply F to X, e.g.

<<3 4> (+)> : apply -> 7

assoc [X, Y] belongs to [(O+)*, O]

associative lookup. e.g.

<<<a 1> <b 2> <c 3>> b> : assoc -> <b 2>
<<<a 1> <c 3> <d 4>> b> : assoc -> f

id X belongs to O identity

User Defined Functions

DEF foo AS bar;

where foo is the name of the function and bar is the definition. Example,

DEF Square AS [id, id] | *;

Functional Forms

Constant

Constant functions always return the same result when applied to any value which is not "?". Constant functions are written as:

#c

where c is the constant value to be returned. A constant function applied to "?" results in "?". Examples:

923 : #<cat in hat> -> <cat in hat>
<a b c d e f> : #427 -> 427
? : #<q w e r t y> -> ?
5 : #? -> ?

Selection

Selector functions return the nth element of a sequence and are written as n, where n is a positive integer. There are also a corresponding set of select-from-right functions, written as nr. These select the nth element of a sequence countinf from right. Examples:

<a b c d e> : 1 -> a
<a b c d e> : 2 -> b
<apple banana cherry> : 1r -> cherry
<apple banana cherry> : 4 -> ?
hello : 1 -> ?

Composition

f | g

is the same as applying f and then g, i.e.

x : f | g

will return the result of f(g(x)). Since function composition is associative, the composition of more than two fucntions is written as:

f1 | f2 | ... | fn

Construction

[f1, f2, ..., fn]

i.e.

x : [f1, f2, ..., fn] is the same as <x:f1, x:f2, ..., x:fn>

Apply to Each

EACH f END

is defined as:

<x1, x2, ..., xn> : EACH f END -> <x1:f, x2:f, ..., xn:f>

If-Then-Else

The IF fucntional form allows conditional function application. It is written as:

IF p THEN g ELSE h END

and is defined as

x : IF p THEN g ELSE h END -> g(x) if p(x) = t; h(x) if p(x) = f; ? otherwise

The level of nesting of conditional forms may be reduced by using ELSIF clauses.

Filter

The FILTER functional form filters through elements of a sequence satisfying a predicate. It is written as:

FILTER p END

For example,

<1 a 2 b 3 c> : FILTER numeric END -> <1 2 3>

Right Insert

INSERT f END

Example:

<1 2 3 4 5> : INSERT + END -> 15

While

The WHILE functional form allows indefinite composition. It is written as:

WHILE p DO f END

Fetch

The FETCH functional form allows easy access to association sequences (see assoc above). A fetch is written as ^c, where c is an object. Example:

<<a 1> <b 2> <c 3>> : ^b -> 2

Comments

Comments are identified by matching pairs of "(*" and "*)".