2
votes

I am attempting to use the #‹digit10›{1,8}= and #‹digit10›{1,8}# syntax as described in The Reader, but receive the read-syntax: `#...=` forms not enabled when I do so:

This code has been run a DrRacket REPL with only #lang racket in the edit area, and in the racket program through a terminal emulator with no further arguments or (require ...)s.

racket> (list #1=100 #1# #1#)
    ==> read-syntax: `#...=` forms not enabled

Reading states that the parameter read-accept-graph determines whether the reader will parse graph syntax. What's strange is that the parameter is currently set to #t.

racket> (read-accept-graph)
    ==> #t

The following confirms that read-accept-graph changes how the reader reacts to graph syntax:

racket> (parameterize ([read-accept-graph #t])
          (read (open-input-string "(list #1=100 #1# #1#)")))
    ==> '(list 100 100 100)
racket> (parameterize ([read-accept-graph #f])
          (read (open-input-string "(list #1=100 #1# #1#)")))
    ==> string::7: read: `#...=` forms not allowed in `read-syntax` mode

It seems that the problem is that read-accept-graph is bound to #f at the moment when racket is reading the expressions, even if it might be #t by the time those expressions are executed.

TLDR:
How do I parameterize read-accept-graph to #t before expressions containing graph structure are read?

1
There's a vital missing piece of information in how exactly you're interacting with racket. Is this part of a top-level interaction? Your prompts suggest that it is. Can you provide either a single program that, when run, reproduces the problem, or alternately, a sequence of steps that reproduces the problem? - John Clements
FWIW, my strong suspicion is that what you're doing is morally equivalent to trying to change the reader of the code that's currently being read, which would probably be both a security hole and a performance problem. - John Clements
@JohnClements Thank you for raising the question about how I was actually running the code --- I've edited my question to clarify how the code was run. I think your suspicion is correct. The reason I believed that I should be able to change read-accept-graph at run time was because of the documentation on Reading Graph Structure (see Alexis King's answer). - Michael MacLeod

1 Answers

2
votes

The blunt answer to your question is that reader graph notation is not allowed in read-syntax mode, regardless of the current value of read-accept-graph.

However, your question helpfully uncovered two things:

  1. The recent rewrite of the reader in Racket v7.0 broke the error message raised when encountering illegal graph notation. The first error should read `#...=` forms not allowed in `read-syntax` mode, and the second should read `#...=` forms not enabled, the reverse of what they currently produce.

  2. The relevant section of the reference, Reading Graph Structure, does not properly document this difference between read and read-syntax.

I’ve pushed a fix for both of these problems in commit 2a667dc, which will be included in Racket v7.1.