[OpenSCAD] Openscad Indirect Functions
nop.head at gmail.com
Mon Oct 10 05:06:50 EDT 2016
You don't seem to use the @ sign in the places I would expect. I don't see
a need for them in the function definition as any function should be
passable as an argument. I would expect them to be needed where a function
is called from a string, so:
function xsq(x) = x*x;
function map(func,vec) = [for (i=vec) @func(i)];
The @ sign could also be used to make a function literal instead of passing
string but that is a bigger change to the language. Simply adding @ to take
a string and look up function seems like a simple mod. Creating a new
variable type that is a function would have much bigger implications
because it could be used in any expression. Keeping the name as a string
allows all sorts of tricks by concatenating suffixes, etc.
On 10 October 2016 at 09:53, otto <otto at 123phase.com> wrote:
> I have hacked the openscad source code to support function indirection.
> Here is a sample of how it works. Function is decorated with the "@"
> character when it is created and when it is used, but not when it is
> passed to another function.
> //Preferred usage//
> function @xsq(x) = x*x;
> function @recip(x)=1/x;
> function map(func,vec) = [for (i=vec) @func(i)];
> //Other crazy usage//
> function div3(x)=x/3;
> indirect = "div3";
> Output is:
> ECHO: [1, 4, 9]
> ECHO: [0.01, 0.49]
> ECHO: [1, 0.5, 0.333333]
> ECHO: [10, 1.42857]
> ECHO: [0.0333333, 0.233333]
> Everything is contained in the github repositor:
> There is a pdf file there with some sample 3D and 2D output. In order
> to get this capability you need to add about 30 lines of code in
> changes to five files in the source directory. These are relatively
> stable files and you may get away with simply copying them from the
> ojasSources directory.
> This is very much a work in progress. Comments, questions, flames,
> laughter, mockery etc. all welcome. If anyone tests this please let me
> know what your experience is. Everything is gnu public license as is
> the source code for openscad.
> OpenSCAD mailing list
> Discuss at lists.openscad.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Discuss