summaryrefslogtreecommitdiff
path: root/doc.txt
blob: f4b243918ed3d163a91655022edbc99409456ecb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# types
	nil: nil. it's always nil
	bool: true, false. 
	num: 1234. -123.56. 64bit floating point number
	cfunc: pointer to native c function
	func: badthing function
	arr: [ 10 20 30 ] array of badthing values
		array indexing is the same as function calling: (a 1) -> 20
	string: 'word  "string with spaces"
		strings are interned: two strings with the same contents
			are always the same object in memory

# variables
	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.
	def and defn are only allowed at top level
	
# builtin forms
	arithmetic: + - * / %     (+ 1 2)
	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
	when: (when cond body...) like if with multiple body exprs. returns nil
	while: (while cond body...)  returns nil
	
# 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
	(sbytes s): returns arr containing bytes in s
	(sin x) (cos x) (ceil x) (floor x) (abs x): should be obvious

# cmdline args
	bth [-Dl] [-Dt] filenames...
		-Dl: print bytecode listing before execution
		-Dt: trace each executed bytecode instruction
		-Ds: dump read s-expressions
		filename "-" can be provided to mean stdin.