file i/o 
Author Message
 file i/o

hi, i'm pretty new to prolog and i can't get this to work :(

the predicate works fine, and appends "hay" onto an inputted word
after changing the word into an array, and then prints it to a file

change( Word, Output ) :- name(Word, Array), addv( Array, Output,
Word).

addv( [ H | T ] , Output, Word  ) :- vowel(H),
                             append( [H|T], [104, 97, 121], Array),
                             name(Output, Array),
                             tell(file) , write('lookup(') , write(Word) ,
                             write(',') , write(Output) , write(').') ,
                             nl , told.

so it writes "lookup(test, estay)." into a file

i need it to append the input to the end of the file, but it
overwrites the
whole file instead. any ideas?

thanks,
        declan



Sun, 06 Jun 2004 14:37:19 GMT  
 file i/o

Quote:
> hi, i'm pretty new to prolog and i can't get this to work :(

> the predicate works fine, and appends "hay" onto an inputted word
> after changing the word into an array, and then prints it to a file

> change( Word, Output ) :- name(Word, Array), addv( Array, Output,
> Word).

> addv( [ H | T ] , Output, Word  ) :- vowel(H),
>                              append( [H|T], [104, 97, 121], Array),
>                              name(Output, Array),
>      tell(file) , write('lookup(') , write(Word) ,
>      write(',') , write(Output) , write(').') ,
>                              nl , told.

> so it writes "lookup(test, estay)." into a file

> i need it to append the input to the end of the file, but it
> overwrites the
> whole file instead. any ideas?

> thanks,
>         declan

Try putting "tell" and "told" elsewhere.
Something like this :

change2( Word, Output ) :-
    tell( file ),
    write_everything( Word, Output ),
    told.

You need to define "write_everything/2".
It should not contain "tell" and "told".

You can test "write_everything/2" on its own,
before you test "change2".

Also there should be a way to append to file
instead of overwriting the file.
I think the word you need to use to do this
is called something like "file_open" or "open_file", I don't remember.
Look in the documentation for your variety of prolog.

--
Martin Sondergaard.



Thu, 17 Jun 2004 00:29:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. File Conversion with File Manager on Huge files

2. DOS File Lookup - just the file name, not the path AND file name

3. How can I know the .EXE file name, file date, file size

4. files, temp files, and file-like objects

5. (VA 4.02b) using long file names for Envy file attachments

6. Comparing 2 files to create a third file

7. searching one file using the contents of another file

8. Parsing CSV file outputting desired information into multiple unique files

9. Substituting :: for __ in every htm file, and rename htlml file

10. newbie would like to break input file and output to separate files

11. Merge selected columns from two different files into another file

12. Reading from input file writing to output file

 

 
Powered by phpBB® Forum Software