-
Notifications
You must be signed in to change notification settings - Fork 8
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
[WIP] Implements list-proper-lens and list-improper-lens #293
base: master
Are you sure you want to change the base?
Conversation
Calling it |
@AlexKnauth Right. I'm not terribly fond of |
Names in |
The error message "expected an improper list of length n (plus the last element)" isn't clear enough. Would something to the effect of "length n (including the tail element)" be less ambiguous? |
In the setter you have to refer to the old target to do the length check; I think that disqualifies it from being an isomorphism; I'm not sure. |
|
If you can't make them out of |
Hmmm, thinking about this more.... what if we threw out the element-replacement part of these lenses? Instead, we had a lens that viewed true or false based on whether the list is improper: > (lens-view list-improper?-lens (list 1 2 3))
#f
> (lens-view list-improper?-lens (list 1 2 . 3))
#t
> (lens-set list-improper?-lens (list 1 2 3) #t)
(list 1 2 . 3) This still has the problem of lists where the last element is a list: > (lens-set list-improper?-lens (list 1 2 (list 3)) #t)
(list 1 2 3) I'm really not sure how to resolve this issue; there seems to be inherent ambiguity in the problem domain. |
Here's an early draft of the improper list lens proposal discussed in #292 . The two lenses implemented are:
Roughly, an improper list which was constructed using
list*
can be turned into the list which would be obtained by passinglist
the same arguments, and vice versa.If this sounds okay, I'll add documentation, as well as
stx-proper-lens
(which turns an improper syntax list into a proper syntax list), andstx-improper-lens
(which turns a proper syntax list into an improper one). Other syntax manipulations operating on improper syntax lists can then be obtained with simple combinations, e.g.@jackfirth I didn't check in-depth the requirements for isomorphisms, but since
(compose list-proper-lens list-improper-lens) = identity
and(compose list-improper-lens list-proper-lens) = identity
for all valid inputs (unless I missed a corner case), doesn't that make the pair of lenses an isomorphism? (In which case I guess I should rename them tolist->list*-lens
andlist*->list-lens
, orproper->improper-lens
andimproper->proper-lens
, or something similar).