Project

General

Profile

Actions

Feature #7336

closed

Flexiable OPerator Precedence

Added by trans (Thomas Sawyer) over 11 years ago. Updated over 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:49256]

Description

=begin
If Ruby classes could provide some means for redefining operator precedence, it would provide the flexibility useful to some DSL use-cases.

My particular application, for instance, is in an SI units system gem that could use ^ to mean power of the unit (e.g. 1.meter^3 would mean cubic meters). But to do that right the operator needs a higher precedence. I don't expect it to be something commonly used, obviously, but it certain use cases like mine it is practically essential.

I first suggested that (({#^})) be given a higher precedence and XOR get another operator in #6678. I was not surprised that it was rejected, but I figured it was the proper first step, before proposing this much broader feature request.

As for notation, I suppose the simplest means if to create class method that can move the precedence to a position relative to another, e.g.

class Unit
  precedence :^, :**

Which is to say, move (({#^})) operator to a precedence above (({#**})).
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0