Home > Archive > Scheme > January 2008 > improper list
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi all,
why is this an improper list?
'((3 . 4) (5 6))
car is an element and can be just anything and cdr is a list, what's
improper with that?
Is it correct to say that improper lists are lists that does not end
with '()?
Thanks,
Luca.
| |
| Kjetil S. Matheussen 2008-01-29, 9:00 am |
| On Tue, 29 Jan 2008, Luca wrote:
> Hi all,
> why is this an improper list?
> '((3 . 4) (5 6))
> car is an element and can be just anything and cdr is a list, what's
> improper with that?
Nothing, its not an improper list. :-)
Are you sure thats the right example?
> Is it correct to say that improper lists are lists that does not end
> with '()?
>
Yes. Proper lists end with '(), like your example.
| |
|
| Oh thanks, I'm going to sleep nicely tonight!
Yes, pretty sure it's the right example, that comes from an
authoritative source :)
On 29 Gen, 12:23, "Kjetil S. Matheussen" <k.s.matheus...@notam02.no>
wrote:
> On Tue, 29 Jan 2008, Luca wrote:
>
> Nothing, its not an improper list. :-)
> Are you sure thats the right example?
>
>
> Yes. Proper lists end with '(), like your example.
| |
| Pascal J. Bourguignon 2008-01-29, 9:00 am |
| Luca <lukasjob@gmail.com> writes:
> On 29 Gen, 12:23, "Kjetil S. Matheussen" <k.s.matheus...@notam02.no>
> wrote:
>
> Oh thanks, I'm going to sleep nicely tonight!
> Yes, pretty sure it's the right example, that comes from an
> authoritative source :)
What is a proper list? It's a list that is not circular, and either
it's () or a pair whose cdr is a proper-list.
Welcome to MzScheme version 360, Copyright (c) 2004-2006 PLT Scheme Inc.
> (define atom? (lambda (object) (not (pair? object))))
(define proper-list-p
(lambda (object)
(letrec ((proper (lambda (current slow)
(cond ((null? current) #t)
((atom? current) #f)
((null? (cdr current)) #t)
((atom? (cdr current)) #f)
((eq? current slow) #f)
(else (proper (cddr current) (cdr slow)))))))
(and (list? object) (proper object (cons '() object))))))>
> (proper-list-p '(a b c))
#t
> (proper-list-p '(a b c . d))
#f
> (proper-list-p '#1=(a b c . #1#))
#f
So, is '((3 . 4) (5 6)) a proper list?
> (proper-list-p '((3 . 4) (5 6)))
#t
Yay! It is!
And indeed:
> (let ((object '((3 . 4) (5 6))))
(list (pair? object)
(pair? (cdr object))
(null? (cddr object))))
(#t #t #t)
--
__Pascal Bourguignon__
| |
| Joel J. Adamson 2008-01-29, 7:41 pm |
| pjb@informatimago.com (Pascal J. Bourguignon) writes:
> Luca <lukasjob@gmail.com> writes:
>
[...]
[color=darkred]
> So, is '((3 . 4) (5 6)) a proper list?
>
> #t
>
> Yay! It is!
Luca, Perhaps you took the car of the list:
________________________________________
__________
Gambit v4.1.2
> (list? '((3 . 4) (5 6)))
#t
> (define list '((3 . 4) (5 6)))
> list
((3 . 4) (5 6))
> (list? (car list))
#f
> (list? (cdr list))
#t
> (list? (cadr list))
#t
> (list? (cdar list))
#f
________________________________________
__________
Joel
--
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA 02114
(617) 643-1432
(303) 880-3109
|
|
|
|
|