doc.tsp (2667B)
1 (def docstr-reg 2 '((car 3 "(car lst)" 4 "First element of list") 5 (cdr 6 "(cdr lst)" 7 "Rest of list after first element") 8 (cons 9 "(cons a d)" 10 "Create new pair with a car of a and cdr of d") 11 (quote 12 "(quote expr)" 13 "Return expression unevaluated" 14 " Can be shortened with the ' prefix" 15 " Also see quote, unquote, and unquote-splice") 16 (Void 17 "Void" 18 "Return nothing" 19 "Used to insert a void type in a list or force a function not to return anything") 20 (eval 21 "(eval expr)" 22 "Evaluate expression, can be dangerous to use in practice") 23 (= 24 "(= . vals)" 25 "Return boolean depending on if multiple values are all equal") 26 (cond 27 "(cond . (expr . body))" 28 "Conditional statement") 29 (typeof 30 "(typeof val)" 31 "Get string stating the argument's type") 32 (get 33 "(get val prop)" 34 "Get the property of the given value depending on its type") 35 (Func 36 "(Func args . body)" 37 "(Func body)" 38 "Create anonymous function" 39 " If only body is given, create function with one argument labeled 'it'") 40 (Macro 41 "(Macro args . body)" 42 "Create anonymous macro, arguments are not evaluated before given to body" 43 " If only body is given, create macro with one argument labeled 'it'") 44 (def 45 "(def var . val)" 46 "Create new variable with value" 47 " If value is not given, make variable a self-evaluating symbol" 48 "" 49 "(def (func . args) . body)" 50 "Create new function with arguments list and body list") 51 (set! 52 "(set! var val)" 53 "change the variable var to val") 54 (load 55 "(load lib)" 56 "Loads the library given as a string") 57 (error 58 "(error func msg)" 59 "Throw error, print message with function name given as symbol") 60 (version 61 "(version)" 62 "Tisp's version number as a string"))) 63 64 (def (docstr-add! . docstrs) 65 "Add given docstrs to the global doc string registry" 66 (set! docstr-reg (apply @(append docstr-reg it) docstrs)) 67 Void) 68 69 (def (doc proc) 70 "Get documentation of procedure" 71 (unless (procedure? proc) 72 (error 'doc "documentation only exists for procedures")) 73 (def (lookup proc) 74 (let ((docstrs (assoc (get proc 'name) docstr-reg))) 75 (if docstrs 76 (map println (cdr docstrs)) 77 (error 'doc (get proc 'name) ": no documentation found") ))) 78 (if (or (function? proc) (macro? proc)) 79 (let ((docstr (car (get proc 'body)))) 80 (println (cons (get proc 'name) (get proc 'args))) 81 (if (string? docstr) 82 (println docstr) 83 (lookup proc))) 84 (lookup proc)) 85 Void)