Why Erlang is the best concurrent language available

Luke Gorrie <>
Fri Jan 24 15:42:28 CET 2003

Luke Gorrie <> writes:

> Consider the implementation of 'map' from lists.erl:
>   map(F, [H|T]) ->
>       [F(H)|map(F, T)];
>   map(_, []) -> [].

BTW, here's another style of writing those functions, which I find
completely impenetrable :-). It's a grand-unified backend for the
various types of map functions, from the list module of a Lisp system
I've been playing with:

  (defun map1 (function original-arglists accumulate take-car)
    "This function is called by mapc, mapcar, mapcan, mapl, maplist, and mapcon.
    It Maps function over the arglists in the appropriate way. It is done when any
    of the arglists runs out.  Until then, it CDRs down the arglists calling the
    function and accumulating results as desired."

    (let* ((arglists (copy-list original-arglists))
           (ret-list (list nil)) 
           (temp ret-list))
      (do ((res nil)
           (args '() '()))
          ((dolist (x arglists nil) (if (null x) (return t)))
           (if accumulate
               (cdr ret-list)
               (car original-arglists)))
        (do ((l arglists (cdr l)))
            ((null l))
          (push (if take-car (caar l) (car l)) args)
          (setf (car l) (cdar l)))
        (setq res (apply function (nreverse args)))
        (case accumulate
          (:nconc (setq temp (last (nconc temp res))))
          (:list (rplacd temp (list res))
                 (setq temp (cdr temp)))))))

I really prefer the Erlang style, even if you need to write each
function separately :-)


More information about the erlang-questions mailing list