lens icon indicating copy to clipboard operation
lens copied to clipboard

struct->vector isomorphism

Open jackfirth opened this issue 10 years ago • 5 comments

Given a structure id, it should be possible to construct an isomoprhism between struct instances of that type and vectors

> (struct position (x y))
> (lens-view (struct->vector-lens position) (position 1 2))
'#(1 2)

jackfirth avatar Dec 04 '15 23:12 jackfirth

I think using the name struct->vector-lens would be confusing because struct->vector puts the extra struct:position symbol at the beginning. struct->list-lens would work for this though, because struct->list doesn't include that symbol.

AlexKnauth avatar Dec 05 '15 03:12 AlexKnauth

I forgot about struct->vector, the lens form should match whatever that does. A struct->list lens would have to be careful of the fact that struct->list is only available in racket 6.3, I'd like to keep supporting the versions we do now.

jackfirth avatar Dec 05 '15 05:12 jackfirth

We could support struct->list-lens without relying on 6.3 if we looked at the struct-info and used the normal accessors, which we should probably be doing anyway.

AlexKnauth avatar Dec 05 '15 05:12 AlexKnauth

Agreed, that would probably be the best way to do this.

jackfirth avatar Dec 05 '15 05:12 jackfirth

Should this issue be closed because of https://github.com/jackfirth/lens/pull/266 ?

AlexKnauth avatar Dec 06 '15 19:12 AlexKnauth