octave-maintainers
[Top][All Lists]
Advanced

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

Fwd: Function handles for nonexisting functions


From: Judd Storrs
Subject: Fwd: Function handles for nonexisting functions
Date: Wed, 22 Apr 2009 22:28:26 -0400



---------- Forwarded message ----------
From: Judd Storrs <address@hidden>
Date: Wed, Apr 22, 2009 at 10:14 PM
Subject: Re: Function handles for nonexisting functions
To: "John W. Eaton" <address@hidden>
Cc: Moritz Borgmann <address@hidden>, address@hidden


On Wed, Apr 22, 2009 at 8:50 PM, John W. Eaton <address@hidden> wrote:
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

>> cd ..
>> fh ()

ans =

d2/crash

>> cd d1
>> fh ()

ans =

d2/crash


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 ()

ans =

d2/crash

>> cd ..
>> fh ()

ans =

d2/crash

>> cd d2
>> fh ()

ans =

foo
 
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]