;; -*- lexical-binding: t; -*- (require 'cl-lib) (require 'mal/types) (require 'mal/reader) (require 'mal/printer) (defun READ (input) (read-str input)) (defun EVAL (input) input) (defun PRINT (input) (pr-str input t)) (defun rep (input) (PRINT (EVAL (READ input)))) (defun readln (prompt) ;; C-d throws an error (ignore-errors (read-from-minibuffer prompt))) (defun println (format-string &rest args) (princ (if args (apply 'format format-string args) format-string)) (terpri)) (defmacro with-error-handling (&rest body) `(condition-case err (progn ,@body) (end-of-token-stream ;; empty input, carry on ) (unterminated-sequence (princ (format "Expected '%c', got EOF\n" (cl-case (cadr err) (string ?\") (list ?\)) (vector ?\]) (map ?}))))) (error ; catch-all (println (error-message-string err))))) (defun main () (let (input) (while (setq input (readln "user> ")) (with-error-handling (println (rep input)))) ;; print final newline (terpri))) (main)