| fractal was asking about REPL variables ( http://arclanguage.org/item?id=776 ). Here's a basic implementation.
In ac.scm, change tl2 thus: (define (tl2)
(display "arc> ")
(on-err (lambda (c)
(set! last-condition* c)
(display "Error: ")
(write (exn-message c))
(newline)
(tl2))
(lambda ()
(let ((expr (read)))
(if (eqv? expr ':a)
'done
(let ((val (arc-eval expr)))
(arc-eval `(input-history-update ',expr)) ; added
(arc-eval `(output-history-update ,val)) ; lines here
(write (ac-denil val))
(namespace-set-variable-value! '_that val)
(namespace-set-variable-value! '_thatexpr expr)
(newline)
(tl2)))))))
And then put these in arc.arc : ; I couldn't find a pre-existing total macro-expander
(def expand (expr)
(if (acons expr)
(macex (cons (car expr)
(map expand (cdr expr))))
expr))
(mac % () nil)
(mac %% () nil)
(mac %%% () nil)
(def input-history-update (expr)
(let expandedexpr (expand expr)
(= %%% %%
%% %)
(mac % () expandedexpr)))
(= ^ nil
^^ nil
^^^ nil)
(def output-history-update (val)
(= ^^^ ^^
^^ ^
^ val))
Then ^, ^^, ^^^ work like CL * , * * , * * * .
And (%), (%%), (%%%) re-evaluate the last, second-last, third-last thing you typed in. (Obviously these are for if you haven't got readline.) |