At Tue, 14 Apr 2015 21:04:38 -0400, "Alexander D. Knauth" wrote: > > On Apr 14, 2015, at 6:57 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote: > > > This is the kind of problem that the readtable argument to > > `read/recursive` was meant to solve, but I see that it doesn't work in > > this case. > > > > I have in mind that you'd map `#` to use `read/recursive` with a > > readtable that restores the default `(`. Mapping `#` would cover hash > > tables, vectors, and prefab structures. > > > > As `read/recursive` is currently implemented, however, a given > > readtable is would be used only for the initial `#`, so it doesn't > > affect the `(`s that delimit hash-table entries. > > Do you mean 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)) > #\# 'non-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()")))) ; '#hash()
Yes. > Because this worked! I’m surprised though; how is it communicating > the orig-readtable to the #hash reader macro so that it can use that > for parsing the ()? Hm, right. The current reader does use the given readtable all the way through the opening '(', but not after that --- which doesn't seem like a good choice overall. > This doesn’t work, though: > (parameterize ([current-readtable ….]) > (println (read (open-input-string "#hash((a . b))")))) ; . read: expected > or > `[' or `{' to start a hash pair > If I replace the inner set of parens with brackets, it works. Yep. > > It would make sense > > --- and I think it would solve your problem --- if the given readtable > > instead applied to all of the delimiters of the non-nested parts of the > > first datum in the input. > > Would this require giving an extra argument to reader macro > procedures, or am I misunderstanding something? I had in mind an extra argument to `read/recursive` to enable the new mode, with no change to the arguments to reader macros. But, now that you say so, I see a potential need to send a readtable to reader macros, too. That would be needed if you wanted to implement a `#hash` macro from scratch that behaves the the built-in one. The interface for reader macros is already complicated, but I think it would work to add one extra optional-to-accept argument that is the readtable to use for immediate delimiters. -- 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.