[WIP] Implements list-proper-lens and list-improper-lens#293
[WIP] Implements list-proper-lens and list-improper-lens#293SuzanneSoy wants to merge 1 commit intojackfirth:masterfrom
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 passinglistthe 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) = identityand(compose list-improper-lens list-proper-lens) = identityfor 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*-lensandlist*->list-lens, orproper->improper-lensandimproper->proper-lens, or something similar).