Arc Forumnew | comments | leaders | submitlogin
2 points by mpr 3175 days ago | link | parent

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

-----