On Mon, Oct 21, 2019 at 4:20 AM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:

The alternative would be, say, #!(encoding latin1). Is it worse than
#!encoding latin1? Apart from that, do we really need such a
directive?

Caveat: When you're parsing encoding directive, you don't know yet which encoding the file
is in.  So you have to read the file in either binary data and then upgrade it to text when you
know the encoding, or you read the file in a provisional encoding that don't have "illegal encoding"
(e.g. latin-1 is ok, utf-8 is not) and then "switch" the encoding after you know it.

The latter may not be always possible (input text may be buffered inside a text port).
To do the former, you may not be able to share the S-expression reader that reads from a text port.

So I suggest to keep encoding directive simple, parsable with a small finite automaton without lookahead.

BTW, If you have encoding token inside commented-out S-expression:

   #;(this is (
           a commented out S-expr
           and contains #!encoding utf-8
     ))

Does #!encoding count?  Or should it be ignored?