<InPhase>
The sum function only gives the total. The integral function gives the list of values where each is the sum of 0 through i of the input list.
<InPhase>
Hold on, this is not setup right for pairs.
<ali1234>
ie instead of writing mylist[len(mylist)-1] you just write mylist[-1]
<InPhase>
Guest64: I updated the repo from the first link. That version should work now too. :)
<InPhase>
ali1234: Probably not difficult at all. Unless someone gives a really good reason to object, I'd support that change. We currently just return undef for negative values, which is as useless as a behavior could get, being neither an error to indicate a bug nor a useful result.
<ali1234>
is there a way to check openscad version in a script?
<ali1234>
so for example if this change or any other was made, scripts can check if the features they use are supported?
<InPhase>
We could set something like $version but this isn't really so obviously useful. There are release versions, that could be like $version = 20210100; But then you'd want a label for nightlies, which could add the day, like $version=20250214; Maybe release could be distinguished by having a 0 under %100 if we never did a second release within a month.
<InPhase>
But you then have the issue of optional and experimental features, which can be compiled in or not compiled in, and the optional ones can be turned on or not by settings.
<InPhase>
But maybe it's better than nothing to provide that as a start.
<ali1234>
if you are running nightly/experimental then you should have a new enough version anyway
<InPhase>
Of course, if we start providing a $version or similar, you'd have to first check if that is set.
<InPhase>
Otherwise your script would fail on versions before it's set. ;)
<ali1234>
version() already works
<ali1234>
although it returns two numbers on nightly
<ali1234>
and version_num() returns 2.02501e+7
<ali1234>
actual version is 2025.01.20.ai22731, i wonder why the 20 is not showing
mmu_man has quit [Ping timeout: 244 seconds]
<stealth_>
is version_num returning a float ?
<ali1234>
all numbers are floats in openscad
<ali1234>
double (64 bit) actually, so that any 32 bit int may be exactly represented
<stealth_>
i suppose you just compare the two values, but it wouldn't show actual date in a float
<stealth_>
after the "."
<ali1234>
yeah, it's just because i used echo to print it
<ali1234>
but for example "36342608503257322 % 4294967296" gives the wrong answer in openscad (and javascript/lua/others)
<stealth_>
aww... every time i code in scad, i feel like i should do this in python! lol i just can't code fast enough and i dislike c like syntax.
<ali1234>
i know what you mean, but when i tried using solidpython etc, i found it just allowed even more messy incomprehensible code
<stealth_>
i see, i haven't used those, maybe it needs better syntax.
<ali1234>
i'm not sure. it's "pythonic", which is what you want from a python wrapper?
<ali1234>
problem is that CSG doesn't really fit into python's idea of how to structure code
<stealth_>
i suppose, i should actually use some python to scad languages first then talk about it :p
<stealth_>
csg?
<ali1234>
constructive solid geometry
<ali1234>
what openscad does :)
<stealth_>
i see, i have to mess around with things to figure it out.
<ali1234>
i think it would be better served by bringing some python concepts to openscad rather than trying to wrap it
<stealth_>
maybe you could code it in python and have it create the .scad file and have openscad render it. i think there were some features to support that.
<ali1234>
that is what solidpython does
<teepee>
there is already a version adding python
<teepee>
not in an ugly way like solidpython (which is useful to people but not well integrated)
<stealth_>
how is it bad?
<stealth_>
os maybe a new python like syntax needs to be created for openscad using python's ast ?
<teepee>
not bad
<ali1234>
i would rather see first class modules, geometry introspection, and the tag system in existing openscad syntax, rather than going nuclear by using python as a workaround.
<teepee>
it's not integrated as it just generates source code
<teepee>
yes, I'd like the extended openscad syntax too
<teepee>
if you have the time, try it out
<stealth_>
solidpython right?
<teepee>
sorry I meant ali1234, I have to check the PR and link
<ali1234>
i'd love to be able to just say "center() my_object();" and have my_object translated such that it's bounding box is centred on the origin, but there is no way to implement that currently
<ali1234>
and today my_object was defined by a list so i could get its size by dividing the last item in the list by 2... but then my_list[-1] doesn't work (see above)
<teepee>
no, you can't ;-) but you can say center() my_object;
<ali1234>
what is my_object?
<teepee>
a geometry literal that is already converted to mesh
<stealth_>
i am not a fan of assigning variable `d = cube()` to have it render
<teepee>
you can only get rid of that by patching python I think
<stealth_>
maybe bit of a hack but should be able to render automatically like you would in openscad, it can be triggered when you can `import openscadlibrary`
<teepee>
that would be nice, yes
<teepee>
no I think the patch is C/C++ python, guso78 would know more
<teepee>
but maybe there is a python wizard who knows how to do that on python level too
<teepee>
I've seen plenty of that, yes, great for single lines
<teepee>
not helping for anything bigger. it's just different then
<ali1234>
the solidpython assigns to a variable though
<ali1234>
i'm confused about what exactly you want?
<stealth_>
ali1234, rather than passing `a = cube(); a.render()` in python you just do `cube()` and it should render in python just like openscad would.
<teepee>
I still maintain openscad code can be written in a very readable way (raedable even for non-programmers)
<teepee>
I don't care about code golfing my designs
<stealth_>
teepee, you are used to it :p
<ali1234>
i think openscad is generally easier to understand than the equivalent solidpython
<stealth_>
coming from python coding style into C style is a nightmare
<teepee>
I also do Python for a living for > 3 years now (after like 20 with Java)
<ali1234>
i also use python pretty much exclusive for coding software
<teepee>
so I claim to be able to judge what *I* like :-)
<ali1234>
stealth_: problem is what if you don't want it to render?
<ali1234>
what if you just want to know how big it is?
<ali1234>
but not actually render it
<stealth_>
ali1234, you could have it inside a function/module
<ali1234>
but if you call the function, it will render
<stealth_>
if you are openly calling `cube()` it would render just like in openscad
<stealth_>
yes, so it should.
<ali1234>
so the function behaves differently depending on what scope you call it in?
<stealth_>
technically, wont know till implemented.
<ali1234>
i mean it would have to
<ali1234>
but then what if you want to render something from inside a function?
<stealth_>
like you said you have to call that function
<ali1234>
you always have to call the function, otherwise it won't do anything
<ali1234>
see this is kind of what i was getting at earlier
<ali1234>
python is structured for writing software, not for declaring geometry
<ali1234>
it gives you nice things like first class functions and comprehensions, but it also makes other things harder
<stealth_>
well you can call it once and have it build some kind of array and use that array over and over, if thats what you want.
<stealth_>
or cache function.
Guest64 has quit [Quit: Client closed]
Guest6010 is now known as buZz
<guso78>
Yes, only patching Python. But i have IT. Issue IS that you have to Install a Patched Python Into your system.
<stealth_>
guso78, hmm? patched python?
<guso78>
But really : spending little Note Charakters Makes all Code way more "predictable".
<guso78>
Note=more
<guso78>
A Print Statement IS Not assigned to a var and you dont want to are that to Geometries. What Happens If you do Not assign expressions in sub routines?
muesli has quit [Quit: NO CARRIER]
<stealth_>
guso78, Print statement output's its content to stdout. Are saying you can do the same with openscad render function in python? Its a valid point
muesli has joined #openscad
guso78k has joined #openscad
<guso78k>
the print statement is just an example for understanding, but true is way more sophisticated in reality
<guso78k>
print statement *does* write to stdout, but at the same time it returns None as a return value if it was assigned
<guso78k>
if an expression in a python function was not assigned, would it contribute to python output display or rather to its (implicit) return value ...
<stealth_>
python does lots of weird stuff like that, for good reason. its __set__ under the hood being overridden to not return
<stealth_>
or return None in descriptor.__set__
<guso78k>
i you elaborate little bit more on that ? you mean __set__ for setting object paramters(dictionary) ?
<guso78k>
I suspect, that you would very soon want to go *with* assignments. look at this e.g. https://imgur.com/a/3wcOBHg
<guso78k>
thank you for the link btw
<ali1234>
descriptors only exist on class instances
<stealth_>
most things in python are object and thus a low level class
<ali1234>
all things
<ali1234>
however, the only place where descriptors are involved with functions calls is when you call a method. a descriptor takes the unbound function from the class and converts it into a bound method that you can call without having to provide "self"
<ali1234>
calling bare functions in the module scope doesn't do this, and anyway there are plenty of easier ways to make functions have side-effects. the problem is side-effects are bad
<stealth_>
hmm function don't have methods. also function are global scope while methods are local to class.
<ali1234>
usually, yes
<ali1234>
however you can add methods to a function, because a function is an object, like everything else
<ali1234>
usually you would not do this though
<guso78k>
exact for that reason i had to code almost all functions twice( functions + methods) which is quite some effort, which is not easy to understand
<ali1234>
functions are usually module scope, but they can be defined inside functions as well
<ali1234>
the functions defined on a class are regular functions too, until you try to call them. the method versions are created on-demand
<stealth_>
function inside a function is a local scope function, can't call it from outside!
<ali1234>
you can on a class though, because they are exposed as attributes
<stealth_>
those are methods not function.
<ali1234>
but on instances of that class you get a descriptor that fetches the real function and wraps it
<stealth_>
class().method()
<ali1234>
nope, the functions on a class really are unbound functions
<ali1234>
class.method()
<ali1234>
class().method() invokes a descriptor to dynamically create a bound method object
<ali1234>
this is why you can do f = class().method; f(); - and it remembers which object f should be bound to
<ali1234>
try doing that in C++, it's a nightmare
<stealth_>
ya cause you inilized the class with class()
<ali1234>
when you access class().method, it is actually a property which returns a function
<ali1234>
it takes the unbound function from the class and binds it, then returns it
<stealth_>
or are you talking about static function ? where you can do class.static_function()
<ali1234>
these are all the same thing in python - that's the point
<ali1234>
those decorators like @classmethod and @staticmethod don't actually do much other than swap around the arguments
<stealth_>
i suppose someone figured it was a good idea to add those.
<guso78k>
yes, i like decorators! Its a pitty that you only change functions with it (not variables, not invocations, not modules, not operators)
<ali1234>
try this: "class Foo: def bar(): pass; f = Foo(); a = f.bar; b = f.bar; a is b"
<stealth_>
maybe lost in lingo, for me `f = class().method` would be `f` as reference. and `f()` would be function
<stealth_>
of corse this get weird when you bring in async/await, but lets not go there :p
<ali1234>
class().method is an attribute, and it is backed by a descriptor
<ali1234>
but the point of my example: a is not b. why?
<ali1234>
the answer is because bar is a descriptor that returns a new function every time you access it
<stealth_>
python does weird things like that, might have something to do with __getattr__
<ali1234>
but descriptors can only exist on classes, so literally none of this affects what happens if you have a module that calls "cube();" and doesn't bind the result to a name
<ali1234>
whether it happens inside a function, a method, or at the module scope
<ali1234>
descriptors cannot affect it
misterfish has joined #openscad
J25k has quit [Quit: Client closed]
J25k has joined #openscad
<InPhase>
ali1234: ... I forgot all about version()...
<stealth_>
o, might have to do with descriptors being low level c function/pointer it hasn't been converted to python yet. can't use dis on `f.bar` either.
<ali1234>
cpython has optimisations in this area
<stealth_>
i know stuff like this happens when you are dealing with c/ctypes as well.
<ali1234>
it will avoid ever instantiating the bound method object if all you do is call it and then discard
<ali1234>
this is invisible though. if you bind it to another name, you get a new one every time
<stealth_>
Yeah that not python behavior its C
<ali1234>
point is, descriptors are part of dot notation
guso78k has quit [Quit: Client closed]
<ali1234>
when you call a function like "cube()" there is no dot
<InPhase>
Oof. A lot of fuss over people overthinking the value of putting restrictions on their licenses.
<InPhase>
I'll say it again, there's a reason I CC0 my 3D models and libraries...
<InPhase>
I don't CC0 everything I make! But 3D models and libraries? Unless I have a profit plan for something, CC0. Everything else is just a cascade of chaos for 3D printing.
<InPhase>
Where I see restrictions kicking in as valuable is for more involved applications, where something like GPL serves to future-guard the cutting edge of progressive development on an application. There's no extend-extinguish step possible then. But this is not really an issue for 3D models.
<InPhase>
I suppose also, good on NTI for embracing the public good will obtainable by just fixing the non-problem problem. In a sea of companies not getting the simple things, some do.
little_blossom has quit [Ping timeout: 252 seconds]