From: Nicholas Van Weerdenburg Date: 2004-07-18T23:29:45+09:00 Subject: Re: other meanings of ( and ) aka Lispy usage I think "statement grouping" clears it up for me. I guess in another way, () act as a form of block- you could even think of method parameters as another type of block being passed to a method. {} is syntactic sugar to define a second block being passed as a higher-order function/closure (with the additional parameter passing/yield capability). {|x| do x} --> (lamba (|x| do x)) or something like that. Thanks, Nick Mark Hubbart wrote: > > On Jul 17, 2004, at 8:45 PM, 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)) >> >> Obvious + is actual a method, so that explains the () around >> "command=", but there is the () around the entire line. > > > First, there is the expression grouping. That is what lets you say (23 > + 42) * 69, or (Math.sqrt 23) + 42, or even ("this" + "that").display > > Then, function parameter delimeters. These are, of course, mostly > optional in ruby. STDERR.puts("Yoiks!", "Stop that!") > > Parens can also act as statement groupings. Multiple statements can be > collected into one expression, where the value of the expression -- > everything inside the parens -- is given the value of the last > statement. So, you can do things like this (warning! very contrived): > > baz = ((foo=23; bar=foo+7; bar*foo) if condition) > > In this, if condition is true, foo is set to 23, bar is set to 30, and > the parenthetical expression returns a value of 23*30. baz will be set > to 690. If condition is false, nothing else is evaluated, and baz is > set to nil. > > I hope the last part wasn't more confusing than helpful... :/ > > HTH, > Mark > >