A 1,3,7
B 4,3,9
A 7,4,5
...
What I need to do is produce output of the form:
A 1,3,7,4,5
B 4,3,9,
i.e. a list of unique #'s for each character. I figure that the best
way to parse this file would be to read a line at a time & use a DCG
to extract the character & numbers from each line. After I have
these, I need to accumulate these lists of numbers for each character
to print out after I'm done w/ the file. What's the recommended data
structure for this? In an imperative programming language, I'd use a
hashtable. For Prolog, one idea that comes to mind is a list of
pairs:
[ p('A', [ 1, 3, 7, 4, 5 ]), p('B', [ 4, 3, 9 ]) ]
I'm assuming I'd have to open up this list & reinsert an updated pair
for each character for which I find a line in the file as I'm parsing
the file. Any other suggestions?
Thanks in advance.
> For Prolog, one idea that comes to mind is a list of pairs:
>
> [ p('A', [ 1, 3, 7, 4, 5 ]), p('B', [ 4, 3, 9 ]) ]
>
> I'm assuming I'd have to open up this list & reinsert an updated pair
> for each character for which I find a line in the file as I'm parsing
> the file. Any other suggestions?
Yes - keep the lists ordered. But it is not essential.
Apart from that: go ahead with your plan. You will learn quite a bit of
Prolog while doing so.
And don't forget to post your code here !
Cheers
Bart Demoen