Arc Forumnew | comments | leaders | submitlogin
2 points by shader 5648 days ago | link | parent

Both Adlai's and rntz's version do what I was trying to do.

However, I was looking for a way to assign a value to the variable referenced by the one I was passed. i.e.

  (= v 'b)
  (= (val v) 6) ; unknown function/macro val which returns contents of v so that '= can assign 6 to 'b.
This would allow the expression above to be:

  (each v '(a b c) (= (val v) (readb))) ;assigns three bytes from standard in to 'a, 'b, and 'c respectively.
Whether this is done by overloading 'unquote to work like that outside of a quasiquote, or making something called 'val, I don't know. Maybe it could be done by making val or unquote a setform? That would solve this problem, but I think it might be more useful if it worked in more places than just assignment.


2 points by CatDancer 5648 days ago | link

If b is a global variable, it's easy.

If b is a lexical variable, eval won't help, since it isn't run in the lexical scope in which it's called. An Arc lexical variable will get compiled to an MzScheme lexical variable, and I don't know of a way to refer to an MzScheme lexical variable by name determined at run time. If there isn't, I suspect your only hope might be to modify the Arc compiler to generate code like

  (case v
    ((a) (set! a n))
    ((b) (set! b n))
    ((c) (set! c n))
    ((d) (set! d n))
    ...
for all the lexical variables available at that point.

-----