Hi Alex,

>> I don't think so.  I have simple rules for the reader:
>> - dot is a symbol as any other
>> - if read inside a list, it means: place the next sexp into the current
>>   cells' cdr
>> ...
>> Why error?  Understanding of the three simple rules above is enough and
>> there are not any surprises and pathological cases.
> There are. You gave (1 2 3 . 4 . 5) as an example.
> Your algorithm first replaces the cdr of the last cell of (1 2 3) with
> '4', and then with '5'. So ". 4" is discarded.
> You violated your own rule, in that the "next sexp" is placed into the
> current cell's cdr, because precisely that sexp (the '4') gets lost.

no, the sexp '4' gets lost as a consequence of the rules not because I
violated the rules (simply because the last cell before reading 4 is the
same as before reading 5).  That rule does not cons any cell to the end.
Any other lisp reader is more constrained in these corner/error cases
and/or appears to have some additional arbitrary rules which I think are
not necessary.

> A naive user seeing the above expression would rather assume the first
> dot to be a normal symbol ("dot is a symbol as any other"), and the
> second dot to be the markup of a dotted pair. But implementing this
> would require a read-ahead to find the last dot in an expression.  Or
> he would assume that the first dot is indeed a markup character, and
> (4 . 5) is the "next sexp", but this is also not correct because then
> the expression should be written as (1 2 3 . (4 . 5)).

Well, I think that the only thing a user of any other lisp could expect
in such cases is an error (in some other cases, a hard to guess
behaviour).  What I have done basically, is that I replaced weird errors
and arbitrary behaviour by simpler and more general algorithm.

> However, you get into another dilemma: Despite the fact that the dot
> is a legal internal symbol, you can never read it in a list, not even
> by escaping it. It is a kind of meta-symbol, solely for the reader.

Your are right that my reader cannot read the dot symbol inside a list.
The question is whether it is a problem or not.  I would argue that it
isn't a problem, people never (or hardly ever) use/type such things.

At the moment, I don't do escaping in the reader (except inside strings)
because everything is allowed except the few "special" characters: ()"
Even ' and ` are not special and can be part of a symbol name.  Except
of course at the begining of a sexp (after 'skip').  The quoestion is
wherher escaping at the symbol level is useful and needed.  I personaly
never use it.  And, the user has always an option to intern a string.
It might get tricky with the dot inside a list but it is possible;

: '(1 2 3 . `(cons (intern ".")) 4 . 5)
-> (1 2 3 . 4 . 5)

would be needed to get the dot as a symbol before 4.  So there is a way
to achieve that, just not so convenient for cases that (maybe?) never

> Hmm, not sure. The current reader is (when you ignore special cases like
> NIL, read-macros, superparens etc.) in pseudo code:
>    (de read ()
>       (ifn (= "(" NextToken)
>          (readAtom)
>          (make
>             (loop
>                (T (= ")" NextToken)
>                   (skip) )
>                (T (= " . " NextToken)
>                   (chain (read)) )
>                (link (read)) ) ) ) )
> So the rule is that the dot is only treated as a meta-character when
>    - appearing in a list
>    - unescaped
>    - and not as part of a symbol

I don't think you stick to the rules though:-) See the examples I sent
before.  You'd have to add a few more rules like:

: '(. 1 2)
-> (\. 1 2)

: '(. . 1)
-> (\. . 1)

- not the first thing of the list

: '(. . .)
-> (\. . \.)

- if last thing of the list, make the list circular

- unless the dot (meta-character) was before which won't make it
  circular but will treat is as a symbol

Too many rules IMHO.

I just noticed you added escaping of the dot symbol to the printer in
the latest version of picolisp;-)

Thank you,

UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to