Code Comments
Programming Forum and web based access to our favorite programming groups.I have to parse a string like this
2.London.Paris.
2 indicates the number of the cities I will have.
get_cities(0,Temp,X) :- reverse(Temp,X).
get_cities(N,Temp,X) :-
N > 0, M is N-1, get_word([],C), get_cities(M,[C | Temp],X).
get_num(N) :-
get_word([],M), number_chars(N,M).
get_word(Temp, Word) :-
get_char(C),
( C == '.' ->
reverse(Temp,Word);
(C \== '.' ->
get_word([C | Temp],Word))).
Doing this in swipl
?- see('stradario. txt'),get_num(N),get_cities(N,[],C),seen
.
Seems working now, but I have a result like this
N = 10,
C = [['R', o, m, a], ['P', a, v, i, a], ['M', i, l, a, n, o], ['B', e,
r, g, a|...], ['M', a, n, t|...], ['G', e, n|...], ['V', e|...],
['N'|...], [...|...]|...]
Yes
Why is ['R',o,m,a]?? is only the 'R' considered as a character??
I read that a string is a list of chars, so why ['a','b'] == "ab"
fails??
Thanks a lot, any stylistic/logic suggestions are welcome of course...
Post Follow-up to this messageHum writing to a file and consulting it gives troubles cities(X). X = [[_G252, o, m, a], [_G267, a, v, i, a], [_G285, i, l, a, n, o], [_G306, e, r, g, a|...], [_G285, a, n, t|...], [_G354, e, n|...], [_G375, e|...], [_G399|...], [...|...]|...] I suppose because upper letters are singleton variables, so how could I manage it keeping the upper char?
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.