octave-maintainers
[Top][All Lists]
Advanced

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

Re: [octvae forge] shadowing between packages


From: CROZIER Richard
Subject: Re: [octvae forge] shadowing between packages
Date: Mon, 18 Mar 2019 13:53:05 +0000


On 18/03/2019 13:38, Andrew Janke wrote:
>
>
> On 3/18/19 3:52 AM, JuanPi wrote:
>> Hi Andrew,
>>
>> The case is for geometry and matgeom, in particular function clipPolygon
>> (mercurial) https://sourceforge.net/p/octave/geometry/ci/default/tree/
>> (git) https://sourceforge.net/p/octave/matgeom/ci/master/tree/
>>
>>> Doing namespaces dynamically is hard, because it means that you have to:
>>> a) rearrange the source files on disk to put them in a namespace before
>>> you add them to the path, and
>>
>> I am already doing this anyway. For example I am erasing functions
>> that shadow core functions (e.g. deg2rad), so I could slightly change
>> this to put all these functions into a namespace.
>>
>>> b) transform the code itself so function references now refer to the
>>> namespaced function, instead of the global non-namespaced one.
>>
>> ok, based on my ignorance, I thought namespace would work as the
>> folder private. If global is the first scope where functions are
>> looked for, then namespaces offer no advantages (for this case) over
>> the order of loading the packages, i.e. load pkg A first then pkg B to
>> shadow functions in pkg A, and live with the consequences...
>
> Nope. Namespaced functions don't work like private/. Like static class
> methods, they are only looked for if explicitly referenced using their
> namespace-qualified name. (It's a bummer. There's an "import" command to
> deal with this, but it is scoped to functions, not files or classes, so
> it's not a whole lot of help.)
>
> I don't envy you this work.
>
> If this were me, I would beg the authors of these packages to move their
> functions into namespaces (providing optional global-function shims for
> back-compatibility).
>
> Cheers,
> Andrew
>


I wrote some code to automatically refactor a bunch of functions in a
directory to convert them into a +package and use the full namespaced
calling syntax inside all the function files where they call each other.

If this sounds useful to you I can share it with you. You could probably
set up a script to convert matgeom every time a new version is produced.

Regards,

Richard

The University of Edinburgh is a charitable body, registered in Scotland, with 
registration number SC005336.

reply via email to

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