summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--com.c16
-rw-r--r--doc.txt28
2 files changed, 27 insertions, 17 deletions
diff --git a/com.c b/com.c
index e14bbc6..9b5055b 100644
--- a/com.c
+++ b/com.c
@@ -591,19 +591,19 @@ typedef struct {
} BuiltinForm;
static BuiltinForm builtin_forms[] = {
- { "set!", 2, false, set_form, 0 },
+ { "arrlit", 1, false, arrlit_form, 0 },
+ { "def", 2, false, def_form, 0 },
+ { "defn", 2, true, defn_form, 0 },
{ "do", 1, true, do_form, 0 },
- { "if", 3, false, if_form, 0 },
- { "when", 2, true, when_form, 0 },
- { "while", 2, true, while_form, 0 },
- { "for", 2, true, for_form, 0 },
{ "each", 2, true, each_form, 0 },
{ "fn", 2, true, fn_form, 0 },
+ { "for", 2, true, for_form, 0 },
+ { "if", 3, false, if_form, 0 },
{ "let", 2, true, let_form, 0 },
- { "def", 2, false, def_form, 0 },
- { "defn", 2, true, defn_form, 0 },
{ "quote", 1, false, quote_form, 0 },
- { "arrlit", 1, false, arrlit_form, 0 },
+ { "set!", 2, false, set_form, 0 },
+ { "when", 2, true, when_form, 0 },
+ { "while", 2, true, while_form, 0 },
#define ARITH_OP(str, op) \
{ str, 2, false, arith_form, op },
ARITH_OP("+", OP_ADD)
diff --git a/doc.txt b/doc.txt
index 0c84bcc..b597f46 100644
--- a/doc.txt
+++ b/doc.txt
@@ -6,7 +6,7 @@
func: badthing function
arr: [ 10 20 30 ] array of badthing values
array indexing is the same as function calling: (a 1) -> 20
- string: "hii".
+ string: 'word "string with spaces"
strings are interned: two strings with the same contents
are always the same object in memory
@@ -21,34 +21,44 @@
# builtin forms
arithmetic: + - * / % (+ 1 2)
- equality: (= (+ 2 2) 4)
comparison: (< 0 1). ">" omitted deliberately.
+ equality: (= (+ 2 2) 4)
+ arrlit: internal; [1 2 3] is technically sugar for (arrlit (1 2 3))
+ def: (def foo 123) creates new local in current scope
+ defn: (defn (f x) body...) function's name bound as local within body
+ do: (do body...) returns value of last expr in body
+ each: (each (x arr) body...) array for-each loop. returns nil
+ fn: (fn (arg0 arg1 arg2) body...) anonymous. for now.
+ for: (for (i 10) body...) numeric for loop, i=0,1,...,9 returns nil
+ if: (if cond true-expr false-expr)
let: unremarkable. (let (a 100 b 200) (+ a b))
+ quote: internal. 'foo and "foo" are technically sugar for (quote foo)
set!: mutates values. (set! x 10)
arrays: (set! (a 1) 20) sets index 1 of a
setting 1 past the end of an array will append
- if: (if cond true-expr false-expr)
+ when: (when cond body...) like if with multiple body exprs. returns nil
while: (while cond body...) returns nil
- for: (for (i 10) body...) numeric for loop, i=0,1,...,9 returns nil
- each: (each (x arr) body...) array for-each loop. returns nil
- do: (do body...) returns value of last expr in body
- def: (def foo 123) creates new local in current scope
- fn: (fn (arg0 arg1 arg2) body...) anonymous. for now.
- defn: (defn (f x) body...) function's name bound as local within body
# builtin functions
(clock): clock(3)
(say x): print representation of x, followed by newline
(write x): print representation of x, with no newline
(writebytes a): a is a list of nums in [0,255]
+ (readstring filename): reads whole file as a string
(arr): create new empty array
(append! a x): appends to array a in place, returns a
+ (delete! a i): deletes element i of array a. i must be in bounds. returns a
(# a): get length of array a
(, ...): pend. concatenates arrays, promotes non-arrays to arrays
(, [1 2 3] 4) -> [1 2 3 4]
(, [1 2 3] [4 5]) -> [1 2 3 4 5]
(, 10 20) -> [10 20] etc
(s, ...): spend. concatenates strings
+ (s,@ a): spendsplat. (s,@ [a b c]) <=> (s, a b c)
+ (ssub? needle haystack): is substring?
+ (ssplit delim text): splits text on delim, delim is removed from sections
+ (schars-ascii s): returns arr containing ascii chars (bytes) in s
+ (sin x) (cos x) (ceil x) (floor x) (abs x): should be obvious
# cmdline args
bth [-Dl] [-Dt] filenames...