Arc Forumnew | comments | leaders | submitlogin
bug setting nested tables?
5 points by drcode 5852 days ago | 5 comments
There may be a good reason for this behavior- What do you guys think?

  arc> (= foo (table))                      
  #hash()
  arc> (= foo!bar (table))
  #hash()
  arc> (= (foo!bar 'baz) 6)
  Error: "Can't invert  ((foo (quote bar)) (quote baz))"
  arc> (= qux foo!bar)
  #hash()
  arc> (= qux!baz 6)   
  6


2 points by almkglor 5852 days ago | link

For some reason, '= assumes that if the first element in the assign-to list is not a symbol, the list is "inverted" and '= reverses (!) their order:

  (= foo (table))
  (= ('bar foo) 42)  ; equivalent to (= foo!bar 42) !!!
It's a weird "feature", one of highly dubious use

-----

1 point by drcode 5852 days ago | link

I can't duplicate your sample- Those two statements don't seem to be equivalent:

  arc> (= foo (table))
  #hash()
  arc> (= ('bar foo) 42)
  Error: "Can't set reference  bar #hash() 42"
  arc> (= foo!bar 42)
  42

-----

3 points by kens 5851 days ago | link

For the different table behavior, probably almkglor is using Anarki and drcode is using standard Arc. But your example looks like a bug to me:

  arc> (= ((foo (quote bar)) (quote baz)) 42)
  42
  arc> (= (foo!bar 'baz) 42)
  Error: "Can't invert  ((foo (quote bar)) (quote baz))"
Unless I've messed up the parentheses, those should be equivalent. I think the problem is that expand-metafn-call is being called by setforms when it shouldn't be. (Or alternatively, it shouldn't give up and die.) The example works if you first turn expand-metafn-call into a nop:

   (def expand-metafn-call (a b) (cons a b))

-----

1 point by almkglor 5851 days ago | link

No, it was a mistake by me: Anarki works similarly to ArcN in this case. Sorry for muddying the waters. ^^

The problem appears to be that the current '= was meant for use with the older ssyntax, which supports only : for composition. I'll take a better look maybe later, I'm just home from work, cooling off (very hot in the philippines right now)

The "invert" thing is really confusing, I didn't add docstrings to all the '= related stuff because of that. Me, I say refactor '=. LOL

Edit: Fixed on the git.

  (def metafn (x)
    (set x (ssyntax x))
    (and (acons x) (in (car x) 'compose 'complement)))

-----

2 points by drcode 5851 days ago | link

I wasn't expecting anyone to fix it- I was just wondering whether it was a bug :-)

Thanks almkglor and kens!

-----