discuss@lists.openscad.org

OpenSCAD general discussion

View all threads

Re: first class modules WIP

BC
Bob Carlson
Sun, Sep 4, 2022 7:41 PM

I have slogged through all of this discussion and a lot of the stuff you posted in your issue on Github, but I am still mystified why you find the idea valuable. The code you have posted is all obscure and difficult to understand. What is the point of obscure and difficult to understand code? I just see no advantage to it. If feels like cleverness for its own sake.

The objects proposal on the other hand and the object literals described in issue 3087 seem immediately and obviously useful. It makes code that is more readable and understandable. It allows something close to OOP. A big win.

-Bob
Tucson AZ

On Sep 4, 2022, at 10:33, Andy Little via Discuss discuss@lists.openscad.org wrote:

From: kwikius@yahoo.com
Subject: [OpenSCAD] first class modules WIP
Date: September 4, 2022 at 10:33:05 MST
To: discuss@lists.openscad.org
Reply-To: OpenSCAD general discussion discuss@lists.openscad.org

I Have now managed to get some actual openscad output using the first class feature into the CSG tree and am sure now this would be a very useful feature.

The example demonstrates putting modules in an array and returning from function.(Full code available to view here https://github.com/kwikius/openscad/blob/WIP-first-class-module/tests/data/scad/experimental/first_class_module/module_array.scad) ( pic of output attached)

// Example put modules in array and return modules from function
geometry = [
// [rotation , translation , module name ]
[[0,0,0], [0,0,0], module my_sphere],
[[0,45,0],[0,2.5 * rscale,0], module my_cylinder],
[[45,45,0],[0,-2.5 * rscale,0], module my_cube]
];
/*
instantiate the modules defined in the geometry array
*/
for ( i = [0 :1: 2]){
translate(get_translation(geometry,i)){
rotate(get_rotation(geometry,i)){
modalias = get_module(geometry,i);  // module return from function
modalias(); // instantiate the module
}
}
}
The source code for the executable is on the WIP-first-class-module branch if you want to try it:w

https://github.com/kwikius/openscad/tree/WIP-first-class-module https://github.com/kwikius/openscad/tree/WIP-first-class-module
though it won’t use arguments yet, apart from in the way described belo

I found the following syntax useful

my_cube = module cube;  // alias the builtin cube
Where there are no arguments, the arguments in the instantiation call are simply passed through to the module.

my_cube([1,2,3],center = true);
looking to implement parameters and arguments next.

<module_array.png>


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I have slogged through all of this discussion and a lot of the stuff you posted in your issue on Github, but I am still mystified why you find the idea valuable. The code you have posted is all obscure and difficult to understand. What is the point of obscure and difficult to understand code? I just see no advantage to it. If feels like cleverness for its own sake. The objects proposal on the other hand and the object literals described in issue 3087 seem immediately and obviously useful. It makes code that is more readable and understandable. It allows something close to OOP. A big win. -Bob Tucson AZ On Sep 4, 2022, at 10:33, Andy Little via Discuss <discuss@lists.openscad.org> wrote: From: kwikius@yahoo.com Subject: [OpenSCAD] first class modules WIP Date: September 4, 2022 at 10:33:05 MST To: discuss@lists.openscad.org Reply-To: OpenSCAD general discussion <discuss@lists.openscad.org> I Have now managed to get some actual openscad output using the first class feature into the CSG tree and am sure now this would be a very useful feature. The example demonstrates putting modules in an array and returning from function.(Full code available to view here https://github.com/kwikius/openscad/blob/WIP-first-class-module/tests/data/scad/experimental/first_class_module/module_array.scad) ( pic of output attached) // Example put modules in array and return modules from function geometry = [ // [rotation , translation , module name ] [[0,0,0], [0,0,0], module my_sphere], [[0,45,0],[0,2.5 * rscale,0], module my_cylinder], [[45,45,0],[0,-2.5 * rscale,0], module my_cube] ]; /* instantiate the modules defined in the geometry array */ for ( i = [0 :1: 2]){ translate(get_translation(geometry,i)){ rotate(get_rotation(geometry,i)){ modalias = get_module(geometry,i); // module return from function modalias(); // instantiate the module } } } The source code for the executable is on the WIP-first-class-module branch if you want to try it:w https://github.com/kwikius/openscad/tree/WIP-first-class-module <https://github.com/kwikius/openscad/tree/WIP-first-class-module> though it won’t use arguments yet, apart from in the way described belo I found the following syntax useful my_cube = module cube; // alias the builtin cube Where there are no arguments, the arguments in the instantiation call are simply passed through to the module. my_cube([1,2,3],center = true); looking to implement parameters and arguments next. <module_array.png> _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org
TP
Torsten Paul
Sun, Sep 4, 2022 8:26 PM

On 04.09.22 21:41, Bob Carlson wrote:

The objects proposal on the other hand and the object literals
described in issue 3087 seem immediately and obviously useful.
It makes code that is more readable and understandable. It allows
something close to OOP. A big win.

I have to admit that I also find at least the literal definition
quite convenient syntax wise.

But I'm not saying we should toss out one of the proposals and
just look at the other one. There's information in both which
should be considered on how things will work. By looking at the
topic from various perspectives we hopefully will get something
that works in a sensible and teachable way.

ciao,
Torsten.

On 04.09.22 21:41, Bob Carlson wrote: > The objects proposal on the other hand and the object literals > described in issue 3087 seem immediately and obviously useful. > It makes code that is more readable and understandable. It allows > something close to OOP. A big win. I have to admit that I also find at least the literal definition quite convenient syntax wise. But I'm not saying we should toss out one of the proposals and just look at the other one. There's information in both which should be considered on how things will work. By looking at the topic from various perspectives we hopefully will get something that works in a sensible and teachable way. ciao, Torsten.