[plt-scheme] `shared' syntax confusing

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Nov 11 08:41:31 EST 2008

At Tue, 11 Nov 2008 10:57:10 +0900, Alex Shinn wrote:
> Hi,
> 
> Matthew Flatt <mflatt at cs.utah.edu> writes:
> 
> > Your approach would automatically work with `list*' --- or with any
> > function that does not inspect its arguments and constructs a result
> > using only pairs, vectors, and boxes.
> 
> I'm not quite sure what you mean by that.  The approach in
> general allows any computation. 

A minor point...

I had in mind something like

   (shared ([a (append b a)]
            [b (list 1 2)])
     a)

which is sensible in principle, but doesn't work because `append'
inspects its first argument's list structure (unlike it's last
argument, which is uses without inspecting).

I also had in mind things like

   (define (thunkify a) (lambda () a))

   (shared ([a (thunkify a)])
     a)

which doesn't return a list, vector, or box.

I didn't mean to claim that the current `shared' can handle these
cases, only to summarize when your approach would work.

> > In any case, I've added `list*' and `append' support to `shared' in
> > `scheme/base'. (For both of our approaches, `append' works only with
> > graph references within its final argument.)
> 
> This is not true.  My implementation allows
> 
>   (shared ((a (append (list 1 2 a 3) a))) a)

Good point. I was thinking of immediate uses of graph references, as in
the `append' example above, but your version does capture more `append'
patterns.


I'm still reluctant to use a variant of `shared' that has to be defined
in terms of placeholders. Also, the existing support for mutable
structs is important for the original role of `shared' (in HtDP
Advanced as a way to print cyclic structures created via mutation). For
now, then, I'll plead laziness, since it would take work to fuse the
best parts of what we have on the table.

Meanwhile, I'm happy that you can easily get what you want out of
`make-reader-graph'.


Matthew



Posted on the users mailing list.