[OpenSCAD] Openscad Indirect Functions

doug moen doug at moens.org
Sun Oct 23 07:46:01 EDT 2016


Otto wrote:

> I see a major need for the following:
> 1. The adoption and implementation of anonymous function syntax.
> ...
> Doug proposes anonymous functions be written function(<arglist>) expr
>

The OpenSCAD2 proposal was written during May-July 2015. I've had a lot of
new ideas since then, but I mostly haven't updated the document, because it
was exhausting to write, and time considerations. Now I'm actually coding,
and trying to prototype some of the ideas. I'll write new documentation
once my design stabilizes.

My original 'function(arglist)expr' syntax was based on the old Javascript
syntax for anonymous functions. It turns out that when you try to use this
syntax for writing code, it sucks. That's probably why Javascript has
replaced this syntax with arrow notation. I'm using arrow notation now as
well. My syntax is actually identical to the new Java syntax for anonymous
functions, which uses -> (Javascript is the same except it uses =>).

My original proposed syntax is too verbose for short anonymous functions
like 'x->x+1', and if you want a long anonymous function, it might be
clearer to write a named function definition, as nop head suggested.

The other problem with my original syntax is that it sucks for curried
functions. The OpenSCAD2 proposal explains why curried functions are
important.

In arrow notation, you can write `x->y->x+y`, and that's a curried
function. In the originally proposed syntax, that would be
`function(x)(function(y)x+y)` which is a lot more verbose, and requires
nested parentheses. And you can't write a curried function at all using
Otto's @ notation (I've tried, the code doesn't work).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20161023/efcd92b5/attachment-0002.html>


More information about the Discuss mailing list