I want, given a list formed by A-B elements ([a-b,b-c,c-d]), check if some given element it's already in a list (which I will return), and if it's not, add any "A" or "B" element that is not in the output list yet.
I haven't really found any "easy" enough answer for me to understand yet (like, I found one with mappings and stuff I've never used nor seen).
So the output list would need to only have [a,b,c,d]
edit: what I'm trying to do is, I get called like this:
enumerate([a-b,b-c,c-d], EnumNodes, EnumArcs)
And I have to return two lists. First one gives the nodes (with this specific form:
[enum(1,a),enum(2,b),enum(3,c),enum(4,d)]
,
and second one gives the arcs (the conections) between said nodes.
So I am at the part where I "know" how to count and return items in a list, but I do not know the following:
-How to insert ONLY unique elements in a list
-How to first check if "A" is in the list, if not insert it, and then check if "B" is in the list, if not, insert it (reason for me not knowing this, I can't come with a way of invoking the rule, once it's done, twice, once for each element, each step of recursion, without making a mistake
Are you looking for a clause like this?
Use:
I think this is the sort of thing you are looking for...
Example output:
If you do a
trace
, you can see it working...