octave-3.0.3 accepts 'function' without 'endfucntion' (or with redundant 'endfunction')

David Grundberg individ at acc.umu.se
Fri Jul 10 16:15:00 CDT 2009


bug-octave-request at octave.org skrev:
> Message: 2
> Date: Fri, 10 Jul 2009 08:42:20 -0700 (PDT)
> From: Sergei Steshenko <sergstesh at yahoo.com>
>
>
> Hello,
>
> lately I've been dealing a lot with optim-1.0.4/leasqr.m.
>
> Looking into its source I came to the conclusion that 'endfunction' (or the
> corresponding 'end') is missing. To be honest, I didn't check it very
> thoroughly.
>
> Still, I simply added 'endfunction' and recompiled (even quitting/restarting 'octave') - the compilation went smooth (no warnings)
> and the function works as before.
>
> Now, if the function indeed has missing 'endfunction'/'end', then my 
> addition of it indicates that 'octave' parser accepts it, which I think it shouldn't.
>
> If 'end' is not missing, then 'octave' parser accepts redundant
> 'endfunction', which I think it shouldn't either.
>
> Please note 'leasqr.m' is written in a strange'ish manner - lot of 
> semicolons and colons I wouldn't put.
>
> Thanks,
>   Sergei.
>   
Well,

  function myFunction()
  #body

is a correct declaration of a function inside the file myFunction.m. It 
is accepted (not without warnings, I think) in Matlab, and Octave allows it.

Other declarations are

  function myFunction()
  #body
  end

and

  function myFunction()
  #body
  endfunction

where the former in both Matlab and Octave while the latter only works 
in Octave.

The declaration you are talking about

function myFunction()
#body
end
endfunction

with unbalanced ends, is not correct.

David


More information about the Bug-octave mailing list