• Synonym Streams

    From Alan Bawden@21:1/5 to All on Mon Feb 19 17:06:33 2024
    I no longer remember why we designed this whole synonym stream thing.
    (Where by "we" I really mean Dan Weinreb and Dave Moon, I was mostly
    just in the room when they did this.) I _think_ it is mimicking
    something that the Multics I/O system does.

    I'm not aware of any modern system where I/O has this feature. It is
    true that modern streams are often wrapped around other streams to
    compose features (a text string may wrap a binary stream which may in
    turn wrap an unbuffered stream, etc.), but the idea of one stream
    wrapping another as an _indirection_ mechanism, so that you can
    dynamically replace the wrapped stream with a different one, seems
    unique to Common Lisp.

    I'm not sure what problem it solves, since I don't remember ever wanting
    to use it in Common Lisp (or wishing I had something like it when
    programming in Java, Python, or C). Buy maybe I'm forgetting something.

    I would be interested to know of any place that _does_ use synonym
    streams to solve some real problem.

    - Alan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alan Bawden@21:1/5 to Alan Bawden on Sun Apr 14 18:49:28 2024
    steve <sgonedes1977@gmail.com> writes:

    Alan Bawden <alan@csail.mit.edu> writes:

    > I no longer remember why we designed this whole synonym stream thing.

    [ ... ]

    bivalent streams are useful.

    "In addition, SBCL supports various extensions of ANSI Common Lisp
    streams:

    *Bivalent Streams*
    A type of stream that can read and write both ‘character’ and
    ‘(unsigned-byte 8)’ values.

    I don't see any connection with synonym streams here.

    > I'm not aware of any modern system where I/O has this feature.

    POSIX man dup

    This does not make a synonym in the sense that Common Lisp is using the
    word. If it made a synonym (in the Common Lisp sense) then after:

    old = open("old_file", O_RDONLY);
    new = open("new_file", O_RDONLY);
    fd = dup(old);
    dup2(new, old);

    it would be the case that reading from FD would read from "new_file".
    But if you try it, you will find that FD is still reading from "old_file".

    > I would be interested to know of any place that _does_ use synonym

    I use the following for type 1 font dissasembler. I do not have the code
    right now, but bivalent streams make it much easier to
    read-char/read-byte.

    The code you included isn't using synonym streams.

    I think you haven't fully internalized what a weird feature synonym
    streams really are. Its easy to breeze through the documentation and
    think that a synonym stream is just a way to duplicate a stream. But
    it's more than that: The new stream follows the _current_ value of a
    dynamic variable.

    - Alan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to steve on Mon Apr 15 00:49:38 2024
    On Sun, 14 Apr 2024 11:36:11 -0400, steve wrote:

    *Bivalent Streams*
    A type of stream that can read and write both ‘character’ and
    ‘(unsigned-byte 8)’ values.

    How is that supposed to work, exactly? Is each stream item tagged in some
    way to identify it as a “character” versus an “unsigned-byte 8”?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)