Re: Is this legal ANSI CL behaviour?
From: Christopher C. Stacy (cstacy_at_news.dtpq.com)
Date: 10/24/04
- Next message: André Thieme: "Re: Why Lisp supposedly "sucks for game development""
- Previous message: xstream: "Re: Why Lisp supposedly "sucks for game development""
- In reply to: Thomas Schilling: "Is this legal ANSI CL behaviour?"
- Next in thread: string-downcase: "Re: Is this legal ANSI CL behaviour?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 24 Oct 2004 20:23:23 GMT
"Thomas Schilling" <tjs_ng@yahoo.de> writes:
> Since I have the general experience that CL is so well-designed that
> when functions are given not-so-sane arguments they are mostly
> defaulted to do the Right Thing (tm).
>
> So this seems to me like a bug in acl62:
>
> CL-USER> (subseq "abcd" 0 40)
> "abcd^@???^E^@?^@abcd^@???^E^@?^@abcd^@???^E^@?^@abcd"
>
> I would have expected it to return "abcd", that is automatically
> realizing that 40 > (length "abcd") and choosing the latter as the
> upper bound. Or at least to signal an error like clisp does.)
I don't think it's an ANSI compliance bug.
It's an error for the programmer to reference past the end of a sequence;
the consequences are undefined. Many implementations signal an error.
Some sequence functions (for example, ELT) "Should signal an error of
type type-error if index is not a valid sequence index for sequence.".
I'm not sure how one easily learns all that using CLHS.
I found it out by starting with the X3J13 cleanup issue
SUBSEQ-OUT-OF-BOUNDS referenced on the SUBSQ.
(I'm therefore not 100% sure myself that it's true.)
Your suggestion of truncating the result sequence to the active length
doesn't seem like better solution. Since SUBSEQ is not documented to
signal an error in this situation, you must not be relying on that to
allow handling of the problem at runtime. Therefore, you must be expecting
that this out-of-bounds situation represents a bug in the program.
I think that returning the semi-garbage answer you see above is actually
slightly more likely to help you debug than returning the truncated answer.
If you want a truncating version of SUBSEQ, you should make the explicit in
your program by giving it a new name.
I do think it would be optimal runtime behaviour if an error were signalled.
I am not sure what the advantage is of not doing so, at normal safety levels.
When the cleanup issue was written, all the "current practice" implementations
signalled an error.
- Next message: André Thieme: "Re: Why Lisp supposedly "sucks for game development""
- Previous message: xstream: "Re: Why Lisp supposedly "sucks for game development""
- In reply to: Thomas Schilling: "Is this legal ANSI CL behaviour?"
- Next in thread: string-downcase: "Re: Is this legal ANSI CL behaviour?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|