[racket] Reading graph structure

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Thu Aug 18 09:25:30 EDT 2011

On Thu, Aug 18, 2011 at 9:09 AM, Harry Spier <harryspier at hotmail.com> wrote:
> Dear list members,
>
> Firstly thank you, for clarifying uninterned symbols.
>
> I've tried running the examples for reading graph structure in the reference
> manual 12.6.16 in DrRacket.
>
> When I put (#1=100 #1# #1#) in either the definitions or interactions
> window  I get
>
> . read: #..= expressions not allowed in read-syntax mode
>
> I've tried '(#1=100 #1# #1#) and it gives me the same error.

Try this:

> (read (open-input-string "(#1=100 #1# #1#)"))

Cyclic data is not allowed in *programs*, which is what you type in at the REPL.

> Also I'm not clear how #0=(1 . #0#)  converts to
> (let ([v (cons 1 #f)])
>      (set-cdr! v v) v)

It doesn't convert to that -- the cyclic data is directly constructed
by the reader.  Note also that pairs constructed by `cons' are
immutable, and thus your code won't work (that's why the reader is
necessary here).

See also `shared':
http://docs.racket-lang.org/reference/shared.html?q=shared#%28form._%28%28lib._racket/shared..rkt%29._shared%29%29
-- 
sam th
samth at ccs.neu.edu



Posted on the users mailing list.