From 8d22bf575cca03f6f9cd32b102f3377d93be9158 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Wed, 15 Dec 2021 14:40:49 -0500 Subject: [PATCH] Add history and ok/err functionality to REPL. --- src/examples/repl.pbl | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/examples/repl.pbl b/src/examples/repl.pbl index 5b61ef4..a2be94b 100755 --- a/src/examples/repl.pbl +++ b/src/examples/repl.pbl @@ -1,20 +1,34 @@ #!/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 () ( (prn "pebblisp::> ") + (def input (inp)) + (if (= input "q") () ( + (def _history (ap _history input)) ;(switch input ( - ; ("clear" (fn () (sys "clear"))) + ; ("clear" (sys "clear")) ;)) (if (= input "") () ( (if (= input "clear") (sys "clear") ( - (def ret (eval input)) - (if (iserr ret) (prn "X => ") (prn "Ok => ")) - (prnl ret) - (prn ""))))) - (repl) - )) -))) + (def ret (eval input)) + (if (iserr ret) + (prn "X => ") + (prn "Ok => ")) + (prnl ret) + (prnl "")))) + ) + (repl)))))) (repl)