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

Backreferences? #22

Open
bfoz opened this issue Sep 18, 2018 · 5 comments
Open

Backreferences? #22

bfoz opened this issue Sep 18, 2018 · 5 comments

Comments

@bfoz
Copy link

bfoz commented Sep 18, 2018

What's the Qo-ish way to affect something similar to backreferences?

For example, match a Hash where the value of the :foo key matches the value of the :bar key.

# This doesn't work
Qo[:foo => :bar, :bar => :foo] === {foo:42, bar:42}    # => false
@baweaver
Copy link
Owner

It'd try and do literal compare -> methodized compare. Back references don't currently work as Qo has no idea of that level of introspection.

@baweaver
Copy link
Owner

Now as to how to do that, it'd have to be an entirely different syntax.

I could see something along the lines of adding a handler to Qo:

Qo2 = Qo.with(back_reference: true, bidirectional_matching: true)

Qo2[:foo => :bar, :bar => :foo] === {foo:42, bar:42} # true

@bfoz
Copy link
Author

bfoz commented Sep 19, 2018

How about something like...

Qo[foo: Qo[:bar], bar: Q[:foo]]

That would requiring modifying the hash matcher to notice that the value matcher is another Qo, and then apply it to the target object to get the value to be matched. It would be a small performance penalty, which I know you're against, but it makes the syntax cleaner.

@bfoz
Copy link
Author

bfoz commented Sep 19, 2018

As soon as I posted that I thought of an another idea. Funny how that works.

Taking a page from the Any concept: make an explicit backreference matcher object. Call it BR, for lack of a better idea.

Qo[foo: BR[:bar], bar: BR[:foo]]

@baweaver baweaver mentioned this issue Feb 11, 2019
@baweaver
Copy link
Owner

Thinking about this in the process of releasing 0.99, this seems a bit out of place for the current API.

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

No branches or pull requests

2 participants