[OpenSCAD] Functions literals / higher order functions

Michael Marx michael at marx.id.au
Mon Nov 25 20:07:11 EST 2019


I expect it is a scope issue with the 'move' function, I'll mention it on GitHub.

 

  _____  

From: Discuss [mailto:discuss-bounces at lists.openscad.org] On Behalf Of Michael Marx
Sent: Tue, 26 Nov 2019 11:51
To: 'OpenSCAD general discussion'
Subject: Re: [OpenSCAD] Functions literals / higher order functions

 

I get 

 

Compiling design (CSG Tree generation)...

ECHO: g3_x = function(x) g((x + a))

ERROR: Recursion detected calling function 'g' in file fn literals parkinbot.scad, line 4

TRACE: called by 'g', in file fn literals parkinbot.scad, line 4.

TRACE: called by 'g3', in file fn literals parkinbot.scad, line 13.

TRACE: called by 'echo', in file fn literals parkinbot.scad, line 13.

Compiling design (CSG Products generation)...

 

When I changed it to:

 

function move(a, g) = 

  function(x) 

    //echo(a,g) 

      g(x+a) ;

 

g1 = function(x) x;

g2 = move(0,g1);

g3 = move(1,g2);

 

echo(g3_x=g3);

echo(g3_2=g3(2));

 

removing the comments causes a seeming infinite recursion echoing to the console, had to quit the
gui, then it crashed.

 

  _____  

From: Discuss [mailto:discuss-bounces at lists.openscad.org] On Behalf Of Ronaldo Persiano
Sent: Tue, 26 Nov 2019 11:08
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Functions literals / higher order functions

 

 

I can't see why the following generates a stack overflow:

 

function move(a, g) = 

  function(x) g(x+a) ;

 

g1 = function(x) x;

g2 = move(0,g1);

g3 = move(0,g2);

 

echo(g3_x=g3);

echo(g3_2=g3(2));

 

If g3 is defined as g2 no error is reported.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20191126/4ffce565/attachment.html>


More information about the Discuss mailing list