Lisp circular lists

We were given homework from lisp, where I need to use a "circular" list (I do not know why this is correct). By a "circular" list, I mean a list where the cdr last of them points to the very first of the same list.

 (Value1 . PointerValue2) (Value2 . PointerValue3) (Value3 . PointerValue1) 

We have been taught to create such lists with:

 (defun cykl (l) (setf (cdr (last l)) l) ) 

The lisp software (Lispbox) that I use does not support such lists. I also tried clisp on Debian, but it crashed after creating such a list.

What lisp implementations do you know that this supports (freeware, os independent)?

-3
list lisp circular-list common-lisp
Mar 20 '13 at 23:13
source share
1 answer

All lisp implementations, including clisp , support circular lists .

When you say β€œfailure”, you probably mean a mistake (or a memory error) that you will always remember the β€œread-eval-PRINT?” Loop of the circular structure when *print-circle* is nil By setting it to t , run lisp to use the notation # n # :

 [1]> (defparameter l (list 1 2 3)) L [2]> l (1 2 3) [3]> (setq *print-circle* t) T [4]> (setf (cdr (last l)) l) #1=(1 2 3 . #1#) 

See also the LIST-LENGTH function .

+7
Mar 21 '13 at 0:03
source share



All Articles