Arc Forumnew | comments | leaders | submitlogin
Why is 'copylist necessary?
1 point by rntz 5410 days ago | 6 comments
In arc.arc from arc2.tar:

    (def list args args)
In arc.arc from arc3.tar:

    (def copylist (xs)
      (if (no xs) 
          nil 
          (cons (car xs) (copylist (cdr xs)))))

    (def list args (copylist args))
I'm not sure why 'copylist is necessary, considering the following, evaluated in vanilla arc3:

    arc> (def mylist args args)
    #<procedure: mylist>
    arc> (= l '(1 2 3))
    (1 2 3)
    arc> (is l l)
    t
    arc> (= l2 (apply mylist l))
    (1 2 3)
    arc> (is l l2)
    nil
    arc> (= car.l2 'foo)
    foo
    arc> l2
    (foo 2 3)
    arc> l
    (1 2 3)


2 points by CatDancer 5410 days ago | link

It's because (fn args ...) currently compiles to (lambda args ...), so args becomes a Scheme list instead of an Arc list.

It's hard to see the difference because the Arc runtime mostly treats '() as a synonym for 'nil. But keys to tables aren't converted, so it is possible to get an observable result out of the bug this way:

  arc> (let a (table)
         (= (a ((fn args args) 1 2)) 'hi)
         (a '(1 2)))

  nil

-----

1 point by rntz 5410 days ago | link

Ah, I just realized why.

    arc> (def terminator (l) (if acons.l (terminator cdr.l) l))
    #<procedure: terminator>
    arc> (terminator (list 1 2 3 4 5 6))
    nil
    arc> (terminator (mylist 1 2 3 4 5 6))
    ()

-----

1 point by CatDancer 5410 days ago | link

Ah yes, that's a simpler way to get an observable difference ^_^

-----

1 point by conanite 5410 days ago | link

What's the difference between nil and () ?

They both appear to have the same behaviour for car and cdr (return nil), and for scar and scdr (not allowed), and on top of that

  arc> (is () nil)
  t
Couldn't we drop one of these?

-----

1 point by CatDancer 5410 days ago | link

What's the difference between nil and ()

Arc lists are terminated by 'nil, Scheme lists by '(). Because Scheme lists sometimes appear in Arc, the Arc runtime (such as 'is) treats '() like 'nil.

Couldn't we drop one of these?

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

-----

1 point by conanite 5410 days ago | link

sounds like an onion to me :)

-----