Arc Forumnew | comments | leaders | submitlogin
2 points by aw 3714 days ago | link | parent

Note that you're not converting Scheme '() terminated lists to Arc nil terminated lists. This often isn't noticeable since Arc largely treats '() as a synonym for nil, but it does have an effect in some cases, such as keys in a table:

  arc> (= a (table))
  #hash()
  arc> (= k (fromstring "[1,2]" (json-read (stdin))))
  (1 2)
  arc> (= (a k) 'foo)
  foo
  arc> k
  (1 2)
  arc> (a k)
  foo
  arc> (a '(1 2))
  nil
Here k is (1 2 . ()) while '(1 2) is (1 2 . nil), so they're actually different keys in the table.

Whether you feel the need to fix this depends on your application... I ran into a similar issue myself in another project when I was using lists as keys in a table, but it might not affect you for what you're doing.



1 point by akkartik 3714 days ago | link

Yeah, that's a bug. Sigh. The whole nil vs () makes it non-trivial for arc to benefit from mzscheme's extensive libraries.

Hmm, perhaps there's a way to fix it: get the reader to recognize #t, #f, #<void>, and get (is nil ()) to return t. Is that reasonable?

-----

1 point by aw 3714 days ago | link

(is nil ()) does return t:

  arc> (is nil (ac-scheme '()))
  t
or in Anarki,

  arc> (is nil ($ '()))
  t
Arc does treat Scheme's '() as a synonym for nil quite a bit, so there's only a few odd corner cases where the use of '() becomes visible.

Not sure what you mean by getting the reader to recognize #t, #f, #<void>?

For fun I once hacked ac.scm so that Arc's nil was represented internally by Scheme's '(). Inside of Arc everything was still the same: nil was still a symbol and so on. It even seemed to work, though I didn't test it very much.

-----

1 point by akkartik 3714 days ago | link

Most interesting, thanks for these ideas and tips.

The original scheme version converted true to #t, false to #f, and null to (void) which turns into the #<void> literal. These break in arc because #f isn't nil, and #<void> can't even be read by the reader. So I think I have to take a comprehensive look at mzscheme's syntax at some point and make sure that anything scheme code can emit can be read and understood by the arc compiler.

-----

1 point by aw 3714 days ago | link

Oh, do you mean that if, for example, Arc treated #t as a synonym for t, then we wouldn't have to do that conversion ourselves manually?

-----

1 point by akkartik 3714 days ago | link

Yes.

-----

1 point by aw 3714 days ago | link

hmm, ac.scm is a module, so you should be able to import it into json.ss:

  (require "../ac.scm")
that would give you access to ac-niltree, so at the point where json.ss is creating a list you could convert it to a nil-terminated list.

Another option is to recursively copy the return value of json-read.

-----