[erlang-questions] List to proplist?

Richard O'Keefe ok@REDACTED
Thu Oct 30 05:13:20 CET 2008


On 30 Oct 2008, at 1:41 am, Bengt Kleberg wrote:

> Greetings,
>
> The unfold/2 below seems to take a fun.

Yes, it does.

> Many functions in the lists
> module take their fun as the first argument.

They do.  The Lisp world has a reason for this.
I'll use the (simpler) Scheme version:

    (map F Xs)
    (map F Xs Ys)
    (map F Xs Ys Zs)
    ...

In practice this impairs readability:

    (map (lambda (X)
          ....
           ....
            ...)
         (...))		; this is the list

whereas
     (map (...) (lambda (X)
       ....
        ....
         ....))
would have been easier to follow in the very common case that
the expression that yields the list is short.  In Smalltalk
one writes
	aCollection collect: [:each |
	    ....]
with the fun at the _end_, and the improvement in readability
is noteworthy.

The SML/Haskell world also has a reason for it, but a
different one:

	increase_all = map (+1)

is a function in its own right, thanks to Currying.
(It's still waiting for its list argument.)

Since Erlang doesn't have multi-arity mapping functions
and doesn't do Currying, the best place for fun arguments
would have been at the far end.

Sigh.


> For consistency it would
> perhaps be a good idea to let unfold/2 also takes the fun as its first
> argument?

So that it can be as awkward as the others?
You have a point.

Let it be so, then.




More information about the erlang-questions mailing list