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

cons forms satisfy pair? #119

Merged
merged 1 commit into from
Apr 5, 2022
Merged

cons forms satisfy pair? #119

merged 1 commit into from
Apr 5, 2022

Conversation

vito
Copy link
Owner

@vito vito commented Apr 5, 2022

previously, neither pair? nor list? would return true for this form:

[a & b]

so this changes pair? to also return true for Cons values (square brackets).

admittedly, the naming with list/cons/pair is awfully inconsistent between Go and Bass right now.

in Bass, a list? value must be a linked list - a List whose second value is another List. both Cons and Pair can satisfy this.

in Go, List is the interface implemented by Cons and Pair, but it doesn't ensure that the second value is a list, so it's not always a list?.

in Bass, a pair? value used to be ONLY the Pair type. now it will be true of Cons as well.

here's the old truth table:

         []  ()  [1 2] (1 2) [1 & 2] (1 & 2)
list?    1   1     1     1      0       0
pair?    0   0     0     1      0       1
empty?   1   1     0     0      0       0

here's the new truth table:

         []  ()  [1 2] (1 2) [1 & 2] (1 & 2)
list?    1   1     1     1      0       0
pair?    0   0     1     1      1       1
empty?   1   1     0     0      0       0

there is no cons? - just as there is no keyword?, but there is symbol?. there may be a good reason to add both in the future, but I'm waiting for it to arrive.

an alternative approach here might be to have Cons support decoding into Pair, but that may be the path to darkness. Value.Decode explicitly calls out that it shouldn't be used for converting between Value types, though I don't remember if that's coming from a footgun or if it's speculative.

previously, neither pair? nor list? would return true for this form:

  [a & b]

this changes pair? to also return true for Cons values (square
brackets).

admittedly, the naming with list/cons/pair is awfully inconsistent
between Go and Bass right now.

in Bass, a list? value must be a linked list - a List whose second value
is another List. both Cons and Pair can satisfy this.

in Go, List is the interface implemented by Cons and Pair, but it
doesn't ensure that the second value is a list, so it's not always a
list?.

in Bass, a pair? value used to be ONLY the Pair type. now it will be
true of Cons as well.

here's the old truth table:

             []  ()  [1 2] (1 2) [1 & 2] (1 & 2)
    list?    1   1     1     1     0        0
    pair?    0   0     0     1     0        1
    empty?   1   1     0     0     0        0

here's the new truth table:

             []  ()  [1 2] (1 2) [1 & 2] (1 & 2)
    list?    1   1     1     1     0        0
    pair?    0   0     1     1     1        1
    empty?   1   1     0     0     0        0

there is no cons? - just as there is no keyword?, but there is symbol?.
there may be a good reason to add both in the future, but I'm waiting
for it to arrive.

an alternative approach here might be to have Cons support decoding into
Pair, but that may be the path to darkness. Decode explicitly calls out
that it shouldn't be used for converting between Value types, though I
don't remember if that's coming from a footgun or if it's speculative.
@vito vito added enhancement New feature or request breaking Removes or replaces previously supported functionality labels Apr 5, 2022
@vito vito merged commit 4786b51 into main Apr 5, 2022
@vito vito deleted the cons-is-pair branch April 5, 2022 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Removes or replaces previously supported functionality enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant