pyret-lang icon indicating copy to clipboard operation
pyret-lang copied to clipboard

printing of cyclic values

Open shriram opened this issue 4 years ago • 2 comments

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?

shriram avatar Nov 01 '21 17:11 shriram

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

  • The outermost value you have on the penultimate line is an object, with a ref field that refers back to the outermost object. The cycle gets tied when you re-encounter the object.
  • The outermost value you have on the last line is a ref whose value is an object with the same ref as the outermost one. The cycle gets tied when re-encountering the ref.

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.

blerner avatar Nov 01 '21 23:11 blerner

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.

shriram avatar Nov 02 '21 00:11 shriram