Generated: June 17, 2002, 15:29:52Copyright ©2002, Kurt NørmarkThe local LAML software home page

Prog3 Manual

Kurt Nørmark ©    normark@cs.auc.dk    Department of Computer Science    Aalborg University    Denmark    

Source file: examples/tutorial/schemedoc/prog3.scm
LAML Version 17.20 (June 1, 2002) development

This is a Scheme file with a few simple functions. The functions are written and organized with the purpose of demonstrating the LAML SchemeDoc tool.

Table of Contents:
1. The fac and fib functions.2. A couple of higher order function.3. List selector functions.

Alphabetic index:
compose(compose f g)A higher order function that composes two functions.
fac(fac n)Calculate the factorial of n.
fib(fib n)Calculated the fib function.
first(first lst)Return the first element of a list
negate(negate p)A higher order functions which negates the predicate p.
second(second lst)Return the second element of a list

 

1.   THE FAC AND FIB FUNCTIONS.


fac


Form
(fac n)

Description
Calculate the factorial of n.

Preconditions
The integer must be non-negative.

Parameters
nAn integer

Returns
n!


fib


Form
(fib n)

Description
Calculated the fib function. Notice that this is a very inefficient implementation.

Preconditions
The integer must be non-negative.

Parameters
nAn integer

Returns
The n't fiabonaci number.


 

2.   A COUPLE OF HIGHER ORDER FUNCTION.
These functions are useful in many situations.


negate


Form
(negate p)

Description
A higher order functions which negates the predicate p. Negate accepts a predicate and returns the negated predicate.

Parameters
pa predicate - p: type -> boolean for any type.

Returns
A predicate that returns the negated value. Thus (not ((negate p) x)) = (p x) for all x.


compose


Form
(compose f g)

Description
A higher order function that composes two functions. Returns a function which applies f on g. Both f and g are supposed to take a single argument.

Parameters
fA function of a single parameter.
gA function of a singe parameter.

Returns
f ° g


 

3.   LIST SELECTOR FUNCTIONS.
The functions in this category are alternatives for car, cadr, etc.


first


Form
(first lst)

Description
Return the first element of a list

Parameters
lstA list

Returns
the first element of the list


second


Form
(second lst)

Description
Return the second element of a list

Parameters
lstA list

Returns
the second element of the list


Generated: June 17, 2002, 15:29:52
This documentation has been extracted automatically from the Scheme source file by means of the Schemedoc tool