octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function files (was: why is octave such a crap?)


From: Mike Miller
Subject: Re: function files (was: why is octave such a crap?)
Date: Wed, 17 Aug 2016 11:25:33 -0700
User-agent: Mutt/1.6.2-neo (2016-07-23)

On Wed, Aug 17, 2016 at 14:10:42 -0400, Nicholas Jankowski wrote:
> On Wed, Aug 17, 2016 at 2:06 PM, Nicholas Jankowski <address@hidden>
> wrote:
> 
> > On Wed, Aug 17, 2016 at 2:01 PM, PhilipNienhuis <address@hidden>
> > wrote:
> >
> >> Mike Miller-4 wrote
> >> > On Wed, Aug 17, 2016 at 14:50:30 +0000, Frank Zack wrote:
> >>
> >> Matlab r2016b prerelease (the version I have at hand here) does accept
> >> function names that are different than the .m file name.
> >> Matlab informs the user of this at file saving time rather than error'ing
> >> out at execution time.
> >>
> >
> > last I checked, Octave did the same thing.  Notice that the function name
> > message is a warning, not an error. I've renamed functions and forgotten to
> > change the filename, and it just pops up a warning. I'm not actually sure
> > why it errors on the x definition here, unless that behavior is new.
> >
> 
> running 4.0.3 on Windows. Sure enough I just took one of my function files
> and renamed the function without changing the filename.  got the same
> warning, then it gave me the correct output without error.  So I think
> we're okay there.

So to be clear, you are calling the name of the file as if it were the
function name, and it works, right? For example if I have myfunc.m with

  function y = squared (x)
    y = x.*x;
  endfunction

You can call myfunc(2) and get back 4, but you cannot call squared(2)
because Octave has no way of knowing where that function is defined if
it's not the same as the file name.

The original post showed an attempt to call a function where the name
matched the function declaration in the file, but *not* the name of the
file. This should have thrown a simple "'foo' undefined" error.

I suspect that what the OP actually did was call "test" without any
arguments, as if it were a script file, not a function file. If I do any
of the following with myfunc, I get the same error as the OP:

  >> myfunc
  error: 'x' undefined near line 2 column 7
  error: called from
      myfunc at line 2 column 5
  >> run myfunc
  'x' undefined near line 2 column 7
  error: called from
      run at line 86 column 5
  >> source myfunc.m
  error: 'x' undefined near line 2 column 7
  error: called from
      myfunc at line 2 column 5

I think the confusion point for the OP was the difference between a
script file and a function file.

-- 
mike



reply via email to

[Prev in Thread] Current Thread [Next in Thread]