[OpenSCAD] Functions literals / higher order functions

Parkinbot rudolf at digitaldocument.de
Sun Nov 3 17:46:59 EST 2019


Yes! Just try it out. 

  function foo(a, f) = f(a); 
  echo(foo(30, sin)); 

gives obviously a syntax error: "Ignoring unknown variable 'sin' ... "
while the following code does what you intended. 

  echo(foo(30, function(x) sin(x))); 

Trying to redefine sin() by 

    sin = function(x) sin(x); 

in order to call 

    echo(foo(30, sin)); 

will detect a recursion. While the following typo will indeed brick OpenSCAD

    sin = function(x) sin(); 
    echo(sin(30)); 





--
Sent from: http://forum.openscad.org/



More information about the Discuss mailing list