Prolog, (or XSB) can be useful for writing scripts in a UNIX system. Prolog's simple syntax and declarative semantics make it especially suitable for scripts that involve text processing. Wherever noted, some of these functions are currently working under Unix only.
Unifies Date to the current date, returned as a Prolog term, suitable for term comparison. Currently this only works under Unix, is slow, and should be rewritten in C using time() and localtime().
Example:
> date Thu Feb 20 08:46:08 EST 1997 > xsb -i XSB Version 1.7 [sequential, single word, optimal mode] | ?- [scrptutl]. [scrptutl loaded] yes | ?- date(D). D = date(1997,1,20,8,47,41) yes
This predicate is obsolete and datime/1
, defined in
standard, should be used instead.
Returns file's modification time. Because XSB steals 5 bits from each word, time must be returned as two words: Time1, representing the most significant digits, and Time2, representing the less significant digits.
Returns file size.
Unifies Directory with a list of files in the directory specified by path. Information about the files is similar to that obtained by ls -l, but transformed for ease of processing. This currently works for Unix only, is slow, and should be reimplemented in C using opendir() and readdir().
Expands the file name passed as the first argument and binds the variable in the second argument to the expanded name. This includes expanding Unix tildas, prepending the current directory, etc. In addition, the expanded file name is ``rectified'' so that multiple repeated slashes are replaced with a single slash, the intervening ``./'' are removed, and ``../'' are applied so that the preceding item in the path name is deleted. For instance, if the current directory is /home, then abc//cde/..///ff/./b will be converted into /home/abc/ff/b.
Under Windows, this predicates does rectification (using backslashes when appropriate), but it does not expand the tildas.
For instance, john///doe/dir1//../foo.bar will be parsed into: /home/john/doe/, foo, and bar (where we assume that /home/john is what john expands into).
ads sdfdsfd ee 112 444 4555then
| ?- file_to_list(10, L). L = [[ads,sdfdsfd,ee],[112,444],[4555]] yesNote: file_to_list/2 does not close the I/O port, so it is an application program responsibility.
In addition, the module file_io provides the following unified interface to the operations on files. All these calls succeed iff the corresponding system call succeeds.