Login
7 branches 0 tags
Ben (RPI 4) Fixed NetBSD 6921529 4 years ago 132 Commits
nujel / bin / lib / repl.nuj
[def repl/exception-handler [λ [error]
	[display [cat [ansi-red [car error]] "\r\n" [cdr error] "\r\n"]]
]]

[def repl/history #nil]


[def repl/prompt [λ []
	   "> "
]]

[def repl/wasm [λ [line]
	[try repl/exception-handler
	     [def expr [read line]]
		 [eval* [cons do expr]]
	]
]]

[def repl/readline [λ []
	[def line [readline [repl/prompt]]]
	[when [nil? line]
	      [display " Bye!\r\n"]
	      [exit 0]
	]
	[readline/history/add line]
	[def read [read line]]
	[def result [eval* [cons do read]]]
	[set! repl/history [cons line repl/history]]
	[display [cat [if [nil? result]
			  ""
			  [str/write result]]
		      "\r\n"
		 ]]
]]

[def repl [λ []
	[readline/history/load [readline/history/path]]
	[while #t
	       [try repl/exception-handler
	            [repl/readline]
	       ]
	       [readline/history/save [readline/history/path]]
	]
]]