Ask Your Question
0

Operator Overloading

asked Dec 20 '11

Hossein gravatar image Hossein
81 8 20

Does Rascal support operator overloading? And, if it does, where can I on the documentation find a link to the syntax and the like?

delete close flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered Mar 07

Hossein gravatar image Hossein
81 8 20

When I read this answer a few months ago, I thought: "OK, reasonable. Not very comfortable to me. But, I need to get on with it...". It turns out though that the lack of user-defined operator overloading caused a bug in my Rascal development that took my past two complete days to hunt down. As an experienced industrial programmer, I myself had never experimented such a thing. I could never even think that this might ever happen. However, despite the very hard time I have had with it over two past days, I don't expect Rascal development team to rush on adding support for it ASAP. I'm simply sharing an experience of mine that is relevant to this thread.

I have a piece of code which used to use domainX somewhere. It had come to my notice that this code causes stack overflow due to infinite recursion. After having some debugging, I realised that this is due to the fact that domainX doesn't do what it's supposed to. As a result, the map on which operation runs never shrinks and the computation never ends. I came to know that the reason why this happens is that domainX uses the built-in operator == for exclusion -- which happens not to have the correct semantics for my ADT. Given that Rascal doesn't support user-defined operator overloading, I had to implement my own version of domainX manually. World would have been much nicer if I could simply get this correctness by adding my own operator == overload...

Now, whilst understanding your concerns for not adding this feature, I would like to say that there is a third way too: Rascal can provide another overload of domainX which takes predicates! :)

link delete flag offensive edit

Comments

this is a good point. thanks. The semantics of == is one of the most pivotal in programming, and also in meta programming. Not making it programmable was a design choice, but it is good to think about it again after seeing some use cases.

JurgenVinju (Apr 02)edit

BTW, your post is not an answer to your own question, it should have been a comment with the previous answer.

JurgenVinju (Apr 02)edit
0

answered Dec 22 '11

JurgenVinju gravatar image JurgenVinju flag of Netherlands
554 6 20
http://jurgen.vinju.org/

Not first class. There is some builtin overloading of operators, but thats it. We might provide some user-defined language extension later and we do not want too many sources of ambiguity in the language.

link delete flag offensive edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]
Also see the Rascal Tutor.

Question tools

Follow

subscribe to rss feed

Stats

Asked: Dec 20 '11

Seen: 22 times

Last updated: Mar 07

Related questions