-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow defining methods called !
and ?
#7959
Comments
Also I totally recognize that this should be a low-priority issue, especially for the core team, but I think it makes sense to keep track of ideas and suggestions like this. |
What would be the meaning for those symbols? |
It would depend on the context. They would be regular methods. For example, in the context of I would argue that it would be very nice for I can't think of other use cases off of the top of my head, but I don't think that a feature should be prevented just because it might not seem that useful in the typical contexts. If I hadn't seen the suggestion by @artmadeit, I would not have thought of using it for factorial. This doesn't seem like an incredibly coimplicated feature, nor does it seem like one prone to causing people to create bugs. It seems consistent with the majority of the language semantics and Crystal's Ruby roots. |
I agree that it's easy to implement. I disagree about it being useful. Theres simply no easy way to talk about these things (is it bang? exclamation mark? question?) and if the meaning is going to depend on context then it's going to be even more confusing. I have experience with custom operators in Haskell and I think this is a road for a lot of confusion. So I'll say no to this. |
I respect your opinion but it seems harsh to close this without further discussion from other members of the community. |
Okay,sorry. |
IMO, however, |
I can only see confusing behaviour. I expect a ! method to overload the unary not operator, not be some other method named ! |
Community member passing by. Reminds me of how people sometimes write "?" by itself in chat. |
" would argue that it would be very nice for Object#not_nil! to be replaced/aliased by Object#!" Ugh, please no. I wouldn't mind making it a bit more general by changing that to |
What could possibly go wrong? |
Yeah, if no one has any good use-cases for this aside from |
Thank you all for the feedback, but let's try to be more. respectful of other's ideas and proposals. (no mocking nor sarcasm, please) ❤️ |
This is not a request to allow redefining the meaning of the prefix-
!
operator. This is a request to allow defining a method which could be called on something likesomething.!
orsomething.?
.Since there is no case where someone can define a
!
or?
method, it wouldn't conflict with any other language features. Redefining the meaning of the prefix-!
operator is explicitly denied by the compiler (for good reason!).This was brought up by a (seemingly) new user in the gitter chat
The text was updated successfully, but these errors were encountered: