size(foo), `foo' not being a matrix

View: New views
12 Messages — Rating Filter:   Alert me  

size(foo), `foo' not being a matrix

by G.. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Let foo.m be the simple function file

###  foo.m
disp("What's this?")
###

If foo is not a matrix, issuing size(foo) in the directory of foo.m gives

------------
octave:1> size(foo)
What's this?
ans =

  -1  -1
octave:2>
------------

The same applies to other functions such as numel. I don't think that's meaningful.

G.

_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by David Bateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

GAIL wrote:

> Let foo.m be the simple function file
>
> ###  foo.m
> disp("What's this?")
> ###
>
> If foo is not a matrix, issuing size(foo) in the directory of foo.m gives
>
> ------------
> octave:1> size(foo)
> What's this?
> ans =
>
>   -1  -1
> octave:2>
> ------------
>
> The same applies to other functions such as numel. I don't think that's meaningful.
>
> G.
>
> _______________________________________________
> Bug-octave mailing list
> Bug-octave@...
> https://www.cae.wisc.edu/mailman/listinfo/bug-octave
>
>  
Matlab gives an error for this case. If foo is a function it gives

>> size(foo)
??? Error using ==> foo
Too many output arguments.


If foo is a script it gives

>> size(foo)
??? Attempt to execute SCRIPT foo as a function:
/home/adb014/foo.m

So yes I suppose this should give an error...

D.

--
David Bateman                                David.Bateman@...
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax)

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary

_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 17-Sep-2007, David Bateman wrote:

| GAIL wrote:
| > Let foo.m be the simple function file
| >
| > ###  foo.m
| > disp("What's this?")
| > ###
| >
| > If foo is not a matrix, issuing size(foo) in the directory of foo.m gives
| >
| > ------------
| > octave:1> size(foo)
| > What's this?
| > ans =
| >
| >   -1  -1
| > octave:2>
| > ------------
| >
| > The same applies to other functions such as numel. I don't think that's meaningful.
| >
| > G.
| >
| > _______________________________________________
| > Bug-octave mailing list
| > Bug-octave@...
| > https://www.cae.wisc.edu/mailman/listinfo/bug-octave
| >
| >  
| Matlab gives an error for this case. If foo is a function it gives
|
| >> size(foo)
| ??? Error using ==> foo
| Too many output arguments.
|
|
| If foo is a script it gives
|
| >> size(foo)
| ??? Attempt to execute SCRIPT foo as a function:
| /home/adb014/foo.m
|
| So yes I suppose this should give an error...

I agree, but I see no good way to do it at the moment.  Fixing this
will have to wait until after 3.0.

jwe
_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by G.. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John W. Eaton wrote:
| >> size(foo)
| ??? Attempt to execute SCRIPT foo as a function:
| /home/adb014/foo.m
|
| So yes I suppose this should give an error...

I agree, but I see no good way to do it at the moment.  Fixing this
will have to wait until after 3.0.
so is there any progress/plans? This 'feature' is really annoying as it uncontrollably starts to fire scripts from my octave path. I usually tend to create cases such as w=foo.xyz with a nonexistent structure foo. But then octave secretly launches the command 'foo', creating all sorts of damage. Isn't it easy to check from the start if foo is a structure in that case?

G.

Re: size(foo), `foo' not being a matrix

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 12-Mar-2008, G.. wrote:

|
|
| John W. Eaton wrote:
| >
| > | >> size(foo)
| > | ??? Attempt to execute SCRIPT foo as a function:
| > | /home/adb014/foo.m
| > |
| > | So yes I suppose this should give an error...
| >
| > I agree, but I see no good way to do it at the moment.  Fixing this
| > will have to wait until after 3.0.
| >
|
| so is there any progress/plans? This 'feature' is really annoying as it
| uncontrollably starts to fire scripts from my octave path. I usually tend to
| create cases such as w=foo.xyz with a nonexistent structure foo. But then
| octave secretly launches the command 'foo', creating all sorts of damage.

What kind of damage?

| Isn't it easy to check from the start if foo is a structure in that case?

Short answer: No.

In Octave, you can call a function with just the name (using an
empty argument list '()' is not required) and you can index the result
returned by a function without using a temporary variable.  And at
present, Octave does not check to see whether an symbol like "foo"
above refers to a function or script until it is evaluating the
script, and there is not simple way to perform that check at the point
where you are apparently thinking it should be done.

I think the fix for this is to parse script files completely and store
them in Octave's internal parse tree representation before evaluating
them.  Then I think it would be simple to detect the case of a script
called as a function and produce an error message.

jwe
_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by G.. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 03/12/2008 04:35 PM, John W. Eaton wrote:
> | so is there any progress/plans? This 'feature' is really annoying as it
> | uncontrollably starts to fire scripts from my octave path. I usually tend to
> | create cases such as w=foo.xyz with a nonexistent structure foo. But then
> | octave secretly launches the command 'foo', creating all sorts of damage.
>
> What kind of damage?

for example, if 'foo.m' cleans your harddisk.

G.

_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 12-Mar-2008, GAIL wrote:

| On 03/12/2008 04:35 PM, John W. Eaton wrote:
| > | so is there any progress/plans? This 'feature' is really annoying as it
| > | uncontrollably starts to fire scripts from my octave path. I usually tend to
| > | create cases such as w=foo.xyz with a nonexistent structure foo. But then
| > | octave secretly launches the command 'foo', creating all sorts of damage.
| >
| > What kind of damage?
|
| for example, if 'foo.m' cleans your harddisk.

How would it do that?

I don't think you can blame Octave for something like that.

jwe
_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by G.. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 03/12/2008 05:43 PM, John W. Eaton wrote:
> | > What kind of damage?
> |
> | for example, if 'foo.m' cleans your harddisk.
>
> How would it do that?
>
> I don't think you can blame Octave for something like that.

of course not, it's all my fault. For example, I use octave to run day-long jobs, but now 'foo' might overwrite what I calculated yesterday, and gone is it.

But a more serious issue I think is that in a complex computing environment, which almost certainly contains buggy scripts, uncontrollable behavior of this kind virtually acts like a virus, as there is no control anymore which scripts were run at what time.

G.
_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 12-Mar-2008, GAIL wrote:

| But a more serious issue I think is that in a complex computing
| environment, which almost certainly contains buggy scripts,
| uncontrollable behavior of this kind virtually acts like a virus, as
| there is no control anymore which scripts were run at what time.

I don't understand what you are complaining about.

Fixing this minor issue with scripts vs. functions would not make the
situation much different for you if you write code that can easily
cause trouble.  So it would prevent a script from running in some
circumstances.  It would not at all prevent the execution of functions
which could perform all the same actions as the scripts in those same
cases.  And it would not prevent accidental execution of arbitrary
scripts in other cases.

jwe
_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by G.. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 03/12/2008 06:42 PM, John W. Eaton wrote:
> On 12-Mar-2008, GAIL wrote:
> Fixing this minor issue with scripts vs. functions would not make the
> situation much different for you if you write code that can easily
> cause trouble.  So it would prevent a script from running in some
> circumstances.  It would not at all prevent the execution of functions
> which could perform all the same actions as the scripts in those same
> cases.  And it would not prevent accidental execution of arbitrary
> scripts in other cases.

What about, e.g., the 'pause' function? In matlab I get

>> w = pause.xyz
??? The function, script, or class pause
cannot be indexed using {} or . indexing.

and in octave

octave:1> w = pause.xyz

... actually pausing, which is not what I want.


G.
_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 12-Mar-2008, GAIL wrote:

| What about, e.g., the 'pause' function? In matlab I get
|
| >> w = pause.xyz
| ??? The function, script, or class pause
| cannot be indexed using {} or . indexing.

Don't you get this error in Matlab if you try to index the value
returned from any function, even one that returns a structure?
For example, try defining a function like this:

  function s = f ()
    s.a = 1;
  end

and then

  f.a

in Matlab and Octave.  In Octave, it is equivalent to

  tmp = f;
  tmp.a

and some people seem to like this feature.

| and in octave
|
| octave:1> w = pause.xyz
|
| ... actually pausing, which is not what I want.

And what would you want if you typed that command?

I don't see a way to avoid calling the function and still preserving
the ability to index the value returned from function without
requiring that it first be assigned to a temporary variable, and while
also not requiring "()" when calling functions with not arguments.

I'm open to changing this behavior, but not before first finding out
what other users want.

In any case, if we do change Octave's behavior to be more like matlab
in these cases, the changes won't stop you from finding other ways to
shoot yourself in the foot.

jwe
_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

Re: size(foo), `foo' not being a matrix

by G.. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 03/13/2008 02:29 AM, John W. Eaton wrote:
> | and in octave
> |
> | octave:1> w = pause.xyz
> |
> | ... actually pausing, which is not what I want.
>
> And what would you want if you typed that command?

I'd like to see an error message.

> I don't see a way to avoid calling the function and still preserving
> the ability to index the value returned from function without
> requiring that it first be assigned to a temporary variable, and while
> also not requiring "()" when calling functions with not arguments.

I find it more safe to disallow, as in matlab, function indexing, or at least to require "()" for function calls. Otherwise objects like 'foo.a' are simply ambiguous, and that should be avoided, no?

G.

_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave