From: "Hal E. Fulton" Date: 2001-01-28T09:16:32+09:00 Subject: [ruby-talk:9990] Re: line continuation ----- Original Message ----- From: Harry Ohlsen To: ruby-talk ML Sent: Saturday, January 27, 2001 4:10 PM Subject: [ruby-talk:9988] Re: line continuation > >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? > > I assume it makes the parsing a little easier, but I do find it a pain > each time I get a syntax error because of this sort of thing and it > takes me a while to realise what the problem is. > Well, for one thing, Ruby has no required statement terminator (semicolon). And remember, a standalone expression is valid in Ruby. Thus a = 2 +3 is actually two statements, isn't it? Hal Fulton