[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new function or modify read

This page is part of the web mail archives of SRFI 38 from before July 7th, 2015. The new archives for SRFI 38 contain all messages, not just those from before July 7th, 2015.



> I vote for a new function "read-..." and against modifying "read" because there
> might be situations where you need both in one program.

Duplication of names for similar operations is not a good idea.  It is
better to add parameters to the existing read and write function
(either an explicit parameter, probably optional, or a dynamically
scoped "parameter").  The proposed write-showing-shared is a slight
variation on write.  Someone else might (and will) come up with
another slight variation on write, for example writing numbers in a
particular base, or showing normally hidden fields of data structures,
or pretty-printing, etc.  I wouldn't want to have a separate procedure
for each feature.  The problem is that these features should not be
mutually exclusive, you want to be able to turn them on individually.

I much prefer building the functionality into the write (and read)
procedure, and having a parameter object (as in make-parameter of
Chez, PLT, etc) that can turn these features on/off.  For example,
instead of

  (write-showing-shared X)

you would write

  (parameterize ((write-shared #t))   ; write-shared is a parameter object
    (write X))

This way you can combine features as in

  (parameterize ((write-shared #t)
                 (write-radix 16)
                 (write-prettily #t))
    (write X))

Marc