I am programming for OpenSCAD
(www.openscad.org) a python interface.
One sample code is:
obj1 = linear_extrude(obj=lambda h:[[0,0],[1,0],[1,1],[0,1+h*h/100]],height=10)
Please wrap these in “code fences”; it makes things easier to read and
also preserves various formatting and punctuation, eg:
```
obj1 = linear_extrude(obj=lambda h:[[0,0],[1,0],[1,1],[0,1+h*h/100]],height=10)
```
Anyway, to your suggestion:
This creates an extrusion of a cross section with a “dynamic” cross-section.
It uses a lambda function in order not to define an extra function.
Aside: this does define a function, but it doesn’t have a name 
But it does not yet look very nice(or mathematical). A mathematics would write:
obj1 = linear_extrude(obj(h) =[[0,0],[1,0],[1,1],[0,1+h*h/100]],height=10)
Yes.
I tested this boldly, but python did not understand my intent 
is it possible to make get this working with a decorator ?
Unfortunately, no.
The primary issue is that function arguments are evaluated before the
function is called. CHanging that would break, well, almost everything.
So in your preferred expression with obj(h)=
the right hand sid is
always evaluated. As you’re discovered.
To prevent that you’d need a language level syntactic construct to say
“prepare this expression, but do not run it; instead, let me run it
later”. And that is inherently what a function definition does.
We’ve got two ways to do this: the def f(x)
form and the lambda x:
form.
BTW: it could be a common method to use lambda functions as function arguments …
all the information is there, its shorter to write and more easy to read.
I think almost everyone agrees that writing the word lambda
is very
cumbersome, and it doesn’t look much like a nice clean mathematical
expression.
There have been many calls to allow the greek letter lambda: λ
(GREEK SMALL LETTER LAMDA Unicode: U+019B), though I suppose technically
we should prefer: ƛ (LATIN SMALL LETTER LAMBDA WITH STROKE Unicode:
U+03BB) which I think is the one used in math.
These have generally fizzled, but would have allowed:
obj1 = linear_extrude(obj=ƛ h:[[0,0],[1,0],[1,1],[0,1+h*h/100]],height=10)
Another alternative is JavaScript like “arrow functions”:
(h) -> ([[0,0],[1,0],[1,1],[0,1+h*h/100]])
which are also not part of Python.
It may be better to go with a named function; at least they have the
benefit of having their name evoke the operation semantics and also let
you put in a docstring!
def extrude_nice_adjective_here(h):
''' An extrusion of such and such a type.
'''
return [[0,0],[1,0],[1,1],[0,1+h*h/100]]
Wordier, but then you can write:
obj1 = linear_extrude(obj=extrude_nice_adjective_here, height=10)
which is at least expressive.
Cheers,
Cameron Simpson cs@cskk.id.au