From: Nicholas Van Weerdenburg Date: 2004-07-18T23:42:04+09:00 Subject: Re: other meanings of ( and ) aka Lispy usage Thanks. The code example is enlightening. Nick James Britt wrote: > Nicholas Van Weerdenburg wrote: > >> What's the meaning of () outside of being function parameter >> delimiters aka in a Lispy sense? >> e.g. >> (puts "command=" + (command="vi " + filename)) > > > Well, they help define evaluation order for expressions. > > Ruby makes few distinctions between statements and expressions. Or, > maybe more precisely, pretty much everything in Ruby is an expression, > and so most things return a value. (I'm tempted to say that > *everything* returns a value, but I'm not positive about that. Can > someone clarify this?) > > Many of the return values are silently discarded, though you'll see them > if you use irb. > > If you tend to chain things together, the parens can help ensure the > execution and evaluation occurs as you intended. > > You can also use them to mimic Lisp syntax, then egg people on in a > thread abut Ruby and functional programming. :) > > > (def cons s1, s2 > "#{s2}#{s1}" end ) > > (def foo x > ( cons( ( x ), ("Foo has ") ) ) end ) > > (def bar y > ( cons( ( y ), ("Bar has ") ) ) end ) > > ( puts( foo( bar( "baz" ) ) ) ) > > > > James > > >