Comment by bargainbin

Comment by bargainbin 4 hours ago

6 replies

> (mailbox = mailbox + message) is so simple!

The author did not say this at all, they barely even touched on capabilities of erlang/OTP. Their focus was on the functional syntax of Erlang.

> For instance, in head(sort(list)), will the whole list be sorted, or will the smallest element be returned?

Your point isn’t clear. The functions have a clear nested call sequence, take a list, sort it, get the head.

Also how is it any different than Haskells `head (sort list)`?

ctenb 4 hours ago

In Haskell with `head (sort list)` the entire list does not have to be sorted, depending on the sort implementation. Everything is lazy, so sort can sort the list just enough to return the smallest element.

  • auggierose 4 hours ago

    Going beyond laziness, a compiler that can understand and exploit equations, could use `head (sort list) = smallest (list)` to make the program more efficient, going from O(n * log n) to O(n) complexity.

mrkeen 3 hours ago

> The author did not say this at all, they barely even touched on capabilities of erlang/OTP.

  Two separate Erlang nodes. On different machines, different networks, different continents if I wanted. And they could just… talk. No HTTP. No REST API. No serialization headaches. Just message passing. Just actors doing their thing.
> Their focus was on the functional syntax of Erlang.

They didn't write any Erlang until the ping/pong example, which doesn't have any functions. What does pong() equal? Is it equal to itself even? What's its domain and range? If I wrote a unit test for it, what test inputs would I give it and what outputs would I assert?

  • [removed] 3 hours ago
    [deleted]
petrzjunior 4 hours ago

I think the question is whether sort should return a new, sorted array or whether it should sort the array in place. In functional languages it is the former, in imperative the latter.

  • knome 2 hours ago

    It can be quite useful to have nondestructive sorting in imperative languages as well. Hence python introducing 'sorted' even though '.sort()' preceded it.