octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #56881] Command line functions are visible fro


From: anonymous
Subject: [Octave-bug-tracker] [bug #56881] Command line functions are visible from m files
Date: Fri, 13 Sep 2019 00:27:53 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:60.9) Goanna/4.1 PaleMoon/28.2.0a1

Follow-up Comment #3, bug #56881 (project octave):

For the example I created a directory structure as below also attached.
"testpath" has two sub folders "path1" and "path2".
In each of three folders there is a .m file.


\---testpath
    |   test_fcn_0.m
    |
    +---path1
    |       test_fcn_1.m
    |
    \---path2
            test_fcn_2.m
            

"test_fcn_0" calls "test_fcn_1" and then "test_fcn_1" calls "test_fcn_2" and
test_fcn_2 displays "Hello".

test_fcn_0 ==> test_fcn_1 ==> test_fcn_2 ==> disp("Hello")


%test_fcn_0.m
function test_fcn_0
  test_fcn_1
end

%test_fcn_1.m
function test_fcn_1
  test_fcn_2
end

%test_fcn_2.m
function test_fcn_2
  disp("Hello")
end


Using addpath I pushed all three folders on the path then in the command line
I created a function "test_fcn_2" that has the same name as the function that
prints "Hello" but the command line version displays "Evil".


% command line function
function test_fcn_2
  disp("Evil")
end


In the command line  type 

 > test_fcn_0
 
and it shows "Evil". The command line function shadows the function on the
path.

Now I type 

 > clear test_fcn_2
 
It clears the command line function and again running test_fcn_0  it shows
"Hello".

A user usually creates a command line function because it is handy and there
is no need for it to be saved in a file. But I'm in doubt if a user wants to
create a command line function to deliberately shadow other functions on path.
In other words What users should do if they want to use command line functions
but they don't want to shadow other functions ? Possibly they can choose a
distinct function name to prevent name clash but for it they should
remember/list all the function names on the path. I mean the evil shadowing
shouldn't be as simple as creating a command line function. As in the comment
#2 noted there are more difficult ways to do it.
When I create a command line function it can affect all the functions on path
but when I create a .m file in the current directory ( that isn't on the path)
it can affect only those functions that have been saved in the current
directory.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?56881>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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