Namespace 2

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

Namespace 2

vicnet
Hello,

I rework on namespace with a different approach than first time.
Here is the current code not yet finished (function and variable are not managed)...
  https://github.com/vicnet/openscad/compare/namespace2

Currently, namespace are defined when using library. The last part of the path is use as a namespace.
For example, use <mcad/shape.scad> will define a MCAD namespace. All methods of this module are inside this namespace, and will be not accessible without using namespace.
A method is called like this: mcad.box(x,y,z)

I use this definition (rather than filename = namespace) because a library could contains lot of files (like MCAD) and filename are not always good, library name is better. I use only the last part because I manage only one namespace depth currently.
Also there is parallel between define namespace and using it.
'use <xxx.scad>' without any directory is include in main namespace (no namespace).

In next version, an OpenScad parameter should disallow namespace for compatibility...

Is the way to implement namespace (use and code) is correct ?
Here a summary of code impacts:
- parser.y add 'nspace' struct parameter. nspace srtuct define path (as before) and filename (text by user)
- lexer.l: set 'nspace' parameter with information
- parser.y: in module_instantiation add ID '.' single_module_instantiation that create a NamespaceInstantiation
- module.h/cc: add NamespaceInstantiation (bad name in fact...), 'evaluate' add namespace in eval context then call instantiate as before
- module.h: replace Library from std::string to Library class (with path and name), and allow multiple library definition with different namespaces
- EvalContext: add namespace string for evaluation of a module (and next a function)
- FileContext::instantiate_module
  if context namespace is empty (calling namespace), do as before except FileModule with namespace
  if not, only search in FileModule with namespace

If you have some remarks, don't hesitate...

a+
Vicnet
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

Johannes Reinhardt
Hi,

but this prevents you from organizing your library with subdirectories,
doesn't it? Or how do you distinguish between using a scad file from a
subdirectory and defining a new namespace?

Greetings

On Wed, 4 Dec 2013 05:01:22 -0800 (PST)
vicnet <[hidden email]> wrote:

> Hello,
>
> I rework on namespace with a different approach than first time.
> Here is the current code not yet finished (function and variable are
> not managed)...
>   https://github.com/vicnet/openscad/compare/namespace2
>
> Currently, namespace are defined when using library. The last part of
> the path is use as a namespace.
> For example, use <mcad/shape.scad> will define a MCAD namespace. All
> methods of this module are inside this namespace, and will be not
> accessible without using namespace.
> A method is called like this: mcad.box(x,y,z)
>
> I use this definition (rather than filename = namespace) because a
> library could contains lot of files (like MCAD) and filename are not
> always good, library name is better. I use only the last part because
> I manage only one namespace depth currently.
> Also there is parallel between define namespace and using it.
> 'use <xxx.scad>' without any directory is include in main namespace
> (no namespace).
>
> In next version, an OpenScad parameter should disallow namespace for
> compatibility...
>
> Is the way to implement namespace (use and code) is correct ?
> Here a summary of code impacts:
> - parser.y add 'nspace' struct parameter. nspace srtuct define path
> (as before) and filename (text by user)
> - lexer.l: set 'nspace' parameter with information
> - parser.y: in module_instantiation add ID '.'
> single_module_instantiation that create a NamespaceInstantiation
> - module.h/cc: add NamespaceInstantiation (bad name in fact...),
> 'evaluate' add namespace in eval context then call instantiate as
> before
> - module.h: replace Library from std::string to Library class (with
> path and name), and allow multiple library definition with different
> namespaces
> - EvalContext: add namespace string for evaluation of a module (and
> next a function)
> - FileContext::instantiate_module
>   if context namespace is empty (calling namespace), do as before
> except FileModule with namespace
>   if not, only search in FileModule with namespace
>
> If you have some remarks, don't hesitate...
>
> a+
> Vicnet
>
>
>
>
> --
> View this message in context:
> http://forum.openscad.org/Namespace-2-tp6175.html Sent from the
> OpenSCAD mailing list archive at Nabble.com.
> _______________________________________________ OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
> http://openscad.org - https://flattr.com/thing/121566



--

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

vicnet
Johannes Reinhardt wrote
but this prevents you from organizing your library with subdirectories,
doesn't it? Or how do you distinguish between using a scad file from a
subdirectory and defining a new namespace?
subdirectories: future version should allow multiple namespaces corresponding to each subdirectories.
  use <lib/mcad/shapes.scad>
  lib.mcad.box(1,2,3)

defining namespace: in future too, is should be possible to force namespace
  use <lib/mcad/shapes.scad> as mc
  mc.box(1,2,3)

But before doing this, I want to be sure to go in correct direction concerning implementation...

a+
Vicnet
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

MichaelAtOz
Administrator
a. this is limited to "use <...>", not "include <...>"?

b.
So for

use <dir/f1.scad> 
use <dir/f2.scad>

Are in one namespace (dir) and any variable (v1) in the global scope of f1 & f2 is the same single variable dir.v1; hence the value assigned will follow the last assigned rule I presume, e.g. the f2 assignment.?

c.
I think using MCAD as an example can be confusing, as it is not really a thought out library, just a bunch of code grouped together (IMO), but this also makes your suggestion "OpenScad parameter should disallow namespace for compatibility" more important. I'd suggest the reverse. I haven't done the detail, but I'm pretty sure there are going to be variable, and possibly module/function conflicts in MCAD, so a unsuspecting programmer could be in trouble 'use'ing two MCAD files because they both use 'i='.

I think it would be better to enforce/mandate the "as" syntax (to declare a namespace), rather than defaulting to a name based on directory structure, which brings influences external to the language. Such as if the directory does not reflect a valid OpenSCAD identifier, or you rename directories you have to change every instance of dir.something, rather than just editing the 'use'.

d.
Presumably files in a library can then use their own namespaces.

Would/should these be accessable at global or all levels? Such as
name1.name2.module3(); // at global level

---
That should do for now.. ;)






Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

MichaelAtOz
Administrator
Re my point b above
I also presume (?) that in main file

dir.v1=my_value;

is valid and following the last assigned rule, will be the value of v1 within f1 & f2.
Hence good for setting default values.
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

iamwil
Just wanted to see how the namespace work was going, and wanted an update. I also didn't see Kintel comment on the namespace threads, so I'm wondering if this is even under consideration to make it into the master branch?

I'm still for a package manager for OpenSCAD, but it won't work very well without namespaces.

Cubehero: Work with others on 3D printable projects
https://cubehero.com
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

kintel
Administrator
On Dec 20, 2013, at 17:15 PM, iamwil <[hidden email]> wrote:

> Just wanted to see how the namespace work was going, and wanted an update. I
> also didn't see Kintel comment on the namespace threads, so I'm wondering if
> this is even under consideration to make it into the master branch?
>
I feel the namespace concept needs more discussion. I’m not a big fan of approaches where folder names implicitly define namespaces.

One idea (which is also backwards compatible) would be to explicitly instantiate namespaces using e.g.
mynamespace = use <mylib.scad>;

..or simply deprecate the use <> syntax for a more function-like syntax; mynamespace = use(‘mylib’);
..or use a different keyword (import, require etc.)
We’ll also need to clarify how assignments actually work in OpenSCAD and what can be assigned to what.

Related to this, the new font functionality currently uses ‘use <fontname>’ to include fonts. I think we need to take this into account as well if we’re going to modify the meaning of the ‘use’ keyword.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

iamwil
wasn't it proposed that the format would be:

use <mylib.scad> inside mylibnamespace;

So then it would be optional, and backwards compatible?

Wil
Cubehero: Work with others on 3D printable projects
https://cubehero.com
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

kintel
Administrator
On Dec 21, 2013, at 20:33 PM, iamwil <[hidden email]> wrote:

> wasn't it proposed that the format would be:
>
> use <mylib.scad> inside mylibnamespace;
>
> So then it would be optional, and backwards compatible?
>
Yes, looking more carefully at the history, there was indeed a mention of a ‘use <mylib.scad> as mylib’ as a future implementation.
I think that way of doing it makes sense. Whether or not we assign it to a variable explicitly makes no real difference I think. I just think that using variables makes it more explicit, since we’re going to use the mylib.module() syntax later on.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

runsun
Just follow this thread to check out if there's any movement along this line
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

doug.moen
Hi Runsun.

There is movement. Marius and I have been discussing this. Once we can
agree on an initial design proposal, I will create a github repository
with a design document and some code, and start iterating towards a
working prototype. At that point, it will become possible for other
people to get involved. Once the prototype is applied to existing
OpenSCAD code, then we'll have a better idea of how well the proposal
will work.

Doug Moen.

On 09/05/2015, runsun <[hidden email]> wrote:

> Just follow this thread to check out if there's any movement along this line
>
>
>
>
> -----
>
> $  Runsun Pan, PhD
>
> $ -- OpenScad_DocTest: doc and unit test ( Github , Thingiverse  )
>
> $ -- hash parameter model: here , here
>
> $ -- Linux Mint 17.1 Rebecca x64  + OpenSCAD 2015.03.15/2015.04.01.nightly
>
>
>
>
> --
> View this message in context:
> http://forum.openscad.org/Namespace-2-tp6175p12614.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Namespace 2

runsun
Thx man. Much appreciated.
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets