~james/gengo

gengo/samples-test/samples/Scheme/example.scm -rw-r--r-- 450 bytes
50871857 — james chore(import): snapshot james.dad.town/gengo at 8f775550b0ee 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
; Provides basic mathematical utilities

; Gets n!
(define (factorial n)
  (if (<= n 1)
    1
    (* n (factorial (- n 1)))))

; Gets the nth element of the fibonacci sequence
(define (fibonacci n)
  (cond ((< n 0) (error "n cannot be negative"))
        ((<= n 1) n)
        (else (+ (fibonacci (- n 1)) (fibonacci (- n 2))))))

; Reverses a list
(define (reverse-list l)
  (if (null? l)
    '()
    (append (reverse-list (cdr l)) (list (car l)))))