and-ing, or-ing?
chris.danx
chris.danx@REDACTED
Sun May 18 19:16:28 CEST 2003
Hi,
How do you "and" two truth states? In the following "addEdge" function
It is supposed to add an edge if and only if both vertices exist... the
function existsVertex is defined to return true if a vertex exists in a
given graph.
%% return true if given vertex is in the graph.
%%
existsVertex(N, {graph, []}) ->
false;
existsVertex(N, {graph, [{N,Y}|Xs]}) ->
true;
existsVertex(N, {graph, [_|Xs]}) ->
existsVertex (N, {graph, Xs}).
%% create connection between given vertices
%%
addEdge (N, M, {graph, []}) ->
nil;
addEdge (N, M, {graph, L}) ->
bothExist = ???
if bothExist ->
{graph, []};
true ->
{error, {graph, L}}
end.
It's not complete yet, the return values are just temporary until I
figure out how to check the vertices exist...
Cheers,
Chris
p.s. I might add a function which returns an existing {vertex, [edge]}
tuple to make it more efficient, but for now I'm keeping it simple.
More information about the erlang-questions
mailing list