[erlang-questions] Trying to learn the Erlang Way

Richard A. O'Keefe ok@REDACTED
Mon Feb 10 05:59:53 CET 2014


On 8/02/2014, at 4:53 AM, kraythe . wrote:
> Anyway back to the subject at hand. The algorithm is set but now I am at another quandary Lets say these vectors represent a position in space of particular objects in a simulation. The process of culling the vectors based on the sphere is entirely a vector problem but what the user calling cull/3 really needs to know is which objects are not culled from the list, not just which vectors are not culled. Now in Java I could do a number of things if I wanted to keep the cull algorithm as it is. I could return the list of integers containing the original indexes of the vectors in the list that were culled and use that to filter out which objects need to be considered for the simulation step.

The word "cull" really grates.

And all those negations *really* confused me *all over again*.
I wrote a lengthy and helpful description of how to get the
points that were accepted and the points that were rejected
as two lists, because that was the only way I could interpret
your question to make sense in Erlang.  But on repeated re-reading
it became clear that you were asking for something else.

There is no such thing in Erlang as object identity.
The distinction you are drawing between the "points" and the
"objects" simply doesn't exist.

It so happens that if you use a list comprehension like
	[P || P <- Points, some_predicate(P)]
the elements of the result *will* be (references to) the same
implementation-level webs of chunks of memory that were in the
original list, not copies.  But nothing other than performance
depends on this.

A list of integers such as you ask for could be obtained, but it
would be very little use to you, because Erlang lists are *LINKED
LISTS*, not *INDEXED ARRAYS*.   Finding the nth element of a list
takes O(n) time, and that could not be changed without making
lists much less useful.





More information about the erlang-questions mailing list