From bug-octave-request at bevo dot che dot wisc dot edu Tue Dec 3 11:43:39 2002 Subject: Re: return, continue, break -> ans = 1 From: Etienne Grossmann To: "John W. Eaton" Cc: Miroslaw Kwasniak , bug-octave@bevo.che.wisc.edu, Etienne Grossmann , Pascal.Dupuis@esat.kuleuven.ac.be, octave-maintainers mailing list , Etienne Grossmann Date: Tue, 3 Dec 2002 17:55:02 +0000 Hello, On Tue, Dec 03, 2002 at 11:36:52AM -0600, John W. Eaton wrote: # On 29-Nov-2002, Miroslaw Kwasniak wrote: # # | To: bug-octave at bevo dot che dot wisc dot edu # | Cc: mirek # | Subject: return, continue, break -> ans = 1 # | # | Bug report for Octave 2.1.40 configured for i386-pc-linux-gnu # | # | Description: # | ----------- # | # | Hi, # | # | Control statements: return, continue, break # | # | If they are last statements in a line (not followed by semicolon) # | octave displays: ans = 1 # # This is happening because of some changes I made in response to # http://www.octave.org/mailing-lists/bug-octave/2002/154. The idea was # to make Octave's break, continue, and return statements behave more # like they do in Perl. For example, make # # some_expression || break; # # work as it would in Perl. To implement this within the current # parser/interpreter, break must be an expression that returns a value. # But as people have pointed out, that causes a few other surprises for # existing Octave code. # # My changes were simple. They just made break, continue, and return do # what did before, but also behave as functions that returned 1 so they # would be valid in logical contexts. But a simple change is not good # enough, and I don't see a way to allow the Perl-like behavior and also # be backward compatible without making some major changes to the way # Octave's parser and interpreter work. I don't think it is worth the # effort and I've undone the changes I made earlier. The CVS archive # should be updated within a few minutes. I only sent the report because I was unaware of the change and thought it may be the result of some underlying problem. I only noticed that when some of my functions started printing '1' (the value of break) wherever I use it w/out a ';' after it. Otherwise, the perlier, the better. Biased, me? Cheers, Etienne -- Etienne Grossmann ------ http://www.isr.ist.utl.pt/~etienne ------------------------------------------------------------- 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 -------------------------------------------------------------