[erlang-questions] Extensions to comprehensions eeps

Richard A. O'Keefe ok@REDACTED
Fri Aug 1 01:57:20 CEST 2008


On 31 Jul 2008, at 7:40 pm, Hynek Vychodil wrote:
> > 1/2.
> 0.5
> > 1 div 2.
> 0
>
> There is functional difference,

True.  The difference in this case is in the range of
the function, rather than the domain.

A better example would have been

     atom_to_list/1
     integer_to_list/1
     float_to_list/1

These COULD all be done by one

     constant_to_list/1

function.

> between <- and <= is not functional difference.

Wrong.

>
> There is not [sic.] reason why
>
> [X || <<X>> <- <<"abc">> ].
>
> should not return same [sic.] result as
>
>  > [X || <<X>> <= <<"abc">> ].
> "abc"
>
Wrong, at least in general.
The thing is that a list HAS certain elements
whatever pattern one chooses to match against
them.  A binary or bitstring does not.

The number of bits chopped off at each iteration
DEPENDS ON THE PATTERN.  But the number of list
elements chopped off at each iteration does NOT
depend on the pattern at all.

This is a fundamental difference in the semantics
of <- and <=; it is not simply a matter of enumerating
list elements in one case and bytes in the other.


Arguably the distinction between list element
enumeration and tuple element enumeration IS one
that could be handled at run time, at least for
a sufficiently inefficient implementation, but
an *efficient* implementation, you really do need
different code.





More information about the erlang-questions mailing list