From bug-request at octave dot org Fri Feb 4 06:43:56 2005 Subject: Re: Should be able to say 'for (k=1:N)' From: Paul Kienzle To: Julius Smith Cc: bug at octave dot org Date: Fri, 4 Feb 2005 07:48:28 -0500 This is not a parser inconsistency. "for k = ..." is special syntax in the language. The consistent thing is to consider (k=1:3) to be a value. Whatever you expect from the statement: for 1:3, ... end you should get the same thing from for (k=1:3), ... end The following does look weird, but it is consistent: for k=x=1:3, k, x, end It assigns x to [1,2,3], then lets k cycle over x. - Paul On Feb 2, 2005, at 4:45 PM, Julius Smith wrote: > The octave session below illustrates a small parser inconsistency (see > fourth command line) that tends to bite C programmers. :-) > > > octave > GNU Octave, version 2.1.64 (i686-pc-linux-gnu). > ... > > octave:1> 1:4 > ans = > > 1 2 3 4 > > octave:2> (1:4) > ans = > > 1 2 3 4 > > octave:3> (k=1:4) > k = > > 1 2 3 4 > > octave:4> for (k=1:4), k, end > parse error: > > syntax error > > >>> for (k=1:4), k, end > ^ > > octave:4> for k=1:4, k, end > k = 1 > k = 2 > k = 3 > k = 4 > octave:5> > > > ------------------------------------------------------------- > Octave is freely available under the terms of the GNU GPL. > > Octave's home on the web: http://www.octave.org > How to fund new projects: http://www.octave.org/funding.html > Subscription information: http://www.octave.org/archive.html > ------------------------------------------------------------- > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------