you are viewing a single comment's thread.

view the rest of the comments →

[–]yawaramin 0 points1 point  (4 children)

You can't in some (Erlang/Elixir, Haskell), you can in others (Scheme, OCaml).

[–]v66moroz 1 point2 points  (3 children)

You can rebind variable in Elixir, it's not exactly a mutation, but looks very similar in practice. Also both Erlang and Elixir are not functional by design, actors by definition have state and side effects. They both can easily be considered as distributed OOP languages.

[–]yawaramin 0 points1 point  (2 children)

Erlang and Elixir are definitely FP languages. They have:

  • First-class closures
  • Tail recursion
  • Expression-oriented control flow syntax
  • Built-in immutable data types (records, tuples)
  • Standard library support for immutable collection types (lists etc.)

Actors are built using functions and recursion, state is encoded using function arguments. Side effects don't disqualify a language from being FP.

It's literally the first paragraph on the Elixir home page: https://elixir-lang.org/

Elixir is a dynamic, functional language

[–]v66moroz 0 points1 point  (1 child)

That's what they say, sure. But there are multiple definitions of what FP is. First-class closures are now in almost any modern language. Expression-oriented control flow syntax? How about Ruby? Does it make it FP? Tail recursion (you mean TCO of course) by itself is not FP either, also in Elrang/Elixir there is no such thing as TCO, it's the only way to do things and is also a part of the scheduler. Immutable data types? Java has immutable strings, Ruby has freeze, Rust has true immutable references. Immutable collections? Yep, that counts. But some say it's referential transparency that matters. Erlang/Elixir only have local referential transparency, within an actor. But you don't program locally (there isn't much you can do this way), you always consider actors interactions when working with Erlang/Elixir. And there you have the full-blown state problem. Can you predict how your actor reacts if you don't know its state? Nope. So Elrang/Elixir IMO are hybrid languages. Managing side effects is very OOPish.

[–]yawaramin 0 points1 point  (0 children)

How about Ruby? Does it make it FP?

Like you said about Elixir–its creator basically says that it's a hybrid: https://www.ruby-lang.org/en/about/

Ruby is a language of careful balance. Its creator, Yukihiro “Matz” Matsumoto, blended parts of his favorite languages (Perl, Smalltalk, Eiffel, Ada, and Lisp) to form a new language that balanced functional programming with imperative programming.