Arc Forumnew | comments | leaders | submitlogin
1 point by akkartik 3176 days ago | link | parent

I'm on the move at the moment, but since you brought up defvar yesterday I wonder if that would be a simpler way to go..

Also, it's not clear why you're using the top-level eval. I think it might be unnecessary. Double unquoting is hard to get right so worth avoiding if at all possible. Edit 2 hours later: oh, I see the reason for the eval.



2 points by mpr 3175 days ago | link

I read the link you suggested in my previous post about defvar, and I see that it can be used to set dynamic behavior when a variable is referenced (??). Is this the correct interpretation, and what might be some uses of that?

-----

3 points by akkartik 3175 days ago | link

Yeah it lets you decide what to do when getting or setting a variable. The original link has an example at the bottom, but here's another one kinda related to what you seem to be trying to do:

  arc> (= h (obj a 1 b 2))
  #hash((a . 1) (b . 2))
  arc> (defvar a
               (fn args
                 (if args
                   ; write
                   (= h!a car.args)
                   ; read
                   h!a)))
  arc> a
  1
  arc> (= a 3)
  3
  arc> a
  3
  arc> h
  #hash((a . 3) (b . 2))

-----

2 points by mpr 3175 days ago | link

Oh I see now. That is pretty cool

-----