brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 111 forks source link

printing of cyclic values #1626

Open shriram opened 3 years ago

shriram commented 3 years ago

This program

data Box:
  | box(ref v)
end

b-circ = box("empty")
b-circ!{v: b-circ}
b-circ.v

prints

image

Is there really a need to print different strings?

blerner commented 3 years ago

Yes, I view that as a design feature, actually.

In this particular case, it seems silly because the cycle is so tiny and because the hazard-tape border is visually different. But in the overall design of mutable refs it is entirely possible to alias at either the ref layer or at the object layer, and those aliases could be arbitrarily far apart.

I kinda want to enhance this display further, such that hovering over a <cyclic-foobar-##> draws an arrow (a la DrR's "show definitions", or DCIC's heap arrows) to the beginning of the cyclic reference, and maybe highlights its background the way highlighting srclocs does. I don't know if we have the technical bookkeeping ability to do that, but I think it might be helpful.

shriram commented 3 years ago

I expected something along these lines, and I agree that this distinction is useful if we can make unambiguous what is referring to what. Even if you can't draw arrows, simply the equivalent of Racket's #n= and #n# would be a huge help, perhaps implemented as tooltips. Right now, this is just confusing without being all that helpful.