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

Symmetric difference as a quanthash-y op #362

Closed
wants to merge 1 commit into from
Closed

Symmetric difference as a quanthash-y op #362

wants to merge 1 commit into from

Conversation

ab5tract
Copy link
Collaborator

(^+) -- symmetric difference for quant hashes

I'm still fairly convinced that it makes sense to unify set and quanthash
operators, but this patch is designed to open discussion about 'symmetric
difference' behavior for quanthashes as a separate issue from that. I've
thought about it quite a bit, maybe too much.. Either way, I'm not as sure about it
as when I started.

Outside of LoL context, (^+) makes a fair amount of sense -- give back what was
left after removing any intersecting values:

> ( x => 1, y => 2, <z> ).Bag (^+) ( <w>, x => 2, y => 4 ).Bag
Bag.new(w,x(1),y(2),z)

The implementation uses the absolute value of the subtraction of the
intersecting keys. This allows for symmetry, but because subtraction is not
commutative any claim to symmetry is broken by the order of LoLs.

It could also be argued that the absolute value symmetry is flawed to begin
with, and the ordering should matter in both (^+) and [(^+)] forms.

I'm not as convinced anymore of how important, let alone correct, either approach is,
but I wanted to publish it to see how others might feel. I haven't found spec
information on set operators, but I remember looking when I first started on
this months ago.

(Also, I wanted to note that since starting this work, lizmat++ has contributed a
pretty freaking sweet patch to add LoL to (^). It makes me wonder what might be
possible here, but "implement first, apologize second, golf third" seems like a better
approach for the current tuits.)

CAUTION: NOT WORKING

However, this branch isn't just about that. This works from the repl (but crashes from a file, see the gist linked from the bottom):

(rakudo/quant-sym-diff) $ ./perl6
> my $b = ( x => 1, y => 2, <z> ).Bag
bag(x, y(2), z)
> my $b2 = ( <w>, x => 2, y => 4 ).Bag
bag(w, x(2), y(4))
> $b (^+) $b2
bag(x, y(2), z, w)

But this doesn't.

(rakudo/quant-sym-diff) $ ./perl6
> ( x => 1, y => 2, <z> ).Bag (^+) ( <w>, x => 2, y => 4 ).Bag
===SORRY!=== Error while compiling <unknown file>
Two terms in a row
at <unknown file>:1
------> ( x => 1, y => 2, <z> ).Bag ⏏(^+) ( <w>, x => 2, y => 4 ).Bag
    expecting any of:
        infix stopper
        infix or meta-infix
        statement end
        statement modifier
        statement modifier loop

This gist contains a test file which will fail with the same issue: https://gist.github.com/ab5tract/572342901a4561c53dbc

@lizmat
Copy link
Contributor

lizmat commented Mar 28, 2018

I think the points of this PR have been addressed by my work on set operators. Please correct me if you think I'm wrong :-)

@lizmat lizmat closed this Mar 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants