Mercurial > rlm
annotate src/rlm/elisp_example.el @ 0:78a630e650d2
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Oct 2011 00:57:08 -0700 |
parents | |
children |
rev | line source |
---|---|
rlm@0 | 1 |
rlm@0 | 2 ;;No BigNum Promotion |
rlm@0 | 3 (defun factorial (n &optional f) |
rlm@0 | 4 (cond ((null f) (factorial n 1)) |
rlm@0 | 5 ((<= n 1) f) |
rlm@0 | 6 (t (factorial (- n 1) (* n f))))) |
rlm@0 | 7 |
rlm@0 | 8 ;; No Tail Recursion |
rlm@0 | 9 (defun count (n &optional work) |
rlm@0 | 10 (cond ((<= n 0) work) |
rlm@0 | 11 (t (count (- n 1) (cons n work))))) |
rlm@0 | 12 |
rlm@0 | 13 ;;Shallow Dynamic Variables by Default |
rlm@0 | 14 (setq x 3) |
rlm@0 | 15 |
rlm@0 | 16 (defun whatisx () |
rlm@0 | 17 x) |
rlm@0 | 18 |
rlm@0 | 19 (defun frobx () |
rlm@0 | 20 (setq x 5) |
rlm@0 | 21 (whatisx)) |
rlm@0 | 22 |
rlm@0 | 23 (defun mungex (x) |
rlm@0 | 24 (whatisx)) |
rlm@0 | 25 |
rlm@0 | 26 (defun duncant () |
rlm@0 | 27 (print n)) |
rlm@0 | 28 |
rlm@0 | 29 (defun rlm (n) |
rlm@0 | 30 (duncant)) |
rlm@0 | 31 |
rlm@0 | 32 ;; no namespaces :( |
rlm@0 | 33 |
rlm@0 | 34 ;; compiles to bytecode, very small memory footprint |
rlm@0 | 35 |
rlm@0 | 36 ;; LISP 2 |
rlm@0 | 37 (reduce + '(1 2 3 4)) ;;doesn't work |
rlm@0 | 38 (reduce (function +) '(1 2 3 4)) ;;have to do this! |
rlm@0 | 39 (reduce #'+ '(1 2 3 4)) ;;this works too... |