Erlang list comprehension, traversing two lists and excluding values
Posted
by ErJab
on Stack Overflow
See other posts from Stack Overflow
or by ErJab
Published on 2010-03-13T04:35:19Z
Indexed on
2010/03/13
4:37 UTC
Read the original article
Hit count: 441
erlang
|list-comprehension
I need to generate a set of coordinates in Erlang. Given one coordinate, say (x,y) I need to generate (x-1, y-1), (x-1, y), (x-1, y+1), (x, y-1), (x, y+1), (x+1, y-1), (x+1, y), (x+1, y+1). Basically all surrounding coordinates EXCEPT the middle coordinate (x,y). To generate all the nine coordinates, I do this currently:
[{X,Y} || X<-lists:seq(X-1,X+1), Y<-lists:seq(Y-1,Y+1)]
But this generates all the values, including (X,Y). How do I exclude (X,Y) from the list using filters in the list comprehension?
© Stack Overflow or respective owner