same function name in two files

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

same function name in two files

kamaraju
Let's say I have two scripts (fileA.m, fileB.m) with the following set of functions.

fileA.m
foo()
funcA1()
funcA2()

fileB.m
foo()
funcB1()
funcB2()

The implementation of foo() in both files is completely different. I have no write permissions to edit fileA.m, fileB.m

A third script (fileC.m) uses all the six functions. I want to call both foo() implementations at different points in the code. Is there any way to achieve that? For example, is there anything like fileA.foo() , fileB.foo() to distinguish between the two?

thanks
raju
--
Kamaraju S Kusumanchi
http://malayamaarutham.blogspot.com/

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: same function name in two files

bpabbott
Administrator

On Jun 15, 2014, at 8:06 PM, kamaraju kusumanchi <[hidden email]> wrote:

> Let's say I have two scripts (fileA.m, fileB.m) with the following set of functions.
>
> fileA.m
> foo()
> funcA1()
> funcA2()
>
> fileB.m
> foo()
> funcB1()
> funcB2()
>
> The implementation of foo() in both files is completely different. I have no write permissions to edit fileA.m, fileB.m
>
> A third script (fileC.m) uses all the six functions. I want to call both foo() implementations at different points in the code. Is there any way to achieve that? For example, is there anything like fileA.foo() , fileB.foo() to distinguish between the two?
>

I assume fileA.m and fileB.m are scripts and not functions?

Then, first run fileA and when you use foo() it corresponds to the implementation in fileA.

        fileA
        foo

To use the version if fileB, first fun fileB

        fileA
        foo

Ben

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: same function name in two files

kamaraju

On Sun, Jun 15, 2014 at 8:27 PM, Ben Abbott <[hidden email]> wrote:

On Jun 15, 2014, at 8:06 PM, kamaraju kusumanchi <[hidden email]> wrote:

> Let's say I have two scripts (fileA.m, fileB.m) with the following set of functions.
>
> fileA.m
> foo()
> funcA1()
> funcA2()
>
> fileB.m
> foo()
> funcB1()
> funcB2()
>
> The implementation of foo() in both files is completely different. I have no write permissions to edit fileA.m, fileB.m
>
> A third script (fileC.m) uses all the six functions. I want to call both foo() implementations at different points in the code. Is there any way to achieve that? For example, is there anything like fileA.foo() , fileB.foo() to distinguish between the two?
>

I assume fileA.m and fileB.m are scripts and not functions?
 
Yes, all three of them fileA.m, fileB.m and fileC.m are scripts and not functions. 
 

Then, first run fileA and when you use foo() it corresponds to the implementation in fileA.

        fileA
        foo

To use the version if fileB, first fun fileB

        fileA
        foo


IMHO, this is really error prone way of doing it. Since every time you write code, you have to look back, keep track of the function octave is going to pick up. I am surprised octave does not have better namespace capabilities.

raju
--
Kamaraju S Kusumanchi
http://malayamaarutham.blogspot.com/

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: same function name in two files

bpabbott
Administrator
On Jun 15, 2014, at 8:38 PM, kamaraju kusumanchi <[hidden email]> wrote:

> On Sun, Jun 15, 2014 at 8:27 PM, Ben Abbott <[hidden email]> wrote:
>
> On Jun 15, 2014, at 8:06 PM, kamaraju kusumanchi <[hidden email]> wrote:
>
> > Let's say I have two scripts (fileA.m, fileB.m) with the following set of functions.
> >
> > fileA.m
> > foo()
> > funcA1()
> > funcA2()
> >
> > fileB.m
> > foo()
> > funcB1()
> > funcB2()
> >
> > The implementation of foo() in both files is completely different. I have no write permissions to edit fileA.m, fileB.m
> >
> > A third script (fileC.m) uses all the six functions. I want to call both foo() implementations at different points in the code. Is there any way to achieve that? For example, is there anything like fileA.foo() , fileB.foo() to distinguish between the two?
> >
>
> I assume fileA.m and fileB.m are scripts and not functions?
>  
> Yes, all three of them fileA.m, fileB.m and fileC.m are scripts and not functions.
>  
>
> Then, first run fileA and when you use foo() it corresponds to the implementation in fileA.
>
>         fileA
>         foo
>
> To use the version if fileB, first fun fileB
>
>         fileA
>         foo
>
>
> IMHO, this is really error prone way of doing it. Since every time you write code, you have to look back, keep track of the function octave is going to pick up. I am surprised octave does not have better namespace capabilities.
>
> raju

Historically, the m-file language was not object oriented. However, classdef support is being added to Octave and will allow methods associated with different objects to be called for each instance of an object.

        http://www.mathworks.com/help/matlab/ref/classdef.html

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: same function name in two files

kamaraju
On Sun, Jun 15, 2014 at 8:43 PM, Ben Abbott <[hidden email]> wrote:
On Jun 15, 2014, at 8:38 PM, kamaraju kusumanchi <[hidden email]> wrote:

>
>
> IMHO, this is really error prone way of doing it. Since every time you write code, you have to look back, keep track of the function octave is going to pick up. I am surprised octave does not have better namespace capabilities.
>
> raju

Historically, the m-file language was not object oriented. However, classdef support is being added to Octave and will allow methods associated with different objects to be called for each instance of an object.

        http://www.mathworks.com/help/matlab/ref/classdef.html


Ah, sweet!  I think the methods in the classdef is what I am after. I am currently using octave 3.8.1 on Debian Jessie. Does this support classdef? 

octave:1> help classdef
error: help: 'classdef' not found
octave:1> version
ans = 3.8.1

If not, is it available in a development branch or something? I don't mind compiling from source. I have not done this in a long time as Debian octave packages are pretty good and I never felt the need to compile from sources.

raju
--
Kamaraju S Kusumanchi
http://malayamaarutham.blogspot.com/

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: same function name in two files

bpabbott
Administrator
On Jun 15, 2014, at 8:58 PM, kamaraju kusumanchi <[hidden email]> wrote:

> On Sun, Jun 15, 2014 at 8:43 PM, Ben Abbott <[hidden email]> wrote:
> On Jun 15, 2014, at 8:38 PM, kamaraju kusumanchi <[hidden email]> wrote:
>
> >
> >
> > IMHO, this is really error prone way of doing it. Since every time you write code, you have to look back, keep track of the function octave is going to pick up. I am surprised octave does not have better namespace capabilities.
> >
> > raju
>
> Historically, the m-file language was not object oriented. However, classdef support is being added to Octave and will allow methods associated with different objects to be called for each instance of an object.
>
>         http://www.mathworks.com/help/matlab/ref/classdef.html
>
>
> Ah, sweet!  I think the methods in the classdef is what I am after. I am currently using octave 3.8.1 on Debian Jessie. Does this support classdef?
>
> octave:1> help classdef
> error: help: 'classdef' not found
> octave:1> version
> ans = 3.8.1
>
> If not, is it available in a development branch or something? I don't mind compiling from source. I have not done this in a long time as Debian octave packages are pretty good and I never felt the need to compile from sources.
>
> raju

The work on classdef is under way. A lot is completed in the default branch.

        http://www.gnu.org/software/octave/get-involved.html

There are several Debian users among the developers.  If you would like to help out, first setup your mercurial archive and then send an email to the developers mail-list.

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave