The reader for `#hash` parses parentheses and dots itself, instead of
recurring and checking the result, so that it can provide better error
reporting.

For example, if I write

 #hash((x . 1) y (z . 2))

then the reader can highlight y and complain about that part
specifically. If the `#hash` part of the reader instead inspected the
result of a recursive `read`, then it wouldn't have source location for
"y", or it would have to recur in a way that preserved locations even
though the locations would be later discarded.

Also, checking after recurring would make it more difficult to report
errors left-to-right, such as getting an error about "]" instead of "y"
in

 #hash((x . 1) y ]

It's difficult to say just how much those things matter, and there are
trade-offs in flexibility and error reporting, but that's why the
reader works the way it does currently.

At Sun, 12 Apr 2015 08:54:16 -0400, "Alexander D. Knauth" wrote:
> For something like this:
> #lang racket
> (define orig-readtable (current-readtable))
> (parameterize ([current-readtable
>                 (make-readtable orig-readtable
>                                 #\( 'terminating-macro
>                                 (λ (c in src ln col pos)
>                                   (read-syntax/recursive src in c 
> orig-readtable)))])
>   (println (read (open-input-string "()")))             ; ’()
>   (println (read (open-input-string "#hash()"))))  ; . read: bad syntax 
> `#hash('
> 
> I can understand why this could be a problem, but why doesn't it work so that 
> if reading the () produces the correct association list, it still works?
> 
> Otherwise is there any way around it without just reimplementing #hash(), 
> #hasheq(), #hasheqv(), #(), etc. ?  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email 
> to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to