From: David Alan Black Date: 2001-01-28T09:29:20+09:00 Subject: [ruby-talk:9993] Re: line continuation On Sun, 28 Jan 2001, Harry Ohlsen wrote: > >A statement break into mutliple lines if it is not complete, > >i.e. "if the last token on a line is an operator or comma". > >But you can also use \ as the last character on the line, to > >continue on the next line. > > > >a = 2 + > > 3 > >is equivalent to a=2+3 > > > >a = 2 \ > > + 3 > > > >here you need the \ at the end of the line. > > While it's nice that you can do this, can someone explain why it is > that the Ruby parser can't work out that a statement is not finished, > as, say, a C++ or Java parser can? Because the code layout is, in many cases, the *only* information about how the code should parse. This is the price we pay for not having to type semicolons. Think of it this way: if we wrote sentences without periods (and without starting with a capital letter :-), we'd probably need to put a blank line between every two sentences in order to parse them correctly. (Blank line for us being the equivalent, in this analogy, of newline for Ruby.) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav