Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will contract a rare disease.


comp / comp.lang.lisp / Re: Synonym Streams

SubjectAuthor
* Re: Synonym Streamssteve
+- Re: Synonym StreamsAlan Bawden
`* Re: Synonym StreamsLawrence D'Oliveiro
 `- Re: Synonym Streamssteve

1
Subject: Re: Synonym Streams
From: steve
Newsgroups: comp.lang.lisp
Date: Sun, 14 Apr 2024 15:36 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!69.80.99.27.MISMATCH!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 14 Apr 2024 15:36:12 +0000
From: sgonedes1977@gmail.com (steve)
Newsgroups: comp.lang.lisp
Subject: Re: Synonym Streams
References: <6pd1+E7bUWxwHGM59@bongo-ra.co> <uqtv0o$1fckl$2@dont-email.me> <23FZrFyCKlaZfJP1R@bongo-ra.co> <20240219092306.348@kylheku.com> <867cj0qfbq.fsf_-_@williamsburg.bawden.org>
Date: Sun, 14 Apr 2024 11:36:11 -0400
Message-ID: <8734roez2s.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:qbsZmmH4/M+cVEPXqJbnOM7FpaE=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Lines: 54
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-uIGVqe6N2HiQaplOV95qlEaJCfkl3iucTl75mA/wmV6WL+ScRTaxdSZ5DXt6oBst4npVpOCI+AxGuKj!y/R+O1OCSeTbzc8dPZpp0cCGXKhuhT5pCy5o3O6jz+DgGQ==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

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'm not aware of any modern system where I/O has this feature.

POSIX man dup

> 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.

;;
;;; Macros

(defmacro with-open-file-stream (direction type options &body body)
`(with-open-file
(,@options :direction ,direction :element-type ,type)
,@body))

(defmacro with-binary-input-stream (options &body forms)
`(with-open-file-stream :input '(unsigned-byte 8) ,options ,@forms))

(defmacro with-ascii-input-stream (options &body forms)
`(with-open-file-stream :input 'character ,options ,@forms))

(defmacro with-ascii-output-stream (options &body forms)
`(with-open-file-stream :output 'character ,options ,@forms))

(defmacro with-binary-output-stream (options &body forms)
`(with-open-file-stream :output '(unsigned-byte 8) ,options ,@forms))

> streams to solve some real problem.

i do not have real problems.

> - Alan

steve

Subject: Re: Synonym Streams
From: Alan Bawden
Newsgroups: comp.lang.lisp
Organization: ITS Preservation Society
Date: Sun, 14 Apr 2024 22:49 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!bawden.eternal-september.org!.POSTED!not-for-mail
From: alan@csail.mit.edu (Alan Bawden)
Newsgroups: comp.lang.lisp
Subject: Re: Synonym Streams
Date: Sun, 14 Apr 2024 18:49:28 -0400
Organization: ITS Preservation Society
Lines: 49
Message-ID: <8634rno8zr.fsf@williamsburg.bawden.org>
References: <6pd1+E7bUWxwHGM59@bongo-ra.co> <uqtv0o$1fckl$2@dont-email.me>
<23FZrFyCKlaZfJP1R@bongo-ra.co> <20240219092306.348@kylheku.com>
<867cj0qfbq.fsf_-_@williamsburg.bawden.org> <8734roez2s.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 15 Apr 2024 00:49:31 +0200 (CEST)
Injection-Info: bawden.eternal-september.org; posting-host="db96abda36b57175e5859ec2315adb6f";
logging-data="4074860"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192NyTsc2R827SNxKHYLEL9"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
Cancel-Lock: sha1:ZPdY3MplbOf5Q6sFUUvHsIF7i4w=
sha1:VdPLaZdlO6zXFte2QJtKJyxDGvs=
View all headers

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

Subject: Re: Synonym Streams
From: Lawrence D'Oliv
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 15 Apr 2024 00:49 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.lisp
Subject: Re: Synonym Streams
Date: Mon, 15 Apr 2024 00:49:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <uvhtj1$3th0n$7@dont-email.me>
References: <6pd1+E7bUWxwHGM59@bongo-ra.co> <uqtv0o$1fckl$2@dont-email.me>
<23FZrFyCKlaZfJP1R@bongo-ra.co> <20240219092306.348@kylheku.com>
<867cj0qfbq.fsf_-_@williamsburg.bawden.org> <8734roez2s.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 15 Apr 2024 02:49:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2acb11c3364910c2dba94812b909635b";
logging-data="4113431"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fzoOE0Jm7J0k6ZClf6Qjf"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:59wVf/VHWxQzIWRtDiwfFzrugCQ=
View all headers

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”?

Subject: Re: Synonym Streams
From: steve
Newsgroups: comp.lang.lisp
Date: Fri, 19 Apr 2024 17:44 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!border-4.nntp.ord.giganews.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 19 Apr 2024 17:44:58 +0000
From: sgonedes1977@gmail.com (steve)
Newsgroups: comp.lang.lisp
Subject: Re: Synonym Streams
References: <6pd1+E7bUWxwHGM59@bongo-ra.co> <uqtv0o$1fckl$2@dont-email.me>
<23FZrFyCKlaZfJP1R@bongo-ra.co> <20240219092306.348@kylheku.com>
<867cj0qfbq.fsf_-_@williamsburg.bawden.org> <8734roez2s.fsf@gmail.com>
<uvhtj1$3th0n$7@dont-email.me>
Date: Fri, 19 Apr 2024 13:44:57 -0400
Message-ID: <87frvhl012.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:L49SE/PHG48pJvZ2Ors8ypYx+Sc=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Lines: 27
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-vK8qKAiVyThbuWGyPPUGBTOQ3u8pZI7xVxEOJ+cK4bmTm2NyL2mMCnEfG5I1pJwboByamBbWflhaSB3!PR4pt7cTOCQDvZfSVbWmGbvFCEN2OaIqome8B/K2KsWNPw==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

Lawrence D'Oliveiro <ldo@nz.invalid> writes:

> 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”?

I don't have any code at the moment - you could use 'base-char which
includes

(with-open-file (out "/home/steve/file.txt" :direction :output :element-type 'base-char :if-exists :overwrite)
(write-string "this" out)
(terpri out)
(write out :stream out))
#<SB-SYS:FD-STREAM for "file /home/steve/file.txt" {1002E2A943}>
CL-USER>

File :
this
#<SB-SYS:FD-STREAM for "file /home/steve/file.txt" {1002E2A943}>

hope this helps...

1

rocksolid light 0.9.8
clearnet tor