Intercept and modify user input in Common Lisp

149 views Asked by At

I defined an evaluator in common lisp that can simply be called like:

(repl)

From then on, the repl can interpret function calls like (.cos arg) that are otherwise unknown to lisp.

Ofcourse, to use it, one has to call (repl) first, or lisp doesn't know what .cos is.

I would like to be able to simply call (.cos 90) though, and have it run in the repl. Is there anyway to use lisp's reflection to intercept all user input and call another function before it?

Thanks!

1

There are 1 answers

0
Sylwester On

The better way would be to make my-eval, then you can do

(defun my-cos (arg) 
  (my-eval (list '.cos arg))) 

repl would be something like

(defun my-repl ()  
  (my-eval '((lambda (ev) 
              (ev ev)) 
            (lambda (ev)
              (print (eval (read)))
              (ev ev))))) 

I assume you have print, eval and read defined in your evaluators null environment.