list comprehension bug ?

Håkan Stenholm hakan.stenholm@REDACTED
Thu Jul 10 22:10:34 CEST 2003


I encountered a odd list comprehension bug (R9B-0, MacOS X 10.2.6):

[Pos || map_get(Map,Pos), Pos <- Neighbours].

results in a "variable 'Pos' is unbound" compile error, but changing 
the order of the generator and predicate makes the compile error go 
away:

[Pos || Pos <- Neighbours, map_get(Map,Pos) ].




NOTE - the full function looks like this:

%% return {X,Y} pos list (of neighboring hexes) for currently selected 
hex
neighbours(Map, {X, Y}) ->

     Neighbours = case even(X) of
                      false -> [{X,Y+1}, {X,Y-1}, {X+1,Y-1}, {X+1,Y}, 
{X-1,Y-1}, {X-1,Y} ];
                      true -> [{X,Y+1}, {X,Y-1}, {X+1,Y+1}, {X+1,Y}, 
{X-1,Y+1}, {X-1,Y} ]
                  end,
     %% --> variable 'Pos' is unbound
     %% [Pos || map_get(Map,Pos), Pos <- Neighbours].

     [Pos || Pos <- Neighbours, map_get(Map,Pos) ].




More information about the erlang-questions mailing list