;;;; 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![]()
![]()
(define (fac n) (if (= 0 n) 1 (* n (fac (- n 1))))) ;; Calculated the fib function. ;; Notice that this is a very inefficient ;; Implementation.![]()
![]()
(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.![]()
![]()
(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.![]()
![]()
(define (compose f g) (lambda (x) (f (g x))))