lac : edd86ac2c5a7d82e798742cea3071671d0240c7c

     1: (defun fact (n)
     2:   (cond 
     3:     ((eq n 1) 1) 
     4:     (t (* n (fact (- n 1))))))
     5: 
     6: (defun sum (n)
     7:   (cond 
     8:     ((eq n 1) 1) 
     9:     (t (+ n (sum (- n 1))))))
    10: 
    11: (defun fib (n)
    12:   (cond 
    13:     ((< n 2) n)
    14:     (t (+ (fib (- n 2)) (fib (- n 1))))))
    15: 
    16: (defun gcd (a b)
    17:   (cond
    18:     ((eq b 0) a)
    19:     (t (gcd b (% a b)))))
    20: 
    21: (defun f-collatz (n)
    22:   (cond 
    23:     ((eq n 1) 1)
    24:     ((evenp n) (setq n (/ n 2))) 
    25:     (t (setq n (+ (* 3 n) 1)))))
    26: 
    27: (defun collatz (n)
    28: 	(cond
    29: 		((eq n 1) (list 1))
    30: 		(t (cons n (collatz (f-collatz n)))))
    31: )
    32: 
    33: ; 'A short ballad dedicated to the growth of programs'
    34: ;  http://cognitivecomputing.wordpress.com/1986/01/28/a-short-ballad-dedicated-to-the-growth-of-programs/
    35: (defun values-with-keys (key alist)
    36:   (cdr (assq key alist)))
    37: 
    38: ; Lambda over Let over Lambda example
    39: (define counter-class (lambda () (let ((x 0)) (lambda () (incf x)))))
    40: ; Two counters
    41: (define counter1 (counter-class))
    42: (define counter2 (counter-class))
    43: 
    44: ; Increment the counters
    45: (counter1)
    46: (counter1)
    47: (counter1)
    48: (counter1)
    49: (counter1)
    50: (counter2)
    51: 

Generated by git2html.