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

Why are comparison operators in Red natives, not actions? #333

Closed
meijeru opened this issue Dec 7, 2012 · 2 comments
Closed

Why are comparison operators in Red natives, not actions? #333

meijeru opened this issue Dec 7, 2012 · 2 comments
Assignees
Labels
status.built A change in codebase has been done to address the ticket. type.review Ticket describes a possible improvement.
Milestone

Comments

@meijeru
Copy link
Contributor

meijeru commented Dec 7, 2012

While attempting to document natives and actions, I was struck by the fact that arithmetic operators (add etc.) are actions, whereas comparison operators (equal? etc.) are natives, which are translated into calls to natives/equal?* etc. Each of these dispatches to a call of natives/compare, which in its turn calls actions/compare which performs the actual comparison by calling on the compare function of the appropriate type. This seems a bit roundabout. Or have I missed a subtlety?

@dockimbel
Copy link
Member

I understand your questioning about that approach. The underlying motivation is trying to keep the number of actions low as they are quite costly (in terms of additional code size for each new action). So, packing all comparison operators into a single action seems like a good move. About consistency with math operations, I agree that they could have been "packed" in the same way, but REBOL does not do that, so they might be some advantage doing so that I have not yet met. I tried to prevent future deep changes, but so far, I do not see any advantages of having separate actions for math operators. I guess we should just wait a bit for R3 sources to be released to check if there is a good reason for having math operators as separate actions and change it in Red accordingly.

However, there is one change that could be done right now for better consistency, the native/compare is in fact playing the role of actions/compare*, so it should be moved to actions (this implementation was preceding the split of actions between Red-stack arguments passing functions (names with * suffix) and native-stack arguments passing functions (names with no suffix).

@dockimbel dockimbel changed the title Coding question: Why are comparison operators in Red natives, not actions? Why are comparison operators in Red natives, not actions? Apr 26, 2014
@dockimbel dockimbel added this to the v0.4.2 milestone Apr 26, 2014
@dockimbel dockimbel self-assigned this Apr 26, 2014
@dockimbel
Copy link
Member

A fix has been done to clean-up a bit the COMPARE action by moving the relevant code from %natives.reds to %actions.reds.

Still, the math operations are kept as separate actions for now, as it is not excluded that for some future datatypes, we might want to implement a subset of the math actions only, and not all of them. That is already the case for the bitwise action AND, OR, XOR which are relying on the same underlying code for integer! and char!. However, for the upcoming binary! datatype, they will be implemented specifically, but the arithmetic operators will be disabled.

OTOH, we need the COMPARE action to be implemented for all datatypes as we need it for SORT and set operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status.built A change in codebase has been done to address the ticket. type.review Ticket describes a possible improvement.
Projects
None yet
Development

No branches or pull requests

2 participants