Jump to content


Linking variables file to file, Prolog


7 replies to this topic

#1 ruman29

    New Member

  • Members
  • Pip
  • 8 posts

Posted 11 March 2007 - 02:52 PM

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

#2 Nils Pipenbrinck

    Senior Member

  • Members
  • PipPipPipPip
  • 597 posts

Posted 11 March 2007 - 04:23 PM

There aren't that much prolog users here.

You might have better luck on the usenet.

http://groups.google...g.prolog/topics
My music: http://myspace.com/planetarchh <-- my music

My stuff: torus.untergrund.net <-- some diy electronic stuff and more.

#3 ruman29

    New Member

  • Members
  • Pip
  • 8 posts

Posted 11 March 2007 - 06:25 PM

thanks

#4 Trap D

    Member

  • Members
  • PipPip
  • 55 posts

Posted 11 March 2007 - 09:27 PM

Can you post your code ?

#5 ruman29

    New Member

  • Members
  • Pip
  • 8 posts

Posted 12 March 2007 - 07: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',very,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

#6 Trap D

    Member

  • Members
  • PipPip
  • 55 posts

Posted 14 March 2007 - 01:07 PM

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).


#7 ruman29

    New Member

  • Members
  • Pip
  • 8 posts

Posted 15 March 2007 - 04:22 PM

thanks man it worked!!

#8 Trap D

    Member

  • Members
  • PipPip
  • 55 posts

Posted 15 March 2007 - 08:46 PM

Is-it really what you need ?
I saw this discussion : http://groups.google...0151d23c35d59fb





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users