Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

List of chars
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...


Report this thread to moderator Post Follow-up to this message
Old Post
andrea
08-21-07 09:31 AM


Re: List of chars
Hum 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?


Report this thread to moderator Post Follow-up to this message
Old Post
andrea
08-21-07 09:31 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 02:27 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.