This project has moved and is read-only. For the latest updates, please go here.

Evaluation of && and || operators

Jul 26, 2010 at 12:16 PM
Hi, While trying to add && and || as binary operators in my language runtime, I found that InitOperatorImplementations() is overridable, but AddImplementation is private. Is this behaviour by design? If it is, then what's the recommended way of adding custom implementations of operators?
Jul 26, 2010 at 5:04 PM
this is overlook, just change it to protected or public, will fix that. On general note, about && and || operators, I don't think you can use these methods for these operators, they are substantially different. All binary operators implementations imply that both operators are evaluated before the call; while in these case of these operators, we evaluate first only left operator, then operator function decides whether to evaluate the second one or not. So there must be a different approach here, a special node with a special implementation method. I'm planning to add a facility for these shortcut operators in the future Roman
Jul 27, 2010 at 10:16 AM
That's what I did. For my simple needs evaluating as a binary operator is good enough. Thanks for clearing this up. Also, I understand the global picture now. The following is possible with special evaluation but not evaluating as a binary operator: if (variable != null && == value) { printf("evaluation from left to right allows to do checks without evaluating everything"); }