[OpenSCAD] OpenSCAD and data flow languages

Richard Urwin soronlin+openscad at googlemail.com
Tue Oct 25 09:05:45 EDT 2016


(mailing list still doesn't like raw text.)

Rather than tie up the Polygon thread any more, I'll drop this here.

I was considering for loops and functional language last night.

Consider:

for x in list
   body


That can be seen as an anonymous function something like:

function anon(list)
{
   if len(list) > 0 then
   {
      x = head(list)
      body
      anon(tail(list));
   }
}

anon(list);


What about adding some more parameter passing like this:

function anon(list, local definitions)
{
   if len(list) > 0 then
   {
      x = head(list)
      body
      anon(tail(list), local definitions);
   }
}

anon(list, initial definitions);


Then we need a little more syntax:

for x in list
initially
{
    y = 0
}
{
      y = old y + 1
      ...
}


"y" refers to the parameter that is to be handed off to the next recursion
and "old y" refers to the parameter that was passed to this recursion.
So that would convert to:

function anon(list, old_y)
{
   if len(list) > 0 then
   {
      x = head(list)
      y = old_y + 1
      ...
      anon(tail(list), y);
   }
}

anon (list, 0);




--
View this message in context: http://forum.openscad.org/OpenSCAD-and-data-flow-languages-tp18521p18798.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list