Lisp HUG Maillist Archive

OPEN silently changes element type of stream

[LWW 5.0, but I also see this with 4.4.6]

  CL-USER 3 > (open "/tmp/test.txt"
                    :if-exists :append
                    :if-does-not-exist :create
                    :element-type 'lw:simple-char)
  #<STREAM::LATIN-1-FILE-STREAM C:\tmp\test.txt>

  CL-USER 4 > (stream-element-type *)
  BASE-CHAR

Is that intended behaviour?  I find that very disturbing (unless I'm
missing something).  I explicitely specify an element type, but LW
ignores it.

My guess is that this is because I didn't specify an external format,
but I don't find a justification for this behaviour in the docs.  The
LW Reference Manual for OPEN says that an error is signaled if the
element type doesn't satisfy the requirements for the external format,
but this is not the case here.  The CLHS entry for OPEN says that "a
substitution of types such as that which goes on in upgrading is
permissible."  But from my understanding this is also not the case, as
upgrading means that the type is substituted with a subtype, not a
supertype.

(Yes, I understand that the stream above gets a Latin1 external format
by default and so BASE-CHAR should suffice, but nevertheless...)

Thanks,
Edi.


Re: OPEN silently changes element type of stream

Hello Edi,

| [LWW 5.0, but I also see this with 4.4.6]
|
|   CL-USER 3 > (open "/tmp/test.txt"
|                     :if-exists :append
|                     :if-does-not-exist :create
|                     :element-type 'lw:simple-char)
|   #<STREAM::LATIN-1-FILE-STREAM C:\tmp\test.txt>
|
|   CL-USER 4 > (stream-element-type *)
|   BASE-CHAR
|
| Is that intended behaviour?  I find that very disturbing (unless I'm
| missing something).  I explicitely specify an element type, but LW
| ignores it.
|
| My guess is that this is because I didn't specify an external format,
| but I don't find a justification for this behaviour in the docs.  The
| LW Reference Manual for OPEN says that an error is signaled if the
| element type doesn't satisfy the requirements for the external format,
| but this is not the case here.  The CLHS entry for OPEN says that "a
| substitution of types such as that which goes on in upgrading is
| permissible."  But from my understanding this is also not the case, as
| upgrading means that the type is substituted with a subtype, not a
| supertype.
| (Yes, I understand that the stream above gets a Latin1 external format
| by default and so BASE-CHAR should suffice, but nevertheless...)

The rule of thumb is: the value of :external-format rules.

As (subtypep 'base-char 'lw:simple-char) => T, T, it looks OK with
upgrading.
--
Sincerely,
Dmitriy Ivanov
lisp.ystok.ru


Re: OPEN silently changes element type of stream

On Wed, 20 Sep 2006 10:03:16 +0200, Edi Weitz <edi@agharta.de> wrote:

> as upgrading means that the type is substituted with a subtype, not
> a supertype.

Should have been the other way around, obviously.


Updated at: 2020-12-10 08:47 UTC