tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 4c70395b748f76fa9a86906a6485c7dc6d54a753
parent 1f506dafba08b63a975fbf907b68df2f6bb81541
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Thu, 25 Mar 2021 00:26:40 -0700

Add primitive procedure documentation

Rename repl.tsp to os.tsp

Diffstat:
tib/doc.tsp | 5+++++
tib/io.tsp | 12++++++++++++
tib/os.tsp | 32++++++++++++++++++++++++++++++++
tib/repl.tsp | 15---------------
4 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/tib/doc.tsp b/tib/doc.tsp @@ -61,6 +61,11 @@ "(version)" "Tisp's version number as a string"))) +(def (docstr-add! . docstrs) + "Add given docstrs to the global doc string registry" + (set! docstr-reg (apply @(append docstr-reg it) docstrs)) + (Void)) + (def (doc proc) "Get documentation of procedure" (unless (procedure? proc) diff --git a/tib/io.tsp b/tib/io.tsp @@ -1,3 +1,15 @@ +(docstr-add! + '((write + "(write file . vals)" + "Writes to file given as string all values" + " File can also be symbol 'stdout or 'stderr") + (read + "(read . file)" + "Return string read from optional file, if not given read from stdin") + (parse + "(parse string)" + "Parse Tisp object from given string"))) + (def (run file) (eval (parse (read file)))) (def (print . str) (apply write (list* 'stdout Nil str))) (def (newline . file) ; TODO space and tab functions, accept number of instead diff --git a/tib/os.tsp b/tib/os.tsp @@ -0,0 +1,32 @@ +(docstr-add! + '((cd! + "(cd! dir)" + "Change directory") + (pwd + "(pwd)" + "String of current working directory") + (now + "(now)" + "Number of milliseconds since 1970 (unix time stamp)") + (time + "(time expr)" + "Time taken to run given expression"))) + +(def (repl) + "Read, evaluate, print, loop + To exit enter (quit) or CTRL-D" + (print "> ") + (let ((expr (parse (read)))) + (unless (and (pair? expr) (= (car expr) 'quit)) + ; TODO push! ans to stack of outputs + (let ((ans (eval expr))) + (unless (void? ans) + (displayln ans)) + (repl))))) + +(def (repl-simple) + "Simple REPL interface, only requires io.c tib, no tisp code + See repl for more advanced REPL" + (write 'stdout Nil "> ") + (write 'stdout Nil (eval (parse (read))) "\n") + (repl-simple)) diff --git a/tib/repl.tsp b/tib/repl.tsp @@ -1,15 +0,0 @@ -(def (repl) - (print "> ") - (let ((expr (parse (read)))) - (unless (and (pair? expr) (= (car expr) 'quit)) - ; TODO push! ans to stack of outputs - (let ((ans (eval expr))) - (unless (void? ans) - (displayln ans)) - (repl))))) - -;; simple repl, only requires io.c tib -(def (repl-simple) - (write 'stdout Nil "> ") - (write 'stdout Nil (eval (parse (read))) "\n") - (repl-simple))