pca006132 has quit [Remote host closed the connection]
pca006132 has joined #openscad
kintel has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
TheCoffeMaker has quit [Ping timeout: 268 seconds]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
TheCoffeMaker has joined #openscad
mohammad1722 has joined #openscad
guso78k has joined #openscad
<guso78k>
kintel, I supposed so. I could not make out a "feature" calling "extrudePolygon" twice using some hidden "global" variables even though evaluating the CSG tree appears to have two stages. In any case it was much fun to me when the guys here were kidding about "degenerate #justalittleffold". Was hoping to see a fix like "speeding up
<guso78k>
rotateExtrude by 100%" O:3
mtinman has quit [Quit: Leaving.]
mohammad1722 has quit [Ping timeout: 250 seconds]
guso78k has quit [Quit: Client closed]
<Virindi>
hmm. is there any way to say is_undef but for a function? like, if function xyz is defined, call it. otherwise do something else
J24k19 has quit [Quit: Client closed]
J24k19 has joined #openscad
guso78k has joined #openscad
TheCoffeMaker has quit [Ping timeout: 268 seconds]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
guso78k has quit [Quit: Client closed]
mmu_man has joined #openscad
<J24k19>
Virindi is_undef(f(x))?a:f(x);
<Virindi>
sure, okay. but then I get WARNING: Ignoring unknown function 'f'
TheCoffeMaker has joined #openscad
<Virindi>
can't just have meaningless warnings because then I would miss real warnings :)
TheCoffeMaker has quit [Ping timeout: 256 seconds]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
TheCoffeMaker has joined #openscad
mmu_man has quit [Ping timeout: 256 seconds]
TheCoffeMaker has quit [Ping timeout: 245 seconds]
mmu_man has joined #openscad
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Ping timeout: 255 seconds]
TheCoffeMaker_ has joined #openscad
J24k19 has quit [Quit: Client closed]
J24k19 has joined #openscad
BeginnerHasAQues has joined #openscad
BeginnerHasAQues has quit [Client Quit]
TheCoffeMaker_ has quit [Ping timeout: 268 seconds]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
<J24k19>
virindy you sure need to have the function you want to use defined
TheCoffeMaker has joined #openscad
<J24k19>
Virindi
<J24k19>
you also need to define the variables used
TheCoffeMaker has quit [Excess Flood]
<J24k19>
echo( is_undef(undef)?true:false;);
<Virindi>
huh, that's the whole point. I want to have an optional function
<J24k19>
you can't use something if you didn't define it - maybe paste some sample code so i understand what you trying to do
<Virindi>
what I asked...I want something similar to
<Virindi>
except where no warning is generated if f() is not defined
<J24k19>
the whole point of a warning is that you do something that can't work
<Virindi>
echo(is_undef(f())? true: false);
<Virindi>
produces
<Virindi>
WARNING: Ignoring unknown function 'f' in file...
<Virindi>
yes of course, I am not sure how I am being unclear, I am confused
TheCoffeMaker has joined #openscad
<J24k19>
interestingly enough this isn't an error
<Virindi>
with a variable, I can have an optional variable. I can say is_undef(x) and if x is never assigned, there is no warning. However, I cannot do the same with a function.
<J24k19>
If you write a function in your code that is not existent - this has to cause a warning because you can't do that
<Virindi>
I literally want to test if a function is defined or not.
<J24k19>
you can use function as literal
<J24k19>
i think there is is_function
<Virindi>
...without generating a warning
<Virindi>
there is. however, it does not work as you are saying. first f() is evaluated, then the result is passed to is_function
teepee_ has joined #openscad
<Virindi>
is_function(f()) throws a warning if f() is not defined.
<J24k19>
echo(is_function(x)); but you still need to define x
<Virindi>
no.
<Virindi>
echo(is_function(f())? true: false);
<Virindi>
WARNING: Ignoring unknown function 'f'
<J24k19>
In what universe you have a function in your code that is not defined that will not cause a problem
<J24k19>
x=function () 1;echo(is_function(x));
<Virindi>
for modularity of course. if custom_xyz_function() is defined, compute xyz with that. otherwise use the default one
<Virindi>
so somewhere else in the world, if custom_xyz_function() is defined it overrides the behavior for computing xyz
<J24k19>
there are other ways to do this - please paste your example and i can show you how this can be done
teepee has quit [Ping timeout: 260 seconds]
teepee_ is now known as teepee
<J24k19>
you module has variables defined .. now you can check if these are undef or function and build a conditional or assert them
<Virindi>
I was just asking if it was possible to programmatically determine if a function exists, I guess you are saying the answer is 'no'.
<teepee>
in release version, no
<Virindi>
release? I am using nightly 2024.04.13
<J24k19>
undef and non existent are not the same
<Virindi>
I know that J24k19!
<Virindi>
did you not read my original question
<teepee>
then it should be possible with function literals
<teepee>
but you must not use f() inside the undef call as that already *calls* the function there
<Virindi>
I want some method to determine if a particular function exists, and store that into a boolean, without throwing a warning.
<Virindi>
how, then, teepee?
<Virindi>
temp = f(); // WARNING
<Virindi>
echo(is_function(temp));
<Virindi>
and
<Virindi>
echo(is_function(f())); // WARNING
<J24k19>
you can only evaluate the result of a function - therefor the function need to exist, but you can evaluate a variable that can be a function but therefor that variable need to exist
<Virindi>
just say no, please stop telling me why I don't actually need what I was asking about
<J24k19>
because that would not be true
<J24k19>
but preventing warnings for bad coding skills is not possible
<Virindi>
it's not bad coding if the entire purpose of the code is to check if f() exists
<Virindi>
such a thing is in place for variables. is_undef()
<J24k19>
maybe you don't understand what functional programming means
<Virindi>
if as you say using an undefined thing is "bad coding skills" then why does is_undef() suppress the same warning for variables?
<teepee>
echo(is_function(f())); <--- this first calls f() and then checks if the RETURN value is a function!
<Virindi>
so you have to define the function as a variable in the first place
<Virindi>
yeah I figured as much there.
<J24k19>
a non existent variable is undef but also a=undef;
<J24k19>
a non existent function can't compute
<Virindi>
you can't assign a variable to an existing function and do this, but you can if you treat it like a variable in the definition. I see
<J24k19>
you telling the programm use the function .. so it answers "there is no function with that name"
<Virindi>
thanks teepee
TheCoffeMaker has quit [Ping timeout: 268 seconds]
<J24k19>
as i told you before you can use literals - guess you haven't understood me
<Virindi>
J24k19: if you say, echo(is_undef(foo)); and foo has never been defined, openscad DOES NOT output a warning :P
<Virindi>
personally I am very happy it does not because I make extensive use of that
<J24k19>
again because foo=undef and non existent foo ist both undef. so foo can be your function (as literal) but if you calling a function f(x) you explicitly say "please compute this existent function"
<J24k19>
maybe try with is_num(foo) which will cause a warning if foo is not defined
<J24k19>
undefined variables that are used should cause an error not just a warning
<J24k19>
but modules work even with cylinder(undef);
<teepee>
that's the classical script vs. typed language, which today tends to move towards more typed checks
<teepee>
openscad is old enough to have started with that script style, just go on somehow and maybe give a warning
<J24k19>
like GPT4 .. you get something but don't expect to be what you want
<teepee>
a bit more predictable, but yeah, something like that
<teepee>
with things like "stop on first warning" things are moving into the direction of more checks, more help against random errors or typos
<J24k19>
i mean i prefer to use a conditional instead of a assert(); that stops everything
<J24k19>
like expecting a vec3 but input is vec2 .. just adding a 0 making it a vec3
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
TheCoffeMaker has joined #openscad
<teepee>
it often also depends on context, like it might be ok in an application, but considered rude in a library (like a c++ library doing calling exit() to end the whole program)
<J24k19>
at least you should throw a warning to let you know that your input being corrected
TheCoffeMaker has quit [Ping timeout: 260 seconds]
<Virindi>
I come from the c/c++ world and having actual compile time checking, I just can't handle not having it. It blows my mind that people would rather errors occur at runtime than on the developer's box when they hit compile
<Virindi>
I carefully watch for warnings and correct them, in openscad :)
<J24k19>
"stop at first warning" doesn't leave you any choice
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Read error: Connection reset by peer]
mmu_man has quit [Ping timeout: 268 seconds]
TheCoffeMaker has joined #openscad
mmu_man has joined #openscad
TheCoffeMaker has quit [Ping timeout: 268 seconds]
mmu_man has quit [Ping timeout: 268 seconds]
mmu_man has joined #openscad
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Ping timeout: 252 seconds]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Read error: Connection reset by peer]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Ping timeout: 272 seconds]
TheCoffeMaker has joined #openscad
TheCoffeMaker has quit [Excess Flood]
snaked has quit [Quit: Leaving]
crazy_imp has quit [Ping timeout: 245 seconds]
TheCoffeMaker has joined #openscad
crazy_imp has joined #openscad
R2robot has joined #openscad
<InPhase>
Virindi: Did you understand the part about how function literals give the capability if you initially define functions that might or might not be there as function literals?
<InPhase>
Virindi: This is the bit of the language intended to give more dynamic and flexible behavior like that.
<InPhase>
Virindi: An envisioned workflow for dynamic behavior like that would be passing or omitting a function as a parameter. One could also imagine special variable functions existing or not in different calls. If a standard function is missing from the lexical scope however, this is much more like the case of a C syntax error that would arise and could not be avoided (it requires some fancy SFINAE
<InPhase>
shenanigans in C++ to handle that sort of thing dynamically at compile time, and very few languages can actually do that sort of thing).
<InPhase>
Except that OpenSCAD does several things that should probably be syntax errors through the warning mechanism, for historical reasons. The warning approach was probably an attempt to be more tolerant and beginner friendly, which it achieves in certain cases and fails at in others.
<Virindi>
yeah of course C++ offers better ways to handle module to module interaction :)
<Virindi>
in openscad it is always a hack
<Virindi>
but yeah it seems that assigning a function to a variable is what I wanted
<Virindi>
my partner just asked me if we can implement newton's method in openscad
<Virindi>
he wants to draw a catenary curve exactly
<Virindi>
talk about causing yourself pain
<InPhase>
Virindi: Should be straightforward.
<Virindi>
I assume the approach would be just to use recursion as if it were a loop
<InPhase>
Yep.
<InPhase>
Make sure to make it tail recursion as well, so it optimizes right.
<Virindi>
wait. openscad doesn't have hyperbolic trig? ugh no :(
<InPhase>
It's pretty formulaic really if you do some sort of d=0 depth counter.
<Virindi>
alrighty
<Virindi>
openscad should have hyperbolic trig so I don't have to have those functions in there :)
<InPhase>
Virindi: function sinh(a) = (exp(a)-exp(-a))/2; function cosh(a) = (exp(a)+exp(-a))/2;
<InPhase>
Not exactly a hard implementation. ;)
<Virindi>
yeah I know.
<Virindi>
how exactly would tail recursion look in openscad anyway? since a function is a single expression. would it be like:
<Virindi>
function f(iteration) = (iteration!=0)? ...calculate... : f(x);
<Virindi>
er
<Virindi>
function f(iteration) = (iteration!=0)? ...calculate... : bottom_level_result;
<Virindi>
also is it possible to debug such a thing? as in, can you print inside a function at all? print is a statement, right, so it can't be inserted into an expression?
<Virindi>
ah, the opposite
<InPhase>
echo fits just fine.
<InPhase>
Virindi: Some formulaic thinking demonstrated: https://bpa.st/DTWQ
<Virindi>
we already got newton working :)
<InPhase>
Also, if you ever want more demos of how to do wilder things with functions, this library is good for some examples: https://github.com/thehans/funcutils
<Virindi>
cool
<Virindi>
this is just like, draw a wire in an assembly more correctly :)
<InPhase>
Things like zip, shuffle, slice, csv parsing...
guso78k has joined #openscad
guso78k has quit [Client Quit]
Guest0 has joined #openscad
<Guest0>
hello everyone, I created a model then got a stl file.I want to pint it but it becomes solid