*scratch*

vijay's weblog

« Back to posts
  • Viewed
    times

Filed under

  • lisp
April 1, 2010

Circular lists in Common Lisp

  • Edit
  • Delete
  • Tags
  • Autopost

There are two ways to create a circular list in Common Lisp.  The first method is to use the sharp-equal notation. Here we assign a label to a cons cell, so that we can refer to it later:

> '#1='(1 2 3 . #1#)
(1 2 3 1 2 3 1 2 3 1 ...)

The other method is to nconc a list to itself:

> (setq a '(1 2 3))
(1 2 3)
> (nconc a a)
(1 2 3 1 2 3 1 2 3 1 ...)
Tweet
  • 0 responses
  • Like
  • Comment