[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: same function name in two files
From: |
Ben Abbott |
Subject: |
Re: same function name in two files |
Date: |
Sun, 15 Jun 2014 20:43:26 -0400 |
On Jun 15, 2014, at 8:38 PM, kamaraju kusumanchi <address@hidden> wrote:
> On Sun, Jun 15, 2014 at 8:27 PM, Ben Abbott <address@hidden> wrote:
>
> On Jun 15, 2014, at 8:06 PM, kamaraju kusumanchi <address@hidden> 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