[erlang-questions] Erlang and syntax.

Siraaj Khandkar siraaj@REDACTED
Tue Feb 25 00:38:43 CET 2014


On 2/23/14, 4:35 PM, Richard A. O'Keefe wrote:
> 
> On 23/02/2014, at 12:58 AM, Vlad Dumitrescu wrote:
>> On 22 Feb 2014 12:43, "Anthony Ramine" <n.oxyde@REDACTED> wrote:
>>>
>>> Erlang is made to be boring. Boring means that it needs to be brain dead easy to comprehend. Brain dead easy means no macros.
>>
>> Sorry, but -define () macros can be just as confusing as lispy ones... I would gladly trade them away.
> 
> Don't forget: Erlang had been around and useful for some time
> before the preprocessor was added.
> 
> I used to love the Lisp family.
> But it's not the only functional syntax.
> There are functional languages that make Perl look beautiful
> (O'CAML and F#: I'm thinking of you).
> There's SML, which would be pretty neat if it had list
> comprehensions.  (Hello, SML?  This is the 21st century
> calling!  We have something like list comprehensions in C#.
> Isn't it about time you caught up?)
> There's Haskell and Clean.
> Compare
> 
>    ;; Scheme
> 
>    (define (dot Xs Ys)
>       (let loop ((Xs Xs) (Ys Ys) (S 0))
>         (if (and (pair? Xs) (pair? Ys))
>             (loop (cdr Xs) (cdr Ys) (+ S (* (car Xs) (car Ys))))
>             S)))
> 
>    -- Haskell
> 
>    dot xs ys = loop xs ys 0
>      where loop (x:xs) (y:ys) s = loop xs ys (s+x*y)
>            loop _      _      s = s
> 
>    %% Erlang
> 
>    dot(Xs, Ys) ->
>        loop(Xs, Ys, 0).
> 
>    loop([X|Xs], [Y|Ys], S) ->
>        loop(Xs, Ys, S + X*Y);
>    loop(_, _, S) ->
>        S.

I fail to see the ugliness in:

  let dot xs ys =
    let rec loop = function
      | x::xs, y::ys, s -> loop (xs, ys, s + x * y)
      |     _,     _, s -> s
    in
    loop (xs, ys, 0)


> 
> Does anyone else remember my proposal that would have had us
> write this as
> 
>    dot(Xs, Ys) ->
>      (S where S = 0 then S+X*Y || X <- Xs & Y <- Ys).

Where is S coming from here?


> 
> Historically, Prolog -> Strand-88 -> Erlang.
> I still don't understand why Erlang uses band bor bnot bsl bsr
> instead of Prolog's /\ \/ \ << >> (I understand why it can't
> _now_) and why Erlang reversed the sense of == and =:=.
> 
> Erlang's syntax hits a "familiarity" sweet spot:
>  - it uses infix operators like Pascal/C/Javascript
>    (unlike Lisp)
>  - it uses f(X, Y, Z) function calls like Pascal/C/Javascript
>    (unlike Haskell)
>  - it uses = for binding a value to a variable, which looks
>    a bit like assignment to a C/Javascript programmer
> 
> Or rather, it _did_ hit a sweet spot before records and
> the preprocessor were added.  Even then, the preprocessor
> is aimed squarely at C programmers.  -define macros may
> be (heck, they _are_) even more confusing than lispy ones,
> but they are confusing in a comfortingly familiar way.



More information about the erlang-questions mailing list