|
|
| Jensen.scm |
(define (range n m) (cond ((= n m) (list n)) ((< n m) (cons n (range (+ n 1) m))) (else '()) ) ) (define (sigma x n) (apply + (map x (range 1 n))) ) |
![]() | The same, however, can also be achieved using
anonymous procedures. Instead of passing a parameter i
to sigma that references a variable within the lexical
closure of x, we can pass a parameter directly to sigma.
|
guile> (sigma (lambda (i) i) 3) 6 guile> (define x '#(1 2 3)) guile> (define y '#(4 5 6)) guile> (range 1 3) (1 2 3) guile> (sigma (lambda (i) (* (vector-ref x (- i 1)) ... (vector-ref y (- i 1)))) 3) 32 guile> |
|
| Copyright © 2002 Andreas Borchert, converted to HTML on May 02, 2002 |