Arc Forumnew | comments | leaders | submitlogin
Help wanted: eval and lexical variables
4 points by fallintothis 3662 days ago | 2 comments
Arc's eval works by compiling an expression sans lexical environment, then calling mzscheme's eval on the result.

  (xdef eval (lambda (e)
                (eval (ac (ac-denil e) '()))))
So, it obviously can't evaluate lexical variables:

  arc> (= x 5)
  5
  arc> (eval 'x)
  5
  arc> (let x 10 (eval 'x))
  5
  arc> (let y 10 (eval 'y))
  Error: "reference to undefined identifier: _y"
Perhaps this is intentional. It's the way Common Lisp's eval works, though at least you can reify the environment

  $ clisp
  [1]> (setf x 5)
  5
  [2]> (eval 'x)
  5
  [3]> (let ((x 10)) (eval 'x))
  5
  [4]> (let ((x 10)) (the-environment))
  #(#(X 10 NIL) NIL NIL NIL ((DECLARATION XLIB::CLX-VALUES VALUES OPTIMIZE DECLARATION)))
and use this with evalhook, which takes the environment as an argument

  [5]> (let ((x 10)) (evalhook 'x nil nil (the-environment)))
  10
It's even the way mzscheme's eval works (to the best of my knowledge), so we can't just do something like

  (xdef eval (lambda (expr env)
                (eval (ac (ac-denil expr) (ac-denil env)))))
since Scheme's eval still won't know what to do with the lexical variables compiled out by ac.

I've tried hacking various solutions into ac.scm, but my Scheme-fu is pathetic, and I haven't gotten anything working 100%. I suspect there's some relevant mzscheme feature or other, but I'm pretty tired of wrestling with this.

Can anyone help?



2 points by CatDancer 3662 days ago | link

Well, MzScheme's eval lets you pass in a namespace. Now a namespace is not a lexical environment. It's simply a collection of names and values. Arc uses one MzScheme namespace for its top-level environment. It would be pretty easy for you to create your own namespace and eval Arc expressions in that namespace, so that they'd see a different "top-level" environment than the main program does. However that's not going to give you access to lexical variables.

-----

2 points by rntz 3661 days ago | link

This has been discussed before. As far as I know, there is no solution to this short of making making arc an interpreter rather than an Arc-to-Scheme compiler, since mzscheme does not provide this underlying functionality.

-----