home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / prolog / 1668 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.3 KB

  1. Path: sparky!uunet!munnari.oz.au!goanna!ok
  2. From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
  3. Newsgroups: comp.lang.prolog
  4. Subject: Re: Time and Date in Quintus P.
  5. Summary: it's in the library
  6. Message-ID: <14396@goanna.cs.rmit.oz.au>
  7. Date: 8 Sep 92 04:31:47 GMT
  8. References: <1992Sep3.201023.6191@tom.rz.uni-passau.de>
  9. Organization: Comp Sci, RMIT, Melbourne, Australia
  10. Lines: 49
  11.  
  12. In article <1992Sep3.201023.6191@tom.rz.uni-passau.de>, baier@forwiss.uni-passau.de (Joern Baier) writes:
  13. > For an application I need the time and date in Quintus Prolog. I wrote a
  14. > small predicate date/1 but I'm not content with it, because I have to
  15. > create an extra file.
  16.  
  17. It's already in the library.
  18. Pick up a copy of the manual, and look in the index.
  19. (You do not need a paper copy of the manual, the on-line help system
  20. has all the same information.)
  21. I find, in my copy of the manual:
  22.     "date -- library package, H-122"
  23. You can also find this in the table of contents, where I find
  24.     "H.11: MIscellaneous Packages ...
  25.       H.11-2: date.{c,pl}... H-122"
  26.  
  27. The simplest method is
  28.     ?- use_module(library(date), [date/1]).
  29.     ?- date(TodaysDate).
  30.     TodaysDate = date(1992,8,9).
  31.     /* Month numbers run from 0 to 11 for compatibility with ANSI C */
  32.  
  33.  
  34. > How can I get a random number in PROLOG to create
  35. > unique file names?
  36.  
  37. It's in the library.  In fact, it's library(random).  See the "Abstracts"
  38. section in the library manual.  But if you want to generate unique file
  39. names, random numbers are not really the way to go.  You want to use whatever
  40. your operating system gives us, e.g. tmpnam() in UNIX.
  41.  
  42. > The main problem is that 'unix(system(date))' sends its output directly
  43. > to the user, regardless of the current output.
  44.  
  45. Because that is what it is supposed to do.  unix(system('command'))
  46. does exactly what system("command") would do in C, namely run the command
  47. with the command's input coming from _STANDARD_ input and the command's
  48. output going to _STANDARD_ output (not necessarily the terminal).
  49.  
  50. If you want to get the output of a command, what you want is 
  51.  
  52.     ?- use_module(library(pipe), [popen/3]).
  53.     ?- popen(date, read, Stream),
  54.        read_whatever_you_want_to_from(Stream),
  55.        close(Stream).
  56.  
  57. This is just like popen() in UNIX+C, and it's in the "abstracts" section
  58. of the library manual.
  59. -- 
  60. You can lie with statistics ... but not to a statistician.
  61.