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

"string" but False !eqv "string" but False #3507

Open
Leont opened this issue Feb 22, 2020 · 7 comments · May be fixed by #5275
Open

"string" but False !eqv "string" but False #3507

Leont opened this issue Feb 22, 2020 · 7 comments · May be fixed by #5275

Comments

@Leont
Copy link
Contributor

Leont commented Feb 22, 2020

The Problem

say "foo" but False eqv "foo" but False

Expected Behavior

This should print True

Actual Behavior

It prints False

I'm guessing this is because their types are different due runtime mixing in.

Environment

This is Rakudo version 2020.01 built on MoarVM version 2020.01.1
implementing Perl 6.d.

@dumarchie
Copy link
Contributor

Given your example, the respective types as reported by .WHICH are something like Str+{<anon|1>} and Str+{<anon|2>}. Because different types are generally not considered to be eqv the actual behavior is correct given these types.

Of course it would be nicer if in this case the type would be something like Str+{<Bool|0>}.

@Leont
Copy link
Contributor Author

Leont commented Feb 23, 2020

Given your example, the respective types as reported by .WHICH are something like Str+{<anon|1>} and Str+{<anon|2>}. Because different types are generally not considered to be eqv the actual behavior is correct given these types.

Yeah, it's correct, it's just not useful.

Of course it would be nicer if in this case the type would be something like Str+{<Bool|0>}.

Yeah, that would pretty much exactly by what I would hope for.

@dumarchie
Copy link
Contributor

According to the documentation of infix but you can't actually mix-in an object. Instead, Raku creates an anonymous role with a method that returns the object.

Theoretically, Raku could memoize the anonymous roles it creates, but I doubt that is very practical. So I suggest using but to mix-in a named role, for example:

my role Irrelevant {
    method Bool(--> False) {}
}

my $a = "foo" but Irrelevant;
say $a.^name unless $a;          # OUTPUT: «Str+{Irrelevant}␤»
say $a eqv "foo" but Irrelevant; # OUTPUT: «True␤»

@vrurg
Copy link
Member

vrurg commented Feb 27, 2020

I think this can be closed now.

@vrurg vrurg closed this as completed Feb 27, 2020
@Leont
Copy link
Contributor Author

Leont commented Feb 27, 2020

According to the documentation of infix but you can't actually mix-in an object. Instead, Raku creates an anonymous role with a method that returns the object.

The documentation can be explained to do either thing. Pointing at it isn't much of an argument to do the less helpful of the two options.

Theoretically, Raku could memoize the anonymous roles it creates, but I doubt that is very practical.

I'm pretty sure that mixing in booleans is 95% of all runtime mixins of a value. In particular, «$string but False» is a value that's generated by the core argument parsing --/foo. And «0 but True» was pretty much how the feature was invented. Even just special casing True and False would already be quite helpful (Str is probably the other 4%)

So I suggest using but to mix-in a named role, for example:

That is not a very helpful suggestion when raku itself gives me "string" but False values

@Leont
Copy link
Contributor Author

Leont commented Feb 27, 2020

This doesn't look like such a difficult issue. It's really just a matter of caching a parameterizable role per value type, or am I missing something? The only challenge I can see is that it probably has to happen in NQP.

@jnthn
Copy link
Member

jnthn commented Feb 27, 2020

Ultimately, if we want them to be eqv, then we need to make interning them part of the language spec. That feels reasonable to me. (Note that this needs doing carefully, using the VM-backed paramerizable stuff support, so that the interning happens across pre-compiled modules too.)

@jnthn jnthn reopened this Feb 27, 2020
@Leont Leont linked a pull request Jun 5, 2023 that will close this issue
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

Successfully merging a pull request may close this issue.

4 participants