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

Should colons be allowed in method names? #106

Closed
MadcapJake opened this Issue Jan 17, 2016 · 7 comments

Comments

Projects
None yet
4 participants
@MadcapJake
Copy link

MadcapJake commented Jan 17, 2016

In working out a script that gathers completions, I asked a question on IRC:

Can a :: sigil appear in names of methods/subs?

Initially the response was "that doesn't even make sense" but was followed up by:

class Foo { method foo::bar () { say 665; }; }; Foo.new."foo::bar"(); #-> 665

I don't understand what the usefulness of this feature is. I've done some skimming through S02#names and I can't find any mention of "you can use colons in method names but you'll need to access them via quotes" (though I could've missed it).

I confess, I don't quite have a firm grasp on the :: sigil and package lookup, but why would this be a useful feature?

@awwaiid

This comment has been minimized.

Copy link

awwaiid commented Jan 17, 2016

The feature isn't really that ':' can be in a method name -- it is that ANYTHING can be in a method name. An illustrative example is using ' ' (a single space) as a method name.

class CrayCray {
    my $method = method (|args) { 42 };
    $?CLASS.^add_methmethod(' ', $method);
}
say CrayCray.new." "() # outputs "42"

You can see here that I wasn't able to declare this method using the normal syntax. So maybe another question is why we are able to use the ":" in the method name without having to go out of our way to make it look fancy. I guess... because it's not ambiguous because you can't put namespaces in normal method declarations.

@niner

This comment has been minimized.

Copy link
Contributor

niner commented Jan 17, 2016

I'm actually for allowing as much as possible in method names. Not so much for Perl 6 code as method names that have to be quoted all the time aren't that useful, but for interop with other languages which may have strange naming conventions.

@MadcapJake

This comment has been minimized.

Copy link
Author

MadcapJake commented Jan 17, 2016

@niner I'm all for allowing any kind of character in method names but I think it's a bit confusing to just let colons occur in method declarations without needing to add them via a special method (ala the space method @awwaiid posted). At the very least, somewhere along the way, a warning/error should be issued as the :: syntax is meant to be a specific syntactic/semantic operator/sigil in a few different contexts (all of them revolving around names of things).

@LLFourn

This comment has been minimized.

Copy link

LLFourn commented Jan 17, 2016

:: is a required feature in method names because of the way coercions work.

http://docs.perl6.org/language/functions#Coercion_Types

A single ':' is even more necessary because of method foo:sym in
grammar actions.

On Mon, Jan 18, 2016 at 5:44 AM Jake Russo notifications@github.com wrote:

@niner https://github.com/niner I'm all for allowing any kind of
character in method names but I think it's a bit confusing to just let
colons occur in method declarations without needing to add them via a
special method (ala the space method @awwaiid https://github.com/awwaiid
posted). At the very least, somewhere along the way, a warning/error should
be issued as the :: syntax is meant to be a specific syntactic/semantic
operator/sigil in a few different contexts (all of them revolving around
names of things).


Reply to this email directly or view it on GitHub
#106 (comment).

@MadcapJake

This comment has been minimized.

Copy link
Author

MadcapJake commented Jan 19, 2016

@LLFourn thanks for the linkage! So in that situation they are allowed because they need to match how the type is written. Could you provide a link or explanation wrt to grammar actions, I don't see anything like that in the grammar actions section.

It still feels like some discussion could be had regarding whether they should be declared the same or if maybe there could be a pertinent error message given if you tried to call one, e.g.,

"Cannot locate &bar, this method call contains :: perhaps you meant to enclose the call in quotes."

@LLFourn

This comment has been minimized.

Copy link

LLFourn commented Jan 19, 2016

https://github.com/rakudo/rakudo/blob/nom/src/Perl6/Actions.nqp#L1570

I haven't tried but it probably works in vanilla Perl 6 too. (btw we truely need to work on the grammar docs).

If you mean that error messages could be improved when invoking methods with "::" that don't exist I can agree with you. Keep in mind that qualified method calls are a thing:

Lloyds-iMac:~ llfourn$ p '"foo".Mu::say()'
foo
Lloyds-iMac:~ llfourn$ p '"foo".Mu::sa()'
Cannot find method 'sa'
  in any find_method_qualified at gen/moar/m-Metamodel.nqp line 1101
  in block <unit> at -e line 1
@MadcapJake

This comment has been minimized.

Copy link
Author

MadcapJake commented Feb 7, 2016

Thanks everyone for clearing this up for me!

@MadcapJake MadcapJake closed this Feb 7, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.