Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add struct->struct-lens #268

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AlexKnauth
Copy link
Collaborator

see #267

@jackfirth
Copy link
Owner

This is meant to be an isomorphism yes? I think allowing field reordering would be good. A contrived use case I can think of off the top of my head is wanting a lens to view a position struct in reverse order:

(struct position (x y))
(define inverse-pos-lens (struct->struct-lens position position [x y] [y x]))
(lens-view inverse-pos-lens (position 1 2))

@AlexKnauth
Copy link
Collaborator Author

What you said in (#267 (comment)) about lens-join/struct made me think that of the cases where you might want to re-order the fields, a lot of those could be cases where you might want the freedom and power of (lens-join/struct position position-y-lens position-x-lens). I can see those use cases, but I can see many more where you might want (lens-join/struct position (lens-compose negate-lens position-y-lens) position-x-lens) or something similar.

(syntax-e #'s1) (syntax-e #'s2))
stx))
#'(local [(define (s1->s2 struct1)
(#%app s2.constructor-id (s1.accessor-id struct1) ...))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the #%app needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but I suspect it's because the constructor-id from the struct-info ends up pointing to an identifier macro or something like that that messes it up in some way. I forget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants