help-octave
[Top][All Lists]
Advanced

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

Re: Function calls (Was: Save a plot to .ps)


From: John W. Eaton
Subject: Re: Function calls (Was: Save a plot to .ps)
Date: Fri, 4 Jun 1999 14:52:37 -0500 (CDT)

On  4-Jun-1999, Daniel Heiserer <address@hidden> wrote:

| address@hidden wrote:
| > 
| > On 28-May-1999, Andy Adler <address@hidden> wrote:
| > 
| > | John, I'm not sure I can follow your reasoning. (I may be missing
| > | something really obvious here). I'm all for octave avoiding
| > | inheriting bugs from matlab compatibility, but if there's a
| > | clean way to do something (which I still think there is ) then
| > | I think it should be considered.
| > 
| > Sorry, I've given this issue considerable thought now, and I don't
| > think there is a clean and consistent way to make it work.
| > 
| > To immitate the Matlab behavior, you have to allow that, in the
| > absence of a variable called `f',
| > 
| >   f -1
| 
| Nononono.
| the way matlab does it is different and (surprised?) makes some sense.
| If the second argument is a variable (1 or any numeric-data is a
| variable)
| than it parses it in the way that it would try to substract.

That is not the result I see.  I tried the following with both Matlab
4.2c and 5.2 and they both behave the same way.  If you see different
results, please show exactly what the new behavior is, and what
version of Matlab you are using.

In all of the following, I'm using the function

  function z = f (x, y)
    fprintf ('nargin = %d\n', nargin);
    if (nargin == 0)
      x = 0;
      y = 0;
    elseif (nargin == 1)
      y = 0;
    end
    z = x + y;

defined in an M-file `f.m'.

If this function is called with no arguments, it does what I expect:

  >> f
  nargin = 0

  ans =

       0

I can also write

  >> f-1
  nargin = 0

  ans =

      -1

and it does what I would expect -- the function is called with no
arguments, returns 0, and one is subtracted from that result.

If I call it like this:

  >> f- 1
  nargin = 0

  ans =

      -1

The result is the same.

But now if I put a space before the operator, Matlab thinks it must be
an option for the function, so it passes `-1' in as a string:

  >> f -1
  nargin = 1

  ans =

      45    49

The returned value is the result of adding 0 to the string '-1',
which, according to Matlab's rules, converts the string to a vector
whose elements are the decimal ASCII equivalents of the corresponding
characters in the string.

If I call it with spaces on both sides of the operator, Matlab
interprets this as a function call with two string arguments, '-' and
'1'.  The returned value is the result of adding the string '-' to the
string '1', which, according to Matlab's rules, converts the strings
to vectors whose elements are the decimal ASCII equivalents of the
corresponding characters in the strings, then adds the vectors.

  >> f - 1
  nargin = 2

  ans =

      94

Unfortunately, Matlab won't allow you to bypass the confusion by
writing

  >> f() - 1
  ??? f()
        |
  Missing variable or function.

| If there is no "-/+/*/\" or other operator he prints out an parsing
| error.

That is not the result I see.  Still using the above function, if I
write

  >> f x y
  nargin = 2

  ans =

     241

Matlab calls the function with two string arguments and adds them,
again producing a numeric result.

| Again I still see it as a feature which is already in octave
| (load/save).

As builtin functions, load and save are special, so Octave knows that
they are supposed to handle string (`text') arguments.  Unfortunately,
this still means that Octave has to be more complex than is really
necessary, so that it can allow you to also use load and save as
variables.

| It just would be nice and useful to have it in a MORE GENERAL way.

I disagree.  I actually think it would be nice if there were NO
functions or commands of this form in Octave.  (They are unnecessary
anyway, since you can always invoke them with `f (args)' syntax.)
Then the language would be more consistent, and I wouldn't be wasting
my time arguing about what a stupid feature this is and what bad side
effects it has.  Then I could get on to doing more useful things.

I am quickly losing interest in the compatibility game.  As I see it,
it is a losing proposition.  Complete compatibility has never been a
goal of mine, and there are more interesting things that I can do with
my time.

If you think Octave should support some stupid Matlab feature in the
name of compatibility, then implement it yourself, or hire someone to
implement it.  If you want absolute compatibility (i.e., Matlab) then
you know where to find it.  If you use Octave only because you think
of it as a `Matlab clone' that you can get `for free', then I think
you are missing the whole point of free software like Octave, so why
should I care what you want?

jwe



---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------



reply via email to

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