octave-maintainers
[Top][All Lists]
Advanced

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

Re: Function handles for nonexisting functions


From: Judd Storrs
Subject: Re: Function handles for nonexisting functions
Date: Wed, 22 Apr 2009 21:46:41 -0400

On Wed, Apr 22, 2009 at 8:50 PM, John W. Eaton <address@hidden> wrote:
Will you please try the following with Matlab and tell me what
happens?

Create directories d1 and d2.  Put the following fucntion in
d1/crash.m:

 function crash ()
   'd1/crash'

and put the following function in d2/crash.m:

 function crash ()
   'd2/crash'

Now start Matlab in the directory that contains d1 and d2, and run the
following commands:

 fh = @crash
 fh ()
 cd d1
 fh ()
 cd ../d2
 fh ()

>>  fh = @crash

fh =

    @crash

>>  fh ()
??? Undefined function or variable 'crash'.

>>  cd d1
>>  fh ()

ans =

d1/crash

>>  cd ../d2
>>  fh ()

ans =

d2/crash
 
 clear all
 fh = @crash ()
 cd ..
 fh ()
 cd d1
 fh ()

>>  clear all
>>  fh = @crash ()
???  fh = @crash ()
                 |
Error: Unbalanced or unexpected parenthesis or bracket.

>>  cd ..
>>  fh ()
??? Undefined function or variable 'fh'.

>>  cd d1
>>  fh ()
??? Undefined function or variable 'fh'.

Now, while Matlab is still running, change the definition of
d2/crash.m to be

 function crash ()
   'foo'

and then continue your Matlab session with the following commands:

 fh ()
 cd ..
 fh ()
 cd d2
 fh ()

>>  fh ()
??? Undefined function or variable 'fh'.

>>  cd ..
>>  fh ()
??? Undefined function or variable 'fh'.

>>  cd d2
>>  fh ()
??? Undefined function or variable 'fh'.

 clear all
 addpath (pwd)
 cd ..
 fh = @crash
 fh ()

>> clear all
>> addpath(pwd)
>> cd ..
>> fh = @crash

fh =

    @crash

>> fh ()

ans =

foo
 
Now, while Matlab is still running, change the definition of
d2/crash.m to be

 function crash ()
   'bar'

and then continue your Matlab session with the following commands:

 fh ()
 cd d1
 fh ()
 cd ../d2
 fh ()

>> fh ()

ans =

bar

>> cd d1
>> fh ()

ans =

bar

>> cd ../d2
>> fh ()

ans =

bar



reply via email to

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