[OpenSCAD] Functions literals / higher order functions
avm4 at cornell.edu
Sat Nov 9 10:15:00 EST 2019
> On 03.11.19 22:40, adrianv wrote:
>> foo(function(x) sin(x))
> Yes, all built-in functions and also those defined in
> the previously existing function name() = expression
> syntax have their own special namespace and are no values
> that can be passed around. To do that they need to be
> wrapped like that.
Would it be worth adding a simpler mechanism for passing existing functions?
It seems like the existing scheme creates two independent namespaces for
functions and it's sort of clumsy to get between them. In MATLAB, for
example, you can pass an existing function by writing "@sin". I can
imagine having to write code where I generate a table of function
redefinitions to make it easy to pass pre-existing functions without the
need for all the verbosity of a function declaration embedded in the code
for every call.
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....;
This seems like it could be desirable since you can do something with a
function literal defined this way that you can't do with a regular function.
And there is no apparent advantage to defining functions the "normal" way.
I mean, the one obvious limitation is that I no longer have a different
namespace for functions if I do this.
Sent from: http://forum.openscad.org/
More information about the Discuss