PDA

View Full Version : Linking variables file to file, Prolog


ruman29
03-11-2007, 07:52 AM
Hi,

does anyone know how to get variables to map correctly across from file to file?

I get errors for each variable when writing from file to file.

e.g. An 'X' or 'Y' in the first file writes over as '_G699' or similar.

Any one any ideas or suggestions?

thanx

Nils Pipenbrinck
03-11-2007, 09:23 AM
There aren't that much prolog users here.

You might have better luck on the usenet.

http://groups.google.de/group/comp.lang.prolog/topics

ruman29
03-11-2007, 11:25 AM
thanks

Trap D
03-11-2007, 02:27 PM
Can you post your code ?

ruman29
03-12-2007, 12:03 PM
sure.

Here is the code from the main program, reading from one file and writing to another :

write('Can i have your first name only please.'),nl,
write('> '),
read_in(Input1),
[H|T] = Input1,

open(H, 'write', K),
open('patterns.pl', 'read', P),

read(P,Term),
write(K,Term),write(K,'.'), nl(K),
read(P,Term1),
write(K,Term1),write(K,'.'),nl(K),
read(P,Term2),
write(K,Term2),write(K,'.'),nl(K),
read(P,Term3),
write(K,Term3),write(K,'.'),nl(K),
read(P,Term4),
write(K,Term4),write(K,'.'),nl(K),
read(P,Term5),
write(K,Term5),write(K,'.'),nl(K),
read(P,Term6),
write(K,Term6),write(K,'.'),nl(K),
read(P,Term7),
write(K,Term7),write(K,'.'),nl(K),

close(K),
close(P),

Here is the file being READ:

:- dynamic(pattern/1).

pattern([1,my,name,is,2], ['I',already,know,your,name,its,on,your,file,.,'Now ',please,tell,me,about,yourself,.]).

pattern([1,dream,2], [X]) :- dream(X).

pattern([what,can,you,1], ['Is',it,important,if,1,?]).

pattern([1,X,2], [Y]) :- sadfeelings(X,Y).

pattern([1,X,2], ['Please',dont,use,that,kind,of,language,.,'Its',ve ry,crude]) :- swearwords(X).

pattern([1,tomorrow,2], [X]) :- tomorrow(X).

pattern([1,X,2], ['It',is,a,beautiful,game,.,'Do',you,play,much,X,?]) :- sport(X).


And here is the problem where the variables are not binding correctly in the file being WRITTEN to.

:-dynamic pattern/1.
pattern([1, my, name, is, 2], [I, already, know, your, name, its, on, your, file, ., Now, please, tell, me, about, yourself, .]).
pattern([1, dream, 2], [_G385]):-dream(_G385).
pattern([what, can, you, 1], [Is, it, important, if, 1, ?]).
pattern([1, _G432, 2], [_G438]):-sadfeelings(_G432, _G438).
pattern([1, _G453, 2], [Please, dont, use, that, kind, of, language, ., Its, very, crude]):-swearwords(_G453).
pattern([1, tomorrow, 2], [_G509]):-tomorrow(_G509).
pattern([1, _G523, 2], [It, is, a, beautiful, game, ., Do, you, play, much, _G523, ?]):-sport(_G523).


Can you shed any light on it? Thanks

Trap D
03-14-2007, 06:07 AM
If you just want to copy files without any change you can do this :
write('Can i have your first name only please.'),nl,
write('> '),
read_in(Input1),
[H|_] = Input1,

open(H, 'write', K),
open('patterns.pl', 'read', P),

copy_stream_data(P, K),

close(K),
close(P).

ruman29
03-15-2007, 09:22 AM
thanks man it worked!!

Trap D
03-15-2007, 01:46 PM
Is-it really what you need ?
I saw this discussion : http://groups.google.de/group/comp.lang.prolog/browse_thread/thread/91f8d8d4880707dd/a0151d23c35d59fb#a0151d23c35d59fb