diff options
author | ubq323 <ubq323@ubq323.website> | 2024-07-13 12:41:36 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-07-13 12:41:36 +0100 |
commit | 726f9e814b29b4496d07c92323dc55dcf93c2a87 (patch) | |
tree | ff9fb98f94be3bc371b9c5de9fe1eec852ea55cb /doc.txt | |
parent | cb738e17c9751fadc990fda75fa023a8fe9fd671 (diff) |
update docs
Diffstat (limited to 'doc.txt')
-rw-r--r-- | doc.txt | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -7,36 +7,41 @@ arr: [ 10 20 30 ] array of badthing values array indexing is the same as function calling: (a 1) -> 20 string: "hii". - strings are interned: two strings are the same object in memory - iff their contents are the same + strings are interned: two strings with the same contents + are always the same object in memory # variables - let, def, fn introduce new locals + let, def, fn, defn introduce new locals locals are lexically scoped, and scopes can be nested closures and upvalues will work soon if a local is not found with a given name, the name is instead - resolved as a global. this behaviour might change because it's not very good. + resolved as a global. + this behaviour might change because it's not very good. + def and defn are only allowed at top level # builtin forms arithmetic: + - * / % (+ 1 2) equality: (= (+ 2 2) 4) comparison: (< 0 1). ">" omitted deliberately. let: unremarkable. (let (a 100 b 200) (+ a b)) - set: mutates values. (set x 10) - arrays: (set (a 1) 20) sets index 1 of a + 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) 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. only allowed at top level of a 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 (arr): create new empty array - (append a x): appends to array a + (append a x): appends to array a, returns a (len a): get length of array a # cmdline args |