diff options
author | ubq323 <ubq323@ubq323.website> | 2024-10-31 20:13:58 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-10-31 20:13:58 +0000 |
commit | 83056a82a6d55f7edf2d7216d30000a4a6482310 (patch) | |
tree | 2a0c58882ae54e1874189b40028477dd1916fef6 | |
parent | e7cc8217d5f2ba69b8baca97ea9b6bf6fd028c8a (diff) |
-rw-r--r-- | com.c | 16 | ||||
-rw-r--r-- | doc.txt | 28 |
2 files changed, 27 insertions, 17 deletions
@@ -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) @@ -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... |