[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Question regarding "length"
From: |
Kon Lovett |
Subject: |
Re: [Chicken-users] Question regarding "length" |
Date: |
Mon, 29 May 2006 14:47:18 -0700 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On May 29, 2006, at 2:38 PM, Alejandro Forero Cuervo wrote:
What is the list length of (1 . 2) anyway? Only 1 makes sense.
Hmm, I think throwing an error, ―just like (length 'foo) does―, would
make more sense than returning 1 for (length '(1 . 2)).
Yes, if length were re-defined to accept improper & circular lists.
But, since 1) length is less than 1% of core procedure calls in my
corpus of scheme code (~5000 files), 2) generally used after
determination of list kind, 3) procedure contracts generally state
with which kind of list they will work, and 4) scheme procedures are
not required to be bullet-proof - caveat emptor, I don't feel compelled.
SRFI-1 states for an implementation "It is an error to pass a value
to length which is not a proper list (finite and nil-terminated)"
and "In particular, this means an implementation may diverge or
signal an error when length is applied to a circular list." It
doesn't say "must signal an error" for an improper list nor "must
signal an error for a circular list." Chicken meets these conditions.
If coding to the "standard" one must take the above into account
anyway. Having chicken 'length' barf won't change that.
Same goes for a circular list: throwing an error would make more sense
than failing to return, the small overhead required to detect circular
lists considered.
Alejo.
http://azul.freaks-unidos.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)
iD8DBQFEe2vnJJNoeGe+5O4RAt6eAJ4oji2WCaREeuaO6AQStms89+AlmgCfU9Jx
4ZO2kfGHLSbGPh+RJX8bfb4=
=9Xo2
-----END PGP SIGNATURE-----