Matlab incompatibility: cd and which

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Matlab incompatibility: cd and which

Michael Goffioul
I noticed these 2 incompatibilities:

1) "which ... -all" is supposed to return a cell array of string, but does not.

2) "cd" without argument changes to home dir, while in Matlab it simply returns the current directory.

Are those things considered as should-be-fixed and logged as bugs?

Michael.

Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

Markus
Am 2013-10-14 03:31, schrieb Michael Goffioul:
> I noticed these 2 incompatibilities:
>
> 1) "which ... -all" is supposed to return a cell array of string, but
> does not.
>
> 2) "cd" without argument changes to home dir, while in Matlab it
> simply returns the current directory.

I've noticed this a long time ago too. But because this is obviously a
bug in Matlab (in this case "cd" has the same functionality as "pwd".
ChangeDir should change the directory and don't name the location where
you are), i won't care about it.


>> cd /tmp
>> pwd

ans =

/tmp

>> cd

/tmp

>> s=pwd

s =

/tmp

>> s=cd

s =

/tmp

>> cd ~ % imho, this can/should be used if you want to write compatible
>> code for matlab and octave
>> pwd

ans =

/home/markus


cheers
markus
Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

c.-2
In reply to this post by Michael Goffioul

On 14 Oct 2013, at 03:31, Michael Goffioul <[hidden email]> wrote:

> 2) "cd" without argument changes to home dir, while in Matlab it simply returns the current directory.

this has been discussed before, it was decided to follow the more consistent
bash behaviour of cd rather than the strange behaviour chosen by Matlab.

c.
Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

Michael Goffioul
On Mon, Oct 14, 2013 at 3:16 AM, c. <[hidden email]> wrote:

On 14 Oct 2013, at 03:31, Michael Goffioul <[hidden email]> wrote:

> 2) "cd" without argument changes to home dir, while in Matlab it simply returns the current directory.

this has been discussed before, it was decided to follow the more consistent
bash behaviour of cd rather than the strange behaviour chosen by Matlab.

I figured this must have been discussed before, I just didn't remember it. I just happened to bump into a toolbox that uses of handful of "cd()" to retrieve the current directory, leading to unexpected behavior on octave.

Note that the "cd()" behavior in Matlab is consistent with the CD command in a windows command prompt. I suppose it's where this inconsistent-under-unix behavior is coming from.

Michael.

Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

c.-2

On 14 Oct 2013, at 13:51, Michael Goffioul <[hidden email]> wrote:

> Note that the "cd()" behavior in Matlab is consistent with the CD command in a windows command prompt. I suppose it's where this inconsistent-under-unix behavior is coming from.
oh I, see ... I was not aware of this behaviour of cd in windows, it definitely justifies the choice made by TMW, I sucpect Octave development is more *NIX centered, though,
so the current behaviour will still be favoured.

c.
Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

John W. Eaton
Administrator
In reply to this post by Michael Goffioul
On 10/14/2013 07:51 AM, Michael Goffioul wrote:

> On Mon, Oct 14, 2013 at 3:16 AM, c. <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>     On 14 Oct 2013, at 03:31, Michael Goffioul
>     <[hidden email] <mailto:[hidden email]>> wrote:
>
>      > 2) "cd" without argument changes to home dir, while in Matlab it
>     simply returns the current directory.
>
>     this has been discussed before, it was decided to follow the more
>     consistent
>     bash behaviour of cd rather than the strange behaviour chosen by Matlab.
>
>
> I figured this must have been discussed before, I just didn't remember
> it. I just happened to bump into a toolbox that uses of handful of
> "cd()" to retrieve the current directory, leading to unexpected behavior
> on octave.

Is it doing

   x = cd

?  In that case, Octave should be returning the current directory and
not changing it.

If it is not doing that, then what do you mean by "retrieve"?  It's just
doing

   cd

to display the current directory?

jwe

Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

Michael Goffioul
On Mon, Oct 14, 2013 at 11:15 AM, John W. Eaton <[hidden email]> wrote:
On 10/14/2013 07:51 AM, Michael Goffioul wrote:
On Mon, Oct 14, 2013 at 3:16 AM, c. <[hidden email]
<mailto:[hidden email]>> wrote:


    On 14 Oct 2013, at 03:31, Michael Goffioul
    <[hidden email] <mailto:[hidden email]>> wrote:

     > 2) "cd" without argument changes to home dir, while in Matlab it
    simply returns the current directory.

    this has been discussed before, it was decided to follow the more
    consistent
    bash behaviour of cd rather than the strange behaviour chosen by Matlab.


I figured this must have been discussed before, I just didn't remember
it. I just happened to bump into a toolbox that uses of handful of
"cd()" to retrieve the current directory, leading to unexpected behavior
on octave.

Is it doing

  x = cd

?  In that case, Octave should be returning the current directory and not changing it.

It's doing exactly that, and octave changes the current directory to $HOME.

Michael.

Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

PhilipNienhuis
In reply to this post by Michael Goffioul
Michael Goffioul wrote
<snip>

2) "cd" without argument changes to home dir, while in Matlab it simply
returns the current directory.
Also on Linux-based Matlab? or only on Windows? (could be OS-dependent)
I can't test now, my ML prerelease has expired a few weeks ago.

What does ML do on Mac OSX?

Philip
Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

John W. Eaton
Administrator
On 10/14/2013 03:36 PM, PhilipNienhuis wrote:
> Michael Goffioul wrote
>> <snip>
>> 2) "cd" without argument changes to home dir, while in Matlab it simply
>> returns the current directory.
>
> Also on Linux-based Matlab? or only on Windows? (could be OS-dependent)
> I can't test now, my ML prerelease has expired a few weeks ago.
>
> What does ML do on Mac OSX?

I don't think the behavior is dependent on the OS.  There is certainly
no mention of that in the Matlab docs.

jwe

Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

bpabbott
Administrator
In reply to this post by PhilipNienhuis

On Oct 14, 2013, at 3:36 PM, PhilipNienhuis wrote:

> Michael Goffioul wrote
>> <snip>
>> 2) "cd" without argument changes to home dir, while in Matlab it simply
>> returns the current directory.
>
> Also on Linux-based Matlab? or only on Windows? (could be OS-dependent)
> I can't test now, my ML prerelease has expired a few weeks ago.
>
> What does ML do on Mac OSX?
>
> Philip

Matlab R2013a on MacOSX

cd

/Users/bpabbott/Dropbox/pm B26/RX/duty_sensitivity

pwd

ans =

/Users/bpabbott/Dropbox/pm B26/RX/duty_sensitivity

Ben

Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

PhilipNienhuis
In reply to this post by John W. Eaton
John W. Eaton wrote
On 10/14/2013 03:36 PM, PhilipNienhuis wrote:
> Michael Goffioul wrote
>> <snip>
>> 2) "cd" without argument changes to home dir, while in Matlab it simply
>> returns the current directory.
>
> Also on Linux-based Matlab? or only on Windows? (could be OS-dependent)
> I can't test now, my ML prerelease has expired a few weeks ago.
>
> What does ML do on Mac OSX?

I don't think the behavior is dependent on the OS.  There is certainly
no mention of that in the Matlab docs.
Hmm... there's more mention of Matlab behavior missing in their docs :-)

But I agree the on-line ML doc for "cd" is quite unambiguous.

And at least the effect of "cd" is consistent between Windows and Mac OSX.

Perhaps it can be made configurable; but I can't imagine that to be a high priorty.

Philip
Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

John W. Eaton
Administrator
On 10/14/2013 04:03 PM, PhilipNienhuis wrote:

> John W. Eaton wrote
>> On 10/14/2013 03:36 PM, PhilipNienhuis wrote:
>>> Michael Goffioul wrote
>>>>
>> <snip>
>>>> 2) "cd" without argument changes to home dir, while in Matlab it simply
>>>> returns the current directory.
>>>
>>> Also on Linux-based Matlab? or only on Windows? (could be OS-dependent)
>>> I can't test now, my ML prerelease has expired a few weeks ago.
>>>
>>> What does ML do on Mac OSX?
>>
>> I don't think the behavior is dependent on the OS.  There is certainly
>> no mention of that in the Matlab docs.
>
> Hmm... there's more mention of Matlab behavior missing in their docs :-)
>
> But I agree the on-line ML doc for "cd" is quite unambiguous.

Sure, and the behavior of cd in Unixy shells  is also quite well
established.

> And at least the effect of "cd" is consistent between Windows and Mac OSX.
>
> Perhaps it can be made configurable; but I can't imagine that to be a high
> priorty.

No, having a configuation option for things like this is a bad idea.
We had a lot of those things in the early days of Octave and they were
a disaster.  We worked really hard to remove them.  The problem with
configuration options for features like this is that they make it
difficult to write code that works no matter what the user preference
settings happen to be.  You end up having to know all about the
various user preferences and write things like this:

   unwind_protect
     ostate = lone_cd_is_pwd (false);
     ...
     cd;
     ...
   unwind_protect_cleanup
     lone_cd_is_pwd (ostate);
   end_unwind_protect

Yes, I agree that this is a silly case and there are other ways to
write this code so that it will always work (use pwd if that's what
you want, or cd ~ if that's what you want) but the general principle
is the same: global configuration variables that change the behavior
of functions cause more trouble than they are worth.

If people really think that Matlab compatibility at this level is
paramount, then I'd say we should change Octave's bahavior to match.
But we will probably also break a some Octave code that expects "cd"
to change to the user's home directory.  We can't have it both ways.

jwe
Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

Mike Miller
On Mon, Oct 14, 2013 at 16:26:10 -0400, John W. Eaton wrote:

> On 10/14/2013 04:03 PM, PhilipNienhuis wrote:
>>
>> John W. Eaton wrote
>>>
>>> On 10/14/2013 03:36 PM, PhilipNienhuis wrote:
>>>>
>>>> Michael Goffioul wrote
>>>>>
>>>>>
>>> <snip>
>>>>>
>>>>> 2) "cd" without argument changes to home dir, while in Matlab it simply
>>>>> returns the current directory.
>>>>
>>>>
>>>> Also on Linux-based Matlab? or only on Windows? (could be OS-dependent)
>>>> I can't test now, my ML prerelease has expired a few weeks ago.
>>>>
>>>> What does ML do on Mac OSX?
>>>
>>>
>>> I don't think the behavior is dependent on the OS.  There is certainly
>>> no mention of that in the Matlab docs.
>>
>>
>> Hmm... there's more mention of Matlab behavior missing in their docs :-)
>>
>> But I agree the on-line ML doc for "cd" is quite unambiguous.
>
>
> Sure, and the behavior of cd in Unixy shells  is also quite well
> established.

And "help cd" in Octave is pretty upfront about the incompatibility as well.

> [...]
>
> If people really think that Matlab compatibility at this level is
> paramount, then I'd say we should change Octave's bahavior to match.
> But we will probably also break a some Octave code that expects "cd"
> to change to the user's home directory.  We can't have it both ways.

And both behaviors have perfectly acceptible alternate ways to achieve
the same thing much less ambiguously.

I like having the Octave shell behave just like I'm used to in bash,
but I would be ok with changing to be more compatible, and training
myself to do "cd ~" instead.

--
mike
Reply | Threaded
Open this post in threaded view
|

Re: Matlab incompatibility: cd and which

PhilipNienhuis
In reply to this post by John W. Eaton
John W. Eaton wrote:

> On 10/14/2013 04:03 PM, PhilipNienhuis wrote:
>> John W. Eaton wrote
>>> On 10/14/2013 03:36 PM, PhilipNienhuis wrote:
>>>> Michael Goffioul wrote
>>>>>
>>> <snip>
>>>>> 2) "cd" without argument changes to home dir, while in Matlab it
>>>>> simply
>>>>> returns the current directory.
>>>>
>>>> Also on Linux-based Matlab? or only on Windows? (could be OS-dependent)
>>>> I can't test now, my ML prerelease has expired a few weeks ago.
>>>>
>>>> What does ML do on Mac OSX?
>>>
>>> I don't think the behavior is dependent on the OS. There is certainly
>>> no mention of that in the Matlab docs.
>>
>> Hmm... there's more mention of Matlab behavior missing in their docs :-)
>>
>> But I agree the on-line ML doc for "cd" is quite unambiguous.
>
> Sure, and the behavior of cd in Unixy shells is also quite well
> established.
>
>> And at least the effect of "cd" is consistent between Windows and Mac
>> OSX.
>>
>> Perhaps it can be made configurable; but I can't imagine that to be a
>> high
>> priorty.
>
> No, having a configuation option for things like this is a bad idea.
> We had a lot of those things in the early days of Octave and they were
> a disaster. We worked really hard to remove them. The problem with
> configuration options for features like this is that they make it
> difficult to write code that works no matter what the user preference
> settings happen to be. You end up having to know all about the
> various user preferences and write things like this:
>
> unwind_protect
> ostate = lone_cd_is_pwd (false);
> ...
> cd;
> ...
> unwind_protect_cleanup
> lone_cd_is_pwd (ostate);
> end_unwind_protect
>
> Yes, I agree that this is a silly case and there are other ways to
> write this code so that it will always work (use pwd if that's what
> you want, or cd ~ if that's what you want) but the general principle
> is the same: global configuration variables that change the behavior
> of functions cause more trouble than they are worth.
>
> If people really think that Matlab compatibility at this level is
> paramount, then I'd say we should change Octave's bahavior to match.
> But we will probably also break a some Octave code that expects "cd"
> to change to the user's home directory. We can't have it both ways.

Just to make myself clear (I think I wasn't):
I have no preference as to what a lone "cd" should do, I never use it.
I use "pwd" if I want to know where I am. "cd <somewhere>" is for going
somewhere else. If I need to be in my profile I'd use "cd ~/some/where".
So I'm quite OK with current Octave behavior.

Philip