File operations

Description

Simple program to file operations

Source: PrologTutorial (on-line tutorial)

Download

Program source code: file_operations.pl

Listing

/* prolog  tutorial  2.10 */
 
browse :- 
        seeing(Old),      /* save for later */ 
        see(user), 
        write('Enter name of file to browse: '), read(File), 
        see(File),        /* open this file */ 
        repeat, 
        read(Data),       /* read from File */ 
        process(Data),    
        seen,             /* close File */ 
        see(Old),          /*  previous read source */ 
        !.                /* stop now */ 
 
process(end_of_file) :- !. 
process(Data) :-  write(Data), write('.'), nl, fail. 
 
 
my_save(ToFile) :-      
       telling(Old),      /* current write output */ 
       tell(ToFile),      /* open this file */ 
       listing,           /* list all clauses in memory */ 
       told,              /* close ToFile */ 
       tell(Old).         /* resume this output */ 

Comments

pl/prolog/pllib/file_operations.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0