[OpenSCAD] Functions literals / higher order functions

MichaelAtOz oz.at.michael at gmail.com
Mon Nov 25 20:49:25 EST 2019


As I mentioned  On GitHub here
<https://github.com/openscad/openscad/pull/3077#issuecomment-558417555>  ,
this stops the infinite recursion, don't know why, need caffeine...

function move(a, g) = echo(move=a,g)
  function(x) 
      echo(g_in_move=a,x)
        (x+a) ;


g1 = function(x)    
        
          x;
g2 = move(1,g1);
g3 = move(3,g2);

echo(g1_=g1);
echo(g1_1=g1(1));
echo(g2_=g2);
echo(g2_7=g2(7));
echo(g3_x=g3);
echo(g3_5=g3(5));

Gets:

Compiling design (CSG Tree generation)...
ECHO: move = 1, function(x) x
ECHO: move = 3, function(x) echo(g_in_move = a, x) (x + a)
ECHO: g1_ = function(x) x
ECHO: g1_1 = 1
ECHO: g2_ = function(x) echo(g_in_move = a, x) (x + a)
ECHO: g_in_moveg = 1, 7
ECHO: g2_7 = 8
ECHO: g3_x = function(x) echo(g_in_move = a, x) (x + a)
ECHO: g_in_moveg = 3, 5
ECHO: g3_5 = 8
Compiling design (CSG Products generation)...
Geometries in cache: 0



-----
Admin - email* me if you need anything,  or if I've done something stupid...

* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

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



More information about the Discuss mailing list