[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Cyclic lists and the Interpreter
From: |
Graham Fawcett |
Subject: |
Re: [Chicken-users] Cyclic lists and the Interpreter |
Date: |
Tue, 8 Apr 2008 11:57:57 -0400 |
On Mon, Apr 7, 2008 at 3:24 PM, Alex Rozenshteyn <address@hidden> wrote:
> (define a (list 'a))
> (set-cdr! a a)
> ;a is now a cyclic "list"
> (pair? a) ; -> #t
> (list? a) ; -> #f
> (length a)
>
> and now the interpreter gets stuck.
> control-c does not break (this is because I have the readline egg
> installed).
>
>
> I have two questions:
> 1) How do I get C-c to break?
> 2) Is the interpreter supposed to freeze if length is passed a cyclic list?
Yes, it's correct. See length and length+ in SRFI-1:
http://srfi.schemers.org/srfi-1/srfi-1.html#Miscellaneous
length+ will give you sane behaviour with cyclic lists.
> Other scheme implementations generate an error.
Yes, but that's implementation-specifc. (length) may "diverge or
signal an error" according to SRFI-1, and in Chicken's case it
diverges.
Graham