Arc Forumnew | comments | leaders | submitlogin
Does Arc allow cyclic lists?
5 points by kens1 5871 days ago | 4 comments
What's the official status of cyclic lists in Arc? Are they allowed? Disallowed? Subject to certain conditions? Whatever works is allowed?

Currently, Arc lets you create them, but if you try to display one, you end up in swap death.

  arc> (= x '(a b))
  (a b)
  arc> (do (scdr (cdr x) x) t)
  t
  arc> (x 1001)
  b
  arc> x
  ...hangs until ^c...
  > _x
  #0=(a b . #0#)
Note that mzscheme is happy to display the circular list. The (do ... t) wrapper merely avoids displaying the scar result.


7 points by pg 5871 days ago | link

You can make them (and all kinds of other circular structures) but there's currently no way of printing them out. Fixing that is not a top priority. There are plenty of things you don't want to print in the repl, like million-item lists. So in the repl the way to deal with this is by using e.g. (do1 t ...).

I admit it's a problem if you explicitly want to print a circular list, e.g. to store it in a file. But in my experience that is rare.

-----

1 point by absz 5871 days ago | link

I know that mzscheme has a method for printing out circular lists:

  > (define x '(1))
  > (set-cdr! x x)
  > x
  #0=(1 . #0#)
I'm sure there's a good reason that Arc can't just leverage it, but what is said reason?

-----

3 points by pg 5870 days ago | link

Actually it probably just got lost somewhere in converting from nil-terminated lists.

-----

2 points by cchooper 5871 days ago | link

I doubt pg would want to ban them, and I also doubt he's given much thought to printing them, so I guess that's your answer.

-----