io.tsp (1084B)
1 (docstr-add! 2 '((write 3 "(write file . vals)" 4 "Writes to file given as string all values" 5 " File can also be symbol 'stdout or 'stderr") 6 (read 7 "(read . file)" 8 "Return string read from optional file, if not given read from stdin") 9 (parse 10 "(parse string)" 11 "Parse Tisp object from given string"))) 12 13 (def (run file) (eval (parse (read file)))) 14 (def (print . str) (apply write (list* 'stdout Nil str))) 15 (def (newline . file) ; TODO space and tab functions, accept number of instead 16 (if (or (nil? file) (nil? (cdr file))) 17 (write (car (or file '(stdout))) file "\n") 18 (error 'newline "only zero or one file can be given"))) 19 20 (def (display . str) 21 (map @(cond 22 ((string? it) (print "\"" it "\"")) 23 ((true? it) (print it)) ; don't quote True since it's self evaluating 24 ((symbol? it) (print "'" it)) 25 ((pair? it) (print "'" it)) 26 (else (print it))) 27 str) 28 Void) 29 (def (displayln . str) (apply display str) (newline)) 30 (def (println . str) (apply print str) (newline))