discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: Parameters for Complex Constructions

PC
Patrick Callahan
Tue, Nov 23, 2021 10:16 PM

The big thing that's missing is the ability to construct an object from an
OpenSCAD program.  I believe that the expectation is that that will look
something like

o = {
a = 5;
b = 6;
};

Then there should probably be some other stuff like union, difference and
intersection.  Maybe some kind of "object comprehension" that would let you
construct an object in the same sort of way that a list comprehension lets
you construct lists.

Just having the ability to create the object, pass it to a module or

function, and reference the contents by o.a or o.b would be a big win.  It
would reduce the need to create constructor and access functions for every
aspect of a feature.

How can I help?

-Pat
Note that this reply is bottom-posted.
If using Gmail's web app, click the three dots immediately after hitting
reply, place cursor at bottom. Easy!

> > > The big thing that's missing is the ability to construct an object from an > OpenSCAD program. I believe that the expectation is that that will look > something like > > o = { > a = 5; > b = 6; > }; > > Then there should probably be some other stuff like union, difference and > intersection. Maybe some kind of "object comprehension" that would let you > construct an object in the same sort of way that a list comprehension lets > you construct lists. > > Just having the ability to create the object, pass it to a module or function, and reference the contents by o.a or o.b would be a big win. It would reduce the need to create constructor and access functions for every aspect of a feature. How can I help? -Pat Note that this reply is bottom-posted. If using Gmail's web app, click the three dots immediately after hitting reply, place cursor at bottom. Easy!
TP
Torsten Paul
Wed, Nov 24, 2021 5:30 PM

On 23.11.21 23:16, Patrick Callahan wrote:

How can I help?

Discussion about objects is here:
https://github.com/openscad/openscad/pull/3087
https://github.com/openscad/openscad/issues/3088

This is based on the OpenSCAD2 proposal Doug made some
time ago. The topic is a bit dormant, but as Jordan
wrote, the some internal parts of the objects are now
already present in the dev snapshots and used by the
text/fontmetrics calls.

Also note that other parts of the OpenSCAD2 proposal
are already released, like the function literals.

In my view, it's not meant as big bang change, like
the python2 -> python3 process. Instead it's a guide
for improvement.

ciao,
Torsten.

On 23.11.21 23:16, Patrick Callahan wrote: > How can I help? Discussion about objects is here: https://github.com/openscad/openscad/pull/3087 https://github.com/openscad/openscad/issues/3088 This is based on the OpenSCAD2 proposal Doug made some time ago. The topic is a bit dormant, but as Jordan wrote, the some internal parts of the objects are now already present in the dev snapshots and used by the text/fontmetrics calls. Also note that other parts of the OpenSCAD2 proposal are already released, like the function literals. In my view, it's not meant as big bang change, like the python2 -> python3 process. Instead it's a guide for improvement. ciao, Torsten.
PC
Patrick Callahan
Wed, Nov 24, 2021 6:30 PM

On Wed, Nov 24, 2021 at 12:30 PM Torsten Paul Torsten.Paul@gmx.de wrote:

On 23.11.21 23:16, Patrick Callahan wrote:

How can I help?

Discussion about objects is here:
https://github.com/openscad/openscad/pull/3087
https://github.com/openscad/openscad/issues/3088

This is based on the OpenSCAD2 proposal Doug made some
time ago. The topic is a bit dormant, but as Jordan
wrote, the some internal parts of the objects are now
already present in the dev snapshots and used by the
text/fontmetrics calls.

Also note that other parts of the OpenSCAD2 proposal
are already released, like the function literals.

In my view, it's not meant as big bang change, like
the python2 -> python3 process. Instead it's a guide
for improvement.

ciao,
Torsten.


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

On Wed, Nov 24, 2021 at 12:30 PM Torsten Paul <Torsten.Paul@gmx.de> wrote: > On 23.11.21 23:16, Patrick Callahan wrote: > > How can I help? > > Discussion about objects is here: > https://github.com/openscad/openscad/pull/3087 > https://github.com/openscad/openscad/issues/3088 > > This is based on the OpenSCAD2 proposal Doug made some > time ago. The topic is a bit dormant, but as Jordan > wrote, the some internal parts of the objects are now > already present in the dev snapshots and used by the > text/fontmetrics calls. > > Also note that other parts of the OpenSCAD2 proposal > are already released, like the function literals. > > In my view, it's not meant as big bang change, like > the python2 -> python3 process. Instead it's a guide > for improvement. > > ciao, > Torsten. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
PC
Patrick Callahan
Wed, Nov 24, 2021 7:08 PM

On Wed, Nov 24, 2021 at 12:30 PM Torsten Paul Torsten.Paul@gmx.de wrote:

On 23.11.21 23:16, Patrick Callahan wrote:

How can I help?

Ok Read all that.

I understand some of the software language engineering issues raised and
that parts of the OpenScad2 proposal are moving forward even if OpenSCAD2
as a whole is not.

Also note that other parts of the OpenSCAD2 proposal
are already released, like the function literals.

What do function literals allow me to do that I could not do without them?
I can see what they are but can't see beyond that.
For what hat are they suitable?  I'm not clear on how to think about coding
with them.

In my view, it's not meant as big bang change, like

the python2 -> python3 process. Instead it's a guide
for improvement.

Yup. There's a lot of discussion of various points on the proposal

itself,  issue threads, and pull requests, and I'm reading more before
commenting further. Expect questions though.

On Wed, Nov 24, 2021 at 12:30 PM Torsten Paul <Torsten.Paul@gmx.de> wrote: > On 23.11.21 23:16, Patrick Callahan wrote: > > How can I help? > > Discussion about objects is here: > https://github.com/openscad/openscad/pull/3087 > https://github.com/openscad/openscad/issues/3088 > <snip> Ok Read all that. I understand some of the software language engineering issues raised and that parts of the OpenScad2 proposal are moving forward even if OpenSCAD2 as a whole is not. > Also note that other parts of the OpenSCAD2 proposal > are already released, like the function literals. > > What do function literals allow me to do that I could not do without them? I can see what they are but can't see beyond that. For what hat are they suitable? I'm not clear on how to think about coding with them. In my view, it's not meant as big bang change, like > the python2 -> python3 process. Instead it's a guide > for improvement. > > Yup. There's a lot of discussion of various points on the proposal itself, issue threads, and pull requests, and I'm reading more before commenting further. Expect questions though.
NH
nop head
Wed, Nov 24, 2021 7:13 PM

Function literals allow you to store function references in valuables and
pass them as parameters. So for example you could have a quicksort routine
and pass a function to do the comparison.

On Wed, 24 Nov 2021 at 19:09, Patrick Callahan pat.callahan1@gmail.com
wrote:

On Wed, Nov 24, 2021 at 12:30 PM Torsten Paul Torsten.Paul@gmx.de wrote:

On 23.11.21 23:16, Patrick Callahan wrote:

How can I help?

Ok Read all that.

I understand some of the software language engineering issues raised and
that parts of the OpenScad2 proposal are moving forward even if OpenSCAD2
as a whole is not.

Also note that other parts of the OpenSCAD2 proposal
are already released, like the function literals.

What do function literals allow me to do that I could not do without them?
I can see what they are but can't see beyond that.
For what hat are they suitable?  I'm not clear on how to think about
coding with them.

In my view, it's not meant as big bang change, like

the python2 -> python3 process. Instead it's a guide
for improvement.

Yup. There's a lot of discussion of various points on the proposal

itself,  issue threads, and pull requests, and I'm reading more before
commenting further. Expect questions though.


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

Function literals allow you to store function references in valuables and pass them as parameters. So for example you could have a quicksort routine and pass a function to do the comparison. On Wed, 24 Nov 2021 at 19:09, Patrick Callahan <pat.callahan1@gmail.com> wrote: > > > On Wed, Nov 24, 2021 at 12:30 PM Torsten Paul <Torsten.Paul@gmx.de> wrote: > >> On 23.11.21 23:16, Patrick Callahan wrote: >> > How can I help? >> >> Discussion about objects is here: >> https://github.com/openscad/openscad/pull/3087 >> https://github.com/openscad/openscad/issues/3088 >> <snip> > > Ok Read all that. > > I understand some of the software language engineering issues raised and > that parts of the OpenScad2 proposal are moving forward even if OpenSCAD2 > as a whole is not. > > >> Also note that other parts of the OpenSCAD2 proposal >> are already released, like the function literals. >> >> > What do function literals allow me to do that I could not do without them? > I can see what they are but can't see beyond that. > For what hat are they suitable? I'm not clear on how to think about > coding with them. > > In my view, it's not meant as big bang change, like >> the python2 -> python3 process. Instead it's a guide >> for improvement. >> >> Yup. There's a lot of discussion of various points on the proposal > itself, issue threads, and pull requests, and I'm reading more before > commenting further. Expect questions though. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
TP
Torsten Paul
Wed, Nov 24, 2021 7:59 PM

On 24.11.21 20:08, Patrick Callahan wrote:

For what hat are they suitable?  I'm not clear on how to
think about coding with them.

Passing functions to other functions or modules allows
for quite powerful library style functions, e.g. fold()
that give the caller influence of calculation details.

fold = function(i, v, f, off = 0) len(v) > off ? fold(f(i, v[off]), v, f, off + 1) : i;

v = [1, 2, 7, 4, -5];

f_add = function(x, y) x + y;
f_mul = function(x, y) x * y;
f_min = function(x, y) is_undef(x) ? y : min(x, y);
f_max = function(x, y) is_undef(x) ? y : max(x, y);

echo(add = fold(0, v, f_add));    // ECHO: add = 9
echo(mul = fold(1, v, f_mul));    // ECHO: mul = -280
echo(min = fold(undef, v, f_min)) // ECHO: -5
echo(max = fold(undef, v, f_max)) // ECHO: 7

More examples: https://github.com/thehans/funcutils

ciao,
Torsten.

On 24.11.21 20:08, Patrick Callahan wrote: > For what hat are they suitable?  I'm not clear on how to > think about coding with them. Passing functions to other functions or modules allows for quite powerful library style functions, e.g. fold() that give the caller influence of calculation details. fold = function(i, v, f, off = 0) len(v) > off ? fold(f(i, v[off]), v, f, off + 1) : i; v = [1, 2, 7, 4, -5]; f_add = function(x, y) x + y; f_mul = function(x, y) x * y; f_min = function(x, y) is_undef(x) ? y : min(x, y); f_max = function(x, y) is_undef(x) ? y : max(x, y); echo(add = fold(0, v, f_add)); // ECHO: add = 9 echo(mul = fold(1, v, f_mul)); // ECHO: mul = -280 echo(min = fold(undef, v, f_min)) // ECHO: -5 echo(max = fold(undef, v, f_max)) // ECHO: 7 More examples: https://github.com/thehans/funcutils ciao, Torsten.
PC
Patrick Callahan
Thu, Nov 25, 2021 1:52 AM

I've looked through https://github.com/thehans/funcutils.

Now, after looking through the documentation and function definitions in a
few of the modules,  I wonder how the utility functions defined in the
funcutils library help when one uses them in an OpenSCAD program.
I know this question exhibits my lack of background in functional
programming.

-Pat
I wonder when functional programming will start to click for me.

On Wed, Nov 24, 2021 at 2:59 PM Torsten Paul Torsten.Paul@gmx.de wrote:

On 24.11.21 20:08, Patrick Callahan wrote:

For what hat are they suitable?  I'm not clear on how to
think about coding with them.

Passing functions to other functions or modules allows
for quite powerful library style functions, e.g. fold()
that give the caller influence of calculation details.

fold = function(i, v, f, off = 0) len(v) > off ? fold(f(i, v[off]), v, f,
off + 1) : i;

v = [1, 2, 7, 4, -5];

f_add = function(x, y) x + y;
f_mul = function(x, y) x * y;
f_min = function(x, y) is_undef(x) ? y : min(x, y);
f_max = function(x, y) is_undef(x) ? y : max(x, y);

echo(add = fold(0, v, f_add));    // ECHO: add = 9
echo(mul = fold(1, v, f_mul));    // ECHO: mul = -280
echo(min = fold(undef, v, f_min)) // ECHO: -5
echo(max = fold(undef, v, f_max)) // ECHO: 7

More examples: https://github.com/thehans/funcutils

ciao,
Torsten.


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

I've looked through https://github.com/thehans/funcutils. Now, after looking through the documentation and function definitions in a few of the modules, I wonder how the utility functions defined in the funcutils library help when one uses them in an OpenSCAD program. I know this question exhibits my lack of background in functional programming. -Pat I wonder when functional programming will start to click for me. On Wed, Nov 24, 2021 at 2:59 PM Torsten Paul <Torsten.Paul@gmx.de> wrote: > On 24.11.21 20:08, Patrick Callahan wrote: > > For what hat are they suitable? I'm not clear on how to > > think about coding with them. > > Passing functions to other functions or modules allows > for quite powerful library style functions, e.g. fold() > that give the caller influence of calculation details. > > fold = function(i, v, f, off = 0) len(v) > off ? fold(f(i, v[off]), v, f, > off + 1) : i; > > v = [1, 2, 7, 4, -5]; > > f_add = function(x, y) x + y; > f_mul = function(x, y) x * y; > f_min = function(x, y) is_undef(x) ? y : min(x, y); > f_max = function(x, y) is_undef(x) ? y : max(x, y); > > echo(add = fold(0, v, f_add)); // ECHO: add = 9 > echo(mul = fold(1, v, f_mul)); // ECHO: mul = -280 > echo(min = fold(undef, v, f_min)) // ECHO: -5 > echo(max = fold(undef, v, f_max)) // ECHO: 7 > > More examples: https://github.com/thehans/funcutils > > ciao, > Torsten. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
FH
Father Horton
Thu, Nov 25, 2021 4:01 AM

It took several tries for it to click. XSLT is the first functional
language I encountered and it took me forever to get it. It didn’t help
that one of the free books I looked at on Amazon did its level best to use
it as an imperative language.

On Wed, Nov 24, 2021 at 7:52 PM Patrick Callahan pat.callahan1@gmail.com
wrote:

I've looked through https://github.com/thehans/funcutils.

Now, after looking through the documentation and function definitions in a
few of the modules,  I wonder how the utility functions defined in the
funcutils library help when one uses them in an OpenSCAD program.
I know this question exhibits my lack of background in functional
programming.

-Pat
I wonder when functional programming will start to click for me.

On Wed, Nov 24, 2021 at 2:59 PM Torsten Paul Torsten.Paul@gmx.de wrote:

On 24.11.21 20:08, Patrick Callahan wrote:

For what hat are they suitable?  I'm not clear on how to
think about coding with them.

Passing functions to other functions or modules allows
for quite powerful library style functions, e.g. fold()
that give the caller influence of calculation details.

fold = function(i, v, f, off = 0) len(v) > off ? fold(f(i, v[off]), v, f,
off + 1) : i;

v = [1, 2, 7, 4, -5];

f_add = function(x, y) x + y;
f_mul = function(x, y) x * y;
f_min = function(x, y) is_undef(x) ? y : min(x, y);
f_max = function(x, y) is_undef(x) ? y : max(x, y);

echo(add = fold(0, v, f_add));    // ECHO: add = 9
echo(mul = fold(1, v, f_mul));    // ECHO: mul = -280
echo(min = fold(undef, v, f_min)) // ECHO: -5
echo(max = fold(undef, v, f_max)) // ECHO: 7

More examples: https://github.com/thehans/funcutils

ciao,
Torsten.


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


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

It took several tries for it to click. XSLT is the first functional language I encountered and it took me forever to get it. It didn’t help that one of the free books I looked at on Amazon did its level best to use it as an imperative language. On Wed, Nov 24, 2021 at 7:52 PM Patrick Callahan <pat.callahan1@gmail.com> wrote: > I've looked through https://github.com/thehans/funcutils. > > Now, after looking through the documentation and function definitions in a > few of the modules, I wonder how the utility functions defined in the > funcutils library help when one uses them in an OpenSCAD program. > I know this question exhibits my lack of background in functional > programming. > > -Pat > I wonder when functional programming will start to click for me. > > > On Wed, Nov 24, 2021 at 2:59 PM Torsten Paul <Torsten.Paul@gmx.de> wrote: > >> On 24.11.21 20:08, Patrick Callahan wrote: >> > For what hat are they suitable? I'm not clear on how to >> > think about coding with them. >> >> Passing functions to other functions or modules allows >> for quite powerful library style functions, e.g. fold() >> that give the caller influence of calculation details. >> >> fold = function(i, v, f, off = 0) len(v) > off ? fold(f(i, v[off]), v, f, >> off + 1) : i; >> >> v = [1, 2, 7, 4, -5]; >> >> f_add = function(x, y) x + y; >> f_mul = function(x, y) x * y; >> f_min = function(x, y) is_undef(x) ? y : min(x, y); >> f_max = function(x, y) is_undef(x) ? y : max(x, y); >> >> echo(add = fold(0, v, f_add)); // ECHO: add = 9 >> echo(mul = fold(1, v, f_mul)); // ECHO: mul = -280 >> echo(min = fold(undef, v, f_min)) // ECHO: -5 >> echo(max = fold(undef, v, f_max)) // ECHO: 7 >> >> More examples: https://github.com/thehans/funcutils >> >> ciao, >> Torsten. >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
PC
Patrick Callahan
Fri, Nov 26, 2021 12:38 PM

My code looks as imperative as possible.  That For statement is my
downfall, even if it is used in a functional way.

It's been said that OpenScad is a functional language.  Is it?

Can you do this?

Array(10).fill("functional programming is not a religion")
.map((msg) => {
console.log(msg);
return msg;
});

Sorry about the impure thoughts Father Horton, see you next Saturday...

On Thu, Nov 25, 2021 at 2:17 AM Father Horton fatherhorton@gmail.com
wrote:

It took several tries for it to click. XSLT is the first functional
language I encountered and it took me forever to get it. It didn’t help
that one of the free books I looked at on Amazon did its level best to use
it as an imperative language.

On Wed, Nov 24, 2021 at 7:52 PM Patrick Callahan pat.callahan1@gmail.com
wrote:

I've looked through https://github.com/thehans/funcutils.

Now, after looking through the documentation and function definitions in
a few of the modules,  I wonder how the utility functions defined in the
funcutils library help when one uses them in an OpenSCAD program.
I know this question exhibits my lack of background in functional
programming.

-Pat
I wonder when functional programming will start to click for me.

On Wed, Nov 24, 2021 at 2:59 PM Torsten Paul Torsten.Paul@gmx.de wrote:

On 24.11.21 20:08, Patrick Callahan wrote:

For what hat are they suitable?  I'm not clear on how to
think about coding with them.

Passing functions to other functions or modules allows
for quite powerful library style functions, e.g. fold()
that give the caller influence of calculation details.

fold = function(i, v, f, off = 0) len(v) > off ? fold(f(i, v[off]), v,
f, off + 1) : i;

v = [1, 2, 7, 4, -5];

f_add = function(x, y) x + y;
f_mul = function(x, y) x * y;
f_min = function(x, y) is_undef(x) ? y : min(x, y);
f_max = function(x, y) is_undef(x) ? y : max(x, y);

echo(add = fold(0, v, f_add));    // ECHO: add = 9
echo(mul = fold(1, v, f_mul));    // ECHO: mul = -280
echo(min = fold(undef, v, f_min)) // ECHO: -5
echo(max = fold(undef, v, f_max)) // ECHO: 7

More examples: https://github.com/thehans/funcutils

ciao,
Torsten.


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


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


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

My code looks as imperative as possible. That For statement is my downfall, even if it is used in a functional way. It's been said that OpenScad is a functional language. Is it? Can you do this? Array(10).fill("functional programming is not a religion") .map((msg) => { console.log(msg); return msg; }); Sorry about the impure thoughts Father Horton, see you next Saturday... On Thu, Nov 25, 2021 at 2:17 AM Father Horton <fatherhorton@gmail.com> wrote: > It took several tries for it to click. XSLT is the first functional > language I encountered and it took me forever to get it. It didn’t help > that one of the free books I looked at on Amazon did its level best to use > it as an imperative language. > > On Wed, Nov 24, 2021 at 7:52 PM Patrick Callahan <pat.callahan1@gmail.com> > wrote: > >> I've looked through https://github.com/thehans/funcutils. >> >> Now, after looking through the documentation and function definitions in >> a few of the modules, I wonder how the utility functions defined in the >> funcutils library help when one uses them in an OpenSCAD program. >> I know this question exhibits my lack of background in functional >> programming. >> >> -Pat >> I wonder when functional programming will start to click for me. >> >> >> On Wed, Nov 24, 2021 at 2:59 PM Torsten Paul <Torsten.Paul@gmx.de> wrote: >> >>> On 24.11.21 20:08, Patrick Callahan wrote: >>> > For what hat are they suitable? I'm not clear on how to >>> > think about coding with them. >>> >>> Passing functions to other functions or modules allows >>> for quite powerful library style functions, e.g. fold() >>> that give the caller influence of calculation details. >>> >>> fold = function(i, v, f, off = 0) len(v) > off ? fold(f(i, v[off]), v, >>> f, off + 1) : i; >>> >>> v = [1, 2, 7, 4, -5]; >>> >>> f_add = function(x, y) x + y; >>> f_mul = function(x, y) x * y; >>> f_min = function(x, y) is_undef(x) ? y : min(x, y); >>> f_max = function(x, y) is_undef(x) ? y : max(x, y); >>> >>> echo(add = fold(0, v, f_add)); // ECHO: add = 9 >>> echo(mul = fold(1, v, f_mul)); // ECHO: mul = -280 >>> echo(min = fold(undef, v, f_min)) // ECHO: -5 >>> echo(max = fold(undef, v, f_max)) // ECHO: 7 >>> >>> More examples: https://github.com/thehans/funcutils >>> >>> ciao, >>> Torsten. >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
TP
Torsten Paul
Fri, Nov 26, 2021 1:32 PM

On 26.11.21 13:38, Patrick Callahan wrote:

Can you do this?

Sure, but why?

array = [ for (msg = [ for ([0:9]) "blah" ]) echo(msg) msg ];

ciao,
Torsten.

On 26.11.21 13:38, Patrick Callahan wrote: > Can you do this? Sure, but why? array = [ for (msg = [ for ([0:9]) "blah" ]) echo(msg) msg ]; ciao, Torsten.