;;;; 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.
;;;; .title The program prog1
;;;; .author Kurt Nørmark
;;; The fac and fib functions.
;; Calculate the factorial of n
Show source file in large font In prog1: Link from fac to it's cross reference table entry 
(define (fac n) (if (= 0 n) 1 (* n (fac (- n 1))))) ;; Calculated the fib function. ;; Notice that this is a very inefficient ;; Implementation. Show source file in large font In prog1: Link from fib to it's cross reference table entry 
(define (fib n) (cond ((or (= n 0) (= n 1)) 1) (else (+ (fib (- n 1)) (fib (- n 2)))))) ;;; A couple of higher order function. ;;; These functions are useful in many situations. ;; A higher order functions which negates the predicate p. ;; Negate accepts a predicate and returns the negated predicate. Show source file in large font In prog1: Link from negate to it's cross reference table entry 
(define (negate p) (lambda (x) (if (p x) #f #t))) ;; 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. Show source file in large font In prog1: Link from compose to it's cross reference table entry 
(define (compose f g) (lambda (x) (f (g x))))