[OpenSCAD] Functions literals / higher order functions

Torsten Paul Torsten.Paul at gmx.de
Sat Nov 9 10:46:46 EST 2019

On 09.11.19 16:15, adrianv wrote:
> Would it be worth adding a simpler mechanism for passing
> existing functions?

Yes, that certainly is open for discussion. It might even be
possible to bind the built-in functions to the respective
names in the variable namespace.

As that is one layer up from the top layer available to the
user, it would still be possible to just overwrite those names
in existing code.

I believe the only non-compatible change is that you can
still observe this by "if (is_undef(sin))" on top level.

> It seems like the existing scheme creates two independent
> namespaces for functions and it's sort of clumsy to get
> between them.

The other way around. Those separate namespaces already exist
and cause the issues now. The problem is that first class
functions obviously need to be in the variable namespace as
they are really just values.

> What would be the disadvantage of writing all of my functions
> using the new syntax. Would there be any problems with this?
> So always write
> funcname = function(...) definition....;

Right now, the only disadvantage I'm aware of is that use<>
will not import them as they are variables, and use<> only
imports (old style) functions and modules.

That's something which needs to be changed of cause.


More information about the Discuss mailing list