Arc Forumnew | comments | leaders | submitlogin
What does 'nil buy us?
2 points by akkartik 2724 days ago | 9 comments
I can't see any reason to not simply terminate arc lists with '(). Arc already treats '() as a false value:

  (define (ar-false? x)
    (or (eq? x 'nil) (eq? x '()) (eq? x #f)))
Does arc use nil simply to be more like common lisp?

Related: http://www.paulgraham.com/arcll1.html, http://arclanguage.org/item?id=2995, and tangentially http://arclanguage.org/item?id=11505



2 points by rntz 2724 days ago | link

It doesn't. It's just an arbitrary choice between using 'nil and '(). It turns out that using '() is easier when writing arc on top of mzscheme, but that pg decided to go with 'nil - why, who knows? Probably a holdover from the CL implementation, or it matches better with his way of thinking about these things.

In particular, it is completely possible to use () underneath as the list-terminator/false value and still have 'nil be arc-recognized "syntax" for (). See aw's nil-to-() hack, for example.

-----

1 point by akkartik 2721 days ago | link

I'm having trouble finding this nil-to-() hack. Link please?

-----

2 points by fallintothis 2721 days ago | link

http://hacks.catdancer.ws/nil-impl-by-null.html

-----

1 point by akkartik 2721 days ago | link

I basically went through the same process 2 days ago! And yes it works.

-----

1 point by fallintothis 2724 days ago | link

Per the comment above ar-false?

  ; definition of falseness for Arc if.
  ; must include '() since sometimes Arc functions see
  ; Scheme lists (e.g. . body of a macro).
So '() is ar-false? to interact nicely with Scheme. Notice #f is ar-false?, too.

I don't think there's much to it: pg just seems to prefer to spell the empty list nil instead of (). The only place I can think of where these different spellings are useful is in argument lists. That is, I prefer

  (def f () something)
to

  (def f nil something)
Otherwise, I'm used to nil, though I'd probably get used to () just as well.

-----

1 point by zck 2724 days ago | link

It's nice to have a form for that value that you can to say to someone without having to explain. Saying "the empty list" sounds awkward, and it would be consistent with pg's design goals for Arc to make it simple to talk about that value.

-----

2 points by akkartik 2724 days ago | link

That's a fair reason, though you can just teach people to read '() as 'nil' (say in the tutorial).

I'm not second-guessing the decision; I just want to confirm that I'm not missing a more substantial reason. From an implementor's perspective, it's good to know that nil-termination isn't a reason to require a 'compiler pass' for arc. Even if you include 'nil to be eq to '(), ac-denil and ac-niltree are redundant. It seems a strange decision to perform the translation when much of arc is so barebones and no-nonsense.

-----

1 point by pg 2723 days ago | link

I like using the symbol nil for the empty list.

-----

2 points by akkartik 2723 days ago | link

Any code that interacts with scheme code ends up having to jump through hoops like the JSON parser did: http://arclanguage.org/item?id=10799

I suppose the answer is to just make (is nil '()) true.

-----