Introduction to Elixir - Recursion, Tail Calls and Comprehensions - Part Five

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ธ.ค. 2024

ความคิดเห็น • 30

  • @Vogel42
    @Vogel42 5 ปีที่แล้ว +25

    dude, you have no idea how awesome you are.

  • @chriscoyc
    @chriscoyc ปีที่แล้ว +1

    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.

  • @awksedgreep
    @awksedgreep ปีที่แล้ว

    Best explanation yet for a noob trying to learn Elixir. Well done.

    • @TensorProgramming
      @TensorProgramming  ปีที่แล้ว +1

      Nice, I am thinking of remaking this series, but glad its still helping people.

  • @HoracioBertorello
    @HoracioBertorello ปีที่แล้ว

    I'm currently learning Elixir, and this series are really amazing. Thanks a lot for the awesome content!

    • @TensorProgramming
      @TensorProgramming  ปีที่แล้ว +2

      glad you're finding it useful. I want to redo this series soon.

  • @andibensisva2155
    @andibensisva2155 5 ปีที่แล้ว +5

    Thank you Tensor.

  • @newraze
    @newraze 2 ปีที่แล้ว

    Great explained ;)

  • @aleksandrkravtsov8727
    @aleksandrkravtsov8727 2 ปีที่แล้ว +2

    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

    • @TensorProgramming
      @TensorProgramming  2 ปีที่แล้ว +1

      Yeah I am aware. One of the side effects of having all of this stuff be live coded.

  • @zakiabouchi3953
    @zakiabouchi3953 3 ปีที่แล้ว

    Your explanation is awesome and very easy to understanding, Thanks .

  • @GaryThom1965
    @GaryThom1965 5 ปีที่แล้ว +5

    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))

    • @TensorProgramming
      @TensorProgramming  5 ปีที่แล้ว +5

      Yes you are absolutely correct here. I guess this was a side effect of the video being live coded.

  • @dmmm876
    @dmmm876 5 ปีที่แล้ว +1

    Fantastic video. Covered a lot of useful ground

  • @jamesdean3787
    @jamesdean3787 3 ปีที่แล้ว

    great video thank you

  • @RogerioLAguilar
    @RogerioLAguilar 4 ปีที่แล้ว +1

    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
      @TensorProgramming  4 ปีที่แล้ว

      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.

    • @shaunsawyer8298
      @shaunsawyer8298 3 ปีที่แล้ว

      @@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.

  • @jpbastyr
    @jpbastyr 4 ปีที่แล้ว +1

    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

    • @jpbastyr
      @jpbastyr 4 ปีที่แล้ว +1

      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

    • @TensorProgramming
      @TensorProgramming  4 ปีที่แล้ว +2

      @@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.

    • @rafazdeb4242
      @rafazdeb4242 3 ปีที่แล้ว

      @@jpbastyr i got the same output as you. It prints from 1 to 20.

  • @lyloft
    @lyloft 5 ปีที่แล้ว

    the output should be 20, 19 ... 1

    • @lyloft
      @lyloft 5 ปีที่แล้ว

      of the first recursion

    • @TensorProgramming
      @TensorProgramming  5 ปีที่แล้ว

      @@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.

  • @Seanomarachain
    @Seanomarachain 8 หลายเดือนก่อน

    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

    • @TensorProgramming
      @TensorProgramming  7 หลายเดือนก่อน

      Right, its the magic of editing.