i've watched a lot of tutorials and even did a 100 hours course, but only this video teached me way more, thanks for the video. Please keep doing it, youre a excellent teacher.
Thanks a lot for this great series! Only one correction - 2:22 this version of print will output 1..20, not 20..1, as IO.puts goes after recursive call
Thanks for the series, but I want to point out the reduce example where you used fn x,y -> you said x is tha accumulator where in reality the y is the accumulator (docs: Enum.reduce([1, 2, 3], 0, fn x, acc -> x + acc end))
Maybe there is a better sample to show the power of optimized tail calls in Elixir. The problem with that Fibonacci sample is that the two solutions are very different in terms of time complexity (the first sample is exponential and the second is constant). I think that this was the greater optimization here. I'm looking for a example comparing the time in two solutions with similar time complexity.
@@TensorProgramming I just want to reiterate on this. I really wanted to see any speedup due to tail recursion, but going from exponential to linear (not constant) runtime hid any effects it might have had.
Going to keep watching the videos and play around with it myself, but I dont understand right now why at 2:32 it doesnt go print in reverse. My understanding of recursive calls thus far is that since we call the function again before printing with IO.puts, it should call print(20), then print(19) which calls print(18) down to 0 which outputs :ok, then it returns back to print(1) which continues and puts 1, then returns and puts 2, then 3, etc to 20. Maybe the recursion in handled differently in elixir, eg the function call is setup, then the rest of the function continues, then it returns and calls the recursive function? its really weird coming from other procedural languages that work the way I described as far as I know
yeah when I test with this, I get it to print from 1 -> 20. I am wondering if the code you actually compiled had the puts() first then the recursive call. It is confusing watching the video because of this but not the end of the world, easy enough to understand with how the stack works and testing on your own for other people that run into it
@@jpbastyr You are right to suspect something strange is going on but no, this is the code that I ran in this video and in this example. All of my videos are live coded and the code you see in the repo was not changed from what I ran in the console. I can't give you much more information than this because I have also seen inconsistent behavior with this function. Just now when I was reading through your comment I decided to rerun the code and received what I saw in the video. I then implemented a logger to see the underlying stack calls and got the reverse as you mentioned. I will look into this further and see if I can get you an answer.
@@lyloft It is, in the command line I call the function with 20 and get 20...1 The explanation from 10 was to show off what was going on showing it off from 20 would have been redundant.
dude, you have no idea how awesome you are.
Glad you are finding this series useful.
i've watched a lot of tutorials and even did a 100 hours course, but only this video teached me way more, thanks for the video.
Please keep doing it, youre a excellent teacher.
thanks mate. More is on the horizon.
Best explanation yet for a noob trying to learn Elixir. Well done.
Nice, I am thinking of remaking this series, but glad its still helping people.
I'm currently learning Elixir, and this series are really amazing. Thanks a lot for the awesome content!
glad you're finding it useful. I want to redo this series soon.
Thank you Tensor.
Great explained ;)
Thanks a lot for this great series!
Only one correction - 2:22 this version of print will output 1..20, not 20..1, as IO.puts goes after recursive call
Yeah I am aware. One of the side effects of having all of this stuff be live coded.
Your explanation is awesome and very easy to understanding, Thanks .
Thanks for the series, but I want to point out the reduce example where you used fn x,y -> you said x is tha accumulator where in reality the y is the accumulator (docs: Enum.reduce([1, 2, 3], 0, fn x, acc -> x + acc end))
Yes you are absolutely correct here. I guess this was a side effect of the video being live coded.
Fantastic video. Covered a lot of useful ground
Thank you, glad you like the content.
great video thank you
Maybe there is a better sample to show the power of optimized tail calls in Elixir. The problem with that Fibonacci sample is that the two solutions are very different in terms of time complexity (the first sample is exponential and the second is constant). I think that this was the greater optimization here.
I'm looking for a example comparing the time in two solutions with similar time complexity.
Nothing about this series cares about time complexity. I may do something on it later but for now, this is just to help others understand recursion.
@@TensorProgramming I just want to reiterate on this. I really wanted to see any speedup due to tail recursion, but going from exponential to linear (not constant) runtime hid any effects it might have had.
Going to keep watching the videos and play around with it myself, but I dont understand right now why at 2:32 it doesnt go print in reverse. My understanding of recursive calls thus far is that since we call the function again before printing with IO.puts, it should call print(20), then print(19) which calls print(18) down to 0 which outputs :ok, then it returns back to print(1) which continues and puts 1, then returns and puts 2, then 3, etc to 20. Maybe the recursion in handled differently in elixir, eg the function call is setup, then the rest of the function continues, then it returns and calls the recursive function? its really weird coming from other procedural languages that work the way I described as far as I know
yeah when I test with this, I get it to print from 1 -> 20. I am wondering if the code you actually compiled had the puts() first then the recursive call. It is confusing watching the video because of this but not the end of the world, easy enough to understand with how the stack works and testing on your own for other people that run into it
@@jpbastyr You are right to suspect something strange is going on but no, this is the code that I ran in this video and in this example. All of my videos are live coded and the code you see in the repo was not changed from what I ran in the console. I can't give you much more information than this because I have also seen inconsistent behavior with this function.
Just now when I was reading through your comment I decided to rerun the code and received what I saw in the video. I then implemented a logger to see the underlying stack calls and got the reverse as you mentioned. I will look into this further and see if I can get you an answer.
@@jpbastyr i got the same output as you. It prints from 1 to 20.
the output should be 20, 19 ... 1
of the first recursion
@@lyloft It is, in the command line I call the function with 20 and get 20...1 The explanation from 10 was to show off what was going on showing it off from 20 would have been redundant.
Another fantastic explanation. Pground.print(10)
1
2
3
4
5
6
7
8
9
10
When you have
def print(0), do: :ok
def print(n) do
print(n - 1)
IO.puts(n)
end
Right, its the magic of editing.