[OpenSCAD] Proposal for extensions to the OpenSCAD syntax

Torsten Paul Torsten.Paul at gmx.de
Sun Oct 27 20:13:34 EDT 2019


First note that the function literals are now
implemented, so the snapshot version of OpenSCAD
has functions as first class values which means
support for higher order functions.
(https://github.com/openscad/openscad/pull/3077)

I hope to find some time to collect notes and post
an article about it. Meanwhile the minimalist docu
can be found at
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/User-Defined_Functions_and_Modules#Function_Literals

On 28.10.19 00:09, Hugo Jackson wrote:
> To start, I would propose an extension of the "dot"
> notation, that would allow one to refer to a value
> declaration and/or function or module component of
> another module with a dot.

Yes, having access to a nested data structure is
definitely something that would help a lot. The
core changes to the parser implementation that are
required for this are now done and merged to the
development snapshot.

But I don't think it will be possible to link to
the existing function and/or module definitions.

Slightly modified example, just adding a parameter
to module foo():

module foo(offset) {
	valueA = 7 + offset;

	function myFunc(num) = valueA + num;
}

module bar() {
	valueB = 8;

	valueC = foo.valueA + foo.myFunc(valueB);
}

foo(10);
translate([10, 10, 0]) foo(20);

bar(); // <- now what is valueC ?


> The second extension would be the election of three
> operations as 'reserved' functions, union, difference
> and intersection such that one could explicitly call
> that part of a module without calling the others:

I'm not sure I understand how this will work. Why
select specifically those 3 special cases?

Is that meant just as names or would that also mean
intersection() { bar(); foo(); } a bit like operator
overloading?

> foo(); // would execute intersection(){difference(){union(){<union code>}<difference code>}<intersection code>}

Where's the nesting coming from? From the order of
the definitions?

> Please let me know… I didn’t want to bog this
> proposal down with details if it’s obvious, but in
> doing that I have taken the risk that the improvement
> And benefits of such extensions may not be evident.

Yes, more details are always good in that discussion.

See also https://github.com/openscad/openscad/pull/3087
which is implementing a similar proposal mostly as
reference for discussion.

More discussion can be found in
https://github.com/openscad/openscad/issues/3088

It would be great if we can find a definition that
works nicely as addition without breaking existing
scripts.

ciao,
  Torsten.



More information about the Discuss mailing list