Arc Forumnew | comments | leaders | submitlogin
4 points by conanite 5797 days ago | link | parent

I don't get the difference between foo[bar] and foo.bar ... why not use only one? Doesn't the context determine whether you're setting or retrieving a value?

  (= foo[bar] "value")
vs

  (prn foo[bar])
At least, arc makes no distinction:

  (= foo (table))
  (= foo!bar 123)
  (prn foo!bar)
does what you would expect. But it's true that arc syntax for accessing nested tables

  foo!bar
is awkward, in particular because it can't be chained. There's no syntax for

  ((foo 'bar) 'toto)
because

  foo!bar!toto
expands to

  (foo 'bar 'toto)
and that throws an error. I may well be missing some tricks, but deeply nested structures appear to be difficult to use in Arc, and it would be great to fix this. It would be great to write something like

  foo[bar][toto]
And arc's exclamation marks suck as syntax: they make the code look way too urgent and excited.


6 points by skenney26 5797 days ago | link

I agree that the exclamation marks aren't that useful.

Here's a macro that might be useful for digging down into a nested table:

  (mac dig args
   `(,@(reduce list args)))

  arc> (= x (table))
  #hash()
  arc> (= (x 'y) (table))
  #hash()
  arc> (= ((x 'y) 'z) 0)
  0
  arc> x
  #hash((y . #hash((z . 0))))
  arc> (dig x 'y 'z)
  0
  arc> (= (dig x 'y 'z) 1)
  1
  arc> x
  #hash((y . #hash((z . 1))))

-----