vita nouva / diary
"The Rose Garden by Carl Aagaard"
17/01/2026

"Diary Entry - January 17, 2026"

15:35

I just disabled liquid glass from my MacOS 26 machine, and I found out that Apple includes all the old features that were removed with apple glass, see for example "compact mode" in Safari:

../i/15:35/2026-01-17_15-38-30_screenshot.png

Maybe a kind of Bug compatibility. #Apple Glass

17:17 | recursion in Scala

Avoid writing the following form of recursive functions:

def fib(n: Int): Int =
  if (n <= 1) n
  else fib(n - 1) + fib(n - 2)

This usually cause exponential time even when optimized. Imagine a call to fib(n) goes as follows:

fib(n)
├─ fib(n-1)
  ├─ fib(n-2)
  └─ fib(n-3)
└─ fib(n-2)
   ├─ fib(n-3)
   └─ fib(n-4)
  • fib(n-2) is computed twice
  • fib(n-3) is computed three times
  • fib(n-4) is computed five times

Instead, you should use a local tail-recursive helper:

def fib(n: Int): Int = {
  @annotation.tailrec
  def loop(i: Int, prev: Int, curr: Int): Int =
    if (i == 0) prev
    else loop(i - 1, curr, prev + curr)

  loop(n, 0, 1)
}

Now, something important to note here, if someone changes anything in the function call, it will break, silently. Moreover, the meaning of prev / curr isn’t obvious from the signature, which is important in functional programming; the invariant is not enforced by the type system. This is usually acceptable because:

  • loop is local → no external caller can misuse it
  • The invariant is encapsulated, not exposed
  • The outer API fib(n) remains clean and total

#Scala

17:25 | Currying

"This is named after the mathematician Haskell Curry, who discovered the principle. It was independently discovered earlier by Moses Schoenfinkel, but Schoenfinkelization didn’t catch on." Lol. #Mathematics

[permlink]
c. lr0 2025