paren-free call expressions

Dmitry A. Soshnikov dmitry.soshnikov at
Wed May 18 08:53:01 PDT 2011


Parens-free call expression allow to provide some actions 
/decoratively/. From this, the consequence of easy and elegant DSLs 
(domain specific languages). For example:

class Account {
     attributes "customer", "cart"

Thus, call to `attribute` function looks like not the imperative call, 
but like a declaration that instances of Account class has those attributes.

Ruby uses exactly this approach of its attr_accessor, private, etc. 
"keywords" which in fact are just functions placed on the very basic class:

class Foo
   attr_accessor :x, :y

foo =

foo.x = 10
foo.y = 20

which in fact is just a syntactic sugar (not at grammar, but at 
application level via simple `attr_accessor` function) for the:

class Foo

   def x

   def x=(value)

   def y

   def y=(value)


That is, create getter and setter for every needed property (yes, in 
Ruby all public properties are accessors). Thus, this function does it 
behind the scene: attr_accessor(:x, :y), however being called /without/ 
parens, it elegantly looks like a declarative keyword. Another example 
as is said, `private` function which also without parens looks like an 

Besides, If -> will be accepted, in many cases (being passed as 
callback) they will much more elegantly look without parens of call 

So what do you think? If the idea is good, may it bring some problems 
with parsers and grammar?

P.S.: some examples of declarative DSLs:


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list