calling stream_close twice

4 views
Skip to first unread message

Ralf Hemmecke

unread,
May 4, 2026, 3:42:17 PM (5 days ago) May 4
to fricas-devel
Dear Waldek,

I see the following functions:

MAKE_OUTSTREAM(name) == open_stream(name, 'output, false)

make_out_stream(name) == cons(true, MAKE_OUTSTREAM(name)) (*1)

make_append_stream(name) == cons(true, open_stream(name, 'output, true))

make_std_out_stream() == cons(false, get_lisp_std_out()) (*2)

get_lisp_stream(fs) == REST(fs)

but I can only guess, what the first boolean entry in (*1) and (*2)
stands for. Where it is actually used?

Oh, here it is...

stream_close(st) ==
if first(st) then CLOSE(rest(st))

Hmmm, my knowledge of lisp streams is limited, but this code does not
actually change the first entry in st destructively, so

stream_close(st)
stream_close(st)

would call CLOSE(rest(st)) twice on the stream. Is that a problem in
LISP if a closed file is closed again?

Ralf

Waldek Hebisch

unread,
May 4, 2026, 6:53:27 PM (5 days ago) May 4
to 'Ralf Hemmecke' via FriCAS - computer algebra system
AFAICS yes (as other operations on closed stream). The first entry
in representation of streams is to prevent closing Lisp standard
output, that could lead to serious troubles. Not doing anything
with closed stream is just standard programming practice.
Closing streams that we should close, but not closing Lisp
standard output, were more tricky. Boolean entry above solves
this problem.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages