News for hackers. Stuff that matters.
Re:Functional programming languages should be better at muta... by nine_k on Tuesday July 30, 2024 @08:18PM (#41115371)
The standard way to expel stated mutable state us to push it into function parameters and returned values.

With Fibonacci numbers, you cab just compute two if them outright:

  def fib_(n: int) -> tuple[int, int]:
    if n == 0:
      return (1, 1)
    prev, this = fib_(n - 1)
    return (this, this + prev)

  def fib(n): return fib_(n)[0]
Now there is no mutable state that survives between function calls, the performance is linear.

With true memoization though accessing a previously computed value.would be constant time.

Re:Functional programming languages should be better at muta... by narski on Tuesday July 30, 2024 @09:57PM (#41115825)
>The standard way to expel stated mutable state us to push it into function parameters and returned values.

This is precisely what I did in my Hoon solution :) However, I wasn't aware that this approach is the standard way, and I'm glad to have learned that! Thanks