Add history and ok/err functionality to REPL.

This commit is contained in:
Sage Vaillancourt 2021-12-15 14:40:49 -05:00 committed by Sage Vaillancourt
parent f3a69989fa
commit 8d22bf575c
1 changed files with 22 additions and 8 deletions

View File

@ -1,20 +1,34 @@
#!/usr/bin/pl #!/usr/bin/pl
(def _history ())
(def __history (fn (_h) (
(prnl (at 0 _h))
(if (> (len _h) 0) (
(__history (rest _h))
) ())
)))
(def history (fn () (__history _history)))
(def repl (fn () ( (def repl (fn () (
(prn "pebblisp::> ") (prn "pebblisp::> ")
(def input (inp)) (def input (inp))
(if (= input "q") () ( (if (= input "q") () (
(def _history (ap _history input))
;(switch input ( ;(switch input (
; ("clear" (fn () (sys "clear"))) ; ("clear" (sys "clear"))
;)) ;))
(if (= input "") () ( (if (= input "") () (
(if (= input "clear") (sys "clear") ( (if (= input "clear") (sys "clear") (
(def ret (eval input)) (def ret (eval input))
(if (iserr ret) (prn "X => ") (prn "Ok => ")) (if (iserr ret)
(prnl ret) (prn "X => ")
(prn ""))))) (prn "Ok => "))
(repl) (prnl ret)
)) (prnl ""))))
))) )
(repl))))))
(repl) (repl)