califax has quit [Remote host closed the connection]
califax has joined #openscad
N4buc0 has quit [Remote host closed the connection]
lostapathy has joined #openscad
peeps[zen] has joined #openscad
peeps[win] has quit [Ping timeout: 240 seconds]
peepsalot has quit [Ping timeout: 260 seconds]
use-value1 has joined #openscad
use-value has quit [Ping timeout: 260 seconds]
use-value1 is now known as use-value
ur5us_ has joined #openscad
J2226 has joined #openscad
J22 has quit [Ping timeout: 250 seconds]
SilentSquares has joined #openscad
<SilentSquares>
I'm having trouble with re-assigning variables within a loop. With python, you would go something like
<SilentSquares>
x = 0
<SilentSquares>
for i in (len(range(10)))
<SilentSquares>
x =+
<SilentSquares>
and at the end x would be equal to 9
<SilentSquares>
but within openscad
<SilentSquares>
A) you cant specifically assign an *index* of a variable/array, you're reassigning the whole array.
<SilentSquares>
B ) When I'm running my code, and running echo, x will do 0, 10 times
<SilentSquares>
Can Iget some help on this?
<SilentSquares>
basically, I'm unable to re-assign a variable from within a loop. The tutorial shows using i, a, etc. whatever the iterative variable *is.* but I cannot use that alone.
SilentSquares has quit [Ping timeout: 250 seconds]
arebil has joined #openscad
drkow has joined #openscad
arebil has quit [Quit: My keyboard has gone to sleep. ZZZzzz…]
drfff has quit [Ping timeout: 246 seconds]
ViktorasCNC has joined #openscad
arebil has joined #openscad
ur5us_ has quit [Ping timeout: 268 seconds]
J2226 has quit [Quit: Client closed]
J2226 has joined #openscad
arebil has quit [Quit: My keyboard has gone to sleep. ZZZzzz…]
arebil has joined #openscad
J2226 has quit [Quit: Client closed]
J2226 has joined #openscad
<J2226>
silentsquares went silent
califax has quit [Remote host closed the connection]
teepee has quit [Remote host closed the connection]
califax has joined #openscad
teepee has joined #openscad
ali1234 has quit [Remote host closed the connection]
<peeps[zen]>
as a new user in the channel, it makes it looks like you were impatient and quit. if you wanted replies while offline you should mention that before logging off
<peeps[zen]>
but the answer is: no, you can't reassign variables like that. Openscad is a functional language, which follows a declarative model of programming (as opposed to imperative which you are likely accustomed to).
<SilentSquares>
then why does the documentation not mention this? in fact it's super unclear how loop heiarchy works, and I've only gotten so far due to my novice experience in python.
<SilentSquares>
when is a ";" needed? why is it needed? why are the tutorials so barebones? I'm literally writing testing code to attempt to figure out this.
<SilentSquares>
if openscad has it's own language, there's a lot of heritage from python's syntax that *isn't mentioned anywhere.*
<AndrewStone[m]>
how many languages do you know?
<AndrewStone[m]>
(computer)
<SilentSquares>
I'm a novice at python and that's *it*
<SilentSquares>
i just wanted to make fractals
<peeps[zen]>
i'd say its closer to C/C++ in syntax
<SilentSquares>
why can't I re-assign value to a specific index of an array? i have to re-construct the whole array
<SilentSquares>
the list goes on
<AndrewStone[m]>
SilentSquares: its syntax isn't much like python compared to many other computer languages. Computer languages fall into 2 broad categories and the similarities you are finding with python are just those.
<AndrewStone[m]>
a VERY long time ago, 2 major families of computer languages were invented: declarative and functional.
<AndrewStone[m]>
Python is declarative but borrows some functional elements like lambdas, openscad is functional.
<AndrewStone[m]>
what functional means is like math functions.
<AndrewStone[m]>
a math function always returns the same value if given the same input.
<AndrewStone[m]>
ha by "declarative" I meant "imperative", oops
<AndrewStone[m]>
so by extension, in a functional language you can't set a variable to another value, because just returning that variable from a function breaks the "function always returns the same value if given the same input" rule.
<AndrewStone[m]>
since you are used to imperative style, declarative style will seem awkward to you. (and people have their preference, its religious war for programmers)
<AndrewStone[m]>
but under the covers there are cool optimizations functional languages can do. For example, if openscad has already executed "spur_gear(a,b)" and it is called again, it doesn't have to execute it again. It can just grab the prior result.
<AndrewStone[m]>
you can also more effectively do proofs of program behavior on functional style.
<AndrewStone[m]>
these advantages are likely to be irrelevant to you for years -- and yes, you are going to smack straight into functional programming's major drawback -- you can't change variables once set.
<AndrewStone[m]>
So imperative style certainly appeals more to beginners. It might be frustrating, but ultimately probably rewarding to learn both major language families. Each family has advantages and disadvantages
<AndrewStone[m]>
typically in a functional language you want to construct the array "right" the first time, modify it in "passes" -- that is, don't modify just 1 element, pass through the array creating a new array by applying the change to every element in the original one. This is efficient.
<AndrewStone[m]>
WRT openscad though, I don't know, I've been working with the lang for only a week now.
<peeps[zen]>
SilentSquares: what type of fractals did you want to make? there are likely some existing examples you could study, which might help understanding how such things are done
<AndrewStone[m]>
s/declarative/functional/
<peeps[zen]>
SilentSquares: for example, you can see a Menger Sponge implementation in "Examples -> Old -> example024.scad"
<SilentSquares>
Sierpinski gasket, for example
SilentSquares has quit [Quit: Client closed]
TheCoffeMaker has quit [Ping timeout: 260 seconds]