zzz6519003 / blog

My blog about coding
4 stars 1 forks source link

wrap up 7-lang (1) #87

Open zzz6519003 opened 7 years ago

zzz6519003 commented 7 years ago

The current “king of the hill” is object orientation, typically in the Java language. This programming paradigm has three major ideas: encapsulation, inheritance, and polymorphism.

You could actually say that prototype languages are a subset of object- oriented languages,

Your examples were often shorter and simpler than the object-oriented counterparts because you had a broader range of tools for composing programs than you did in the object-oriented paradigm.

With pure functional languages, we could not build programs with mutable state. Instead, we built monads that let us compose functions in a way that helped us structure problems as if they allowed mutable state. Haskell has do notation, supported by monads, to solve this problem.

We used the List monad to compute a Cartesian product and unlock a combination

-module(translate_service).
-export([loop/0, translate/2]).
loop() ->
receive
 end.
{From, "casa"} -> From ! "house",
loop();
{From, "blanca"} -> From ! "white",
loop();
{From, _} ->
From ! "I don't understand.", loop()
translate(To, Word) -> To ! {self(), Word}, receive
Translation -> Translation end.

The pattern match allows the programmer to quickly pick out the important pieces of the message without requiring any parsing from the programmer.

Download prolog/concat.pl
      concatenate([], List, List).
      concatenate([Head|Tail1], List, [Head|Tail2]) :-
        concatenate(Tail1, List, Tail2).

We learned that unification makes this program so powerful because it could work in three ways: testing truth, matching the left side, or matching the right side.