Editing Topic: RCR229 Project: RCR | RCRchive home

RCR 229: Mixf-fix syntax, if-then-else etc. as methods, fewer keywords

submitted by itsme213 on Thu Mar 11 2004 02:27:44 PM -0800

Status: rejected


This RCR allows users to define methods with mix-fix syntax (post-fix, pre-fix, in-fix). It allows 2.0 keyword arguments. It uses this to replace some special forms (e.g. if-else) with normal method definitions.


Ruby has mostly postfix (x.y), some infix (x[5]=0), and some prefix (not x). It also has special forms for familiarity (if-then-) where Smalltalk has just methods ifTrue:[...]. In addition to these special cases, the user cannot define their own prefix or infix methods.


Allow users to define mix-fix methods including self and keyword arguments Examples of method definitions:
  1. def at(i)put(v)
  2. def at(i, put:)
  3. def post (p1:, p2:)...
  4. def if (self:, then:)...
  5. def if(self)then(&block)
  6. def prefix (self:)...
  7. def mix (self, post:)...
  8. def mix (self) post (y)
  9. def [ (index) ] = (value)
Allow corresponding mix-fix invocations, parenthesis required only when otherwise ambiguous. Examples below correspond to method definitions above, and use R as receiver
  1. R.at(i) put (5)
  2. R.at(i, put: 5)
  3. R.post (p1:1, p2:2)
  4. if R then: proc
  5. if R then {...}
  6. prefix R
  7. mix R post: y
  8. mix R post y
  9. R [ 5 ] = 0



Two implementations of incremental grammar definition and parsing, both quite doable in Ruby, but I don't know current parser constraints:

Clases (e.g. in modules) can introduce custom mix-fix syntax. Module 'require' chains have corresponding grammar definition incrementally built up. Ruby's current post-fix and pre-defined operators would be "built-in" by virtue of built-in library modules being required first.

The two method defs with "self:" should instead be "self".
Although I admit this is an interesting idea, applying this to Ruby makes it different language. I really want to see a language designed with this idea, to prove (or disprove) this is good. But not in Ruby.

Ruby will stay Ruby, even in Ruby2 era.


Back to RCRchive.

RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog