🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.prolog
5 messages
5 total messages Started by Joern Baier Thu, 03 Sep 1992 20:10
Time and Date in Quintus P.
#766
Author: Joern Baier
Date: Thu, 03 Sep 1992 20:10
54 lines
2192 bytes
Hi!

For an application I need the time and date in Quintus Prolog. I wrote a
small predicate date/1 but I'm not content with it, because I have to
create an extra file. How can I get a random number in PROLOG to create
unique file names?
The main problem is that 'unix(system(date))' sends its output directly
to the user, regardless of the current output.
 
I enclose the protocol of a session below.

Thanx in advance,
			Joern
-------------------------------Cut here!------------------------------
gandalf:~/prolog/dp 103> prolog

Quintus Prolog Release 2.5.1 (DECstation 3100, Ultrix 3.1)
Copyright (C) 1990, Quintus Computer Systems, Inc.  All rights reserved.
1310 Villa Street, Mountain View, California  (415) 965-7700

| ?-  tell(test_2),current_output(O),unix(system(date)),told.
Thu Sep  3 22:01:06 MET DST 1992

O = '$stream'(35,3) 

| ?- [system].
[consulting /home/forwiss/baier/prolog/dp/system.pl...]
...
 [consulting /private/projects/quintus/generic/qplib2.5.1/library/readin.pl...]
 [readin.pl consulted in module read_in 0.200 sec 2,844 bytes]
[system.pl consulted in module system 2.000 sec 40,736 bytes]

yes
| ?- listing(date).

system:(date(A) :-
        tell('________Datum_Uhrzeit'),
        told,
        unix(system('date > ________Datum_Uhrzeit')),
        open('________Datum_Uhrzeit',read,B),
        set_input(B),
        read_in(A),
        close(B).

yes
| ?- date(Date).

Date = [thu,sep,3,21,:,56,:,52,met,dst,1992,''] 
----------------------------Cut again!------------------------------------
-- 
Joern Baier     (baier@forwiss.uni-passau.de) 
Jesuitengasse 9 	   __o
D-W8390 Passau 		 _ \<,_
Tel +49/851/35239 	(_)/ (_)
Re: Time and Date in Quintus P.
#769
Author: David I Schwartz
Date: Thu, 03 Sep 1992 23:04
28 lines
1627 bytes
In article <1992Sep3.201023.6191@tom.rz.uni-passau.de>, baier@forwiss.uni-passau.de (Joern Baier) writes...
>Hi!
> 
>For an application I need the time and date in Quintus Prolog. I wrote a
>small predicate date/1 but I'm not content with it, because I have to
>create an extra file. How can I get a random number in PROLOG to create
>unique file names?
>The main problem is that 'unix(system(date))' sends its output directly
>to the user, regardless of the current output.
> 
>I enclose the protocol of a session below.
> 
>Thanx in advance,
>			Joern
>-------------------------------Cut here!------------------------------
>gandalf:~/prolog/dp 103> prolog
> 
>Quintus Prolog Release 2.5.1 (DECstation 3100, Ultrix 3.1)
>| ?-  tell(test_2),current_output(O),unix(system(date)),told.
>Thu Sep  3 22:01:06 MET DST 1992
> 

Check out your library files. In version 3.1.1, there are predicates for 
dates (date.pl) and random number generators (random.pl). I think these
may be in your directory already. You'll have to look in these library
files to see which predicates you'll need.

Dave
Re: Time and Date in Quintus P.
#777
Author: Joern Baier
Date: Fri, 04 Sep 1992 18:53
58 lines
2708 bytes
In article <Bu0yr6.LAC@acsu.buffalo.edu> v104n55k@ubvmsd.cc.buffalo.edu (David I Schwartz) writes:
>[...]
>Check out your library files. In version 3.1.1, there are predicates for 
>dates (date.pl) and random number generators (random.pl). I think these
>may be in your directory already. You'll have to look in these library
>files to see which predicates you'll need.
Yes, I found both files in the library. Thank you (and Fernando Pereira who
answered by mail)!
The random number generator works fine but the consulting of 'date.pl'
wasn't successful:

----------------------------------------------------------------------
gandalf:~/prolog/dp 104> prolog

Quintus Prolog Release 2.5.1 (DECstation 3100, Ultrix 3.1)
Copyright (C) 1990, Quintus Computer Systems, Inc.  All rights reserved.
1310 Villa Street, Mountain View, California  (415) 965-7700

| ?- [library(date)].
[consulting /private/projects/quintus/generic/qplib2.5.1/library/date.pl...]
 [consulting /private/projects/quintus/generic/qplib2.5.1/library/errno.pl...]
 [errno.pl consulted in module errno 0.500 sec 11,884 bytes]
ld:
Undefined:
gmtime
localtime
[ERROR: Foreign interface, call to Unix "ld" failed (error 413)]
 [Loading of foreign files NOT completed]
[date.pl consulted in module date 1.333 sec 22,508 bytes]

yes
| ?-
----------------------------------------------------------------------

Then I tried to compile 'date.c' directly:

----------------------------------------------------------------------
gandalf:~/prolog/dp/date 111> gcc date.c
date.c: In function `QD4mat':
date.c:358: warning: suggest parentheses around && within ||
ld:
Undefined:
main
QP_atom_from_string
collect: /usr/bin/ld returned 1 exit status
----------------------------------------------------------------------

It seems that 'QP_atom_from_string' is not defined.

What might help???

Thanx in advance and have a nice weekend,
			Joern
-- 
Joern Baier     (baier@forwiss.uni-passau.de) 
Jesuitengasse 9 	   __o
D-W8390 Passau 		 _ \<,_
Tel +49/851/35239 	(_)/ (_)
Re: Time and Date in Quintus P.
#690
Author: Richard A. O'Keefe
Date: Tue, 08 Sep 1992 04:31
49 lines
2403 bytes
In article <1992Sep3.201023.6191@tom.rz.uni-passau.de>, baier@forwiss.uni-passau.de (Joern Baier) writes:
> For an application I need the time and date in Quintus Prolog. I wrote a
> small predicate date/1 but I'm not content with it, because I have to
> create an extra file.

It's already in the library.
Pick up a copy of the manual, and look in the index.
(You do not need a paper copy of the manual, the on-line help system
has all the same information.)
I find, in my copy of the manual:
	"date -- library package, H-122"
You can also find this in the table of contents, where I find
	"H.11: MIscellaneous Packages ...
	  H.11-2: date.{c,pl}... H-122"

The simplest method is
	?- use_module(library(date), [date/1]).
	?- date(TodaysDate).
	TodaysDate = date(1992,8,9).
	/* Month numbers run from 0 to 11 for compatibility with ANSI C */


> How can I get a random number in PROLOG to create
> unique file names?

It's in the library.  In fact, it's library(random).  See the "Abstracts"
section in the library manual.  But if you want to generate unique file
names, random numbers are not really the way to go.  You want to use whatever
your operating system gives us, e.g. tmpnam() in UNIX.

> The main problem is that 'unix(system(date))' sends its output directly
> to the user, regardless of the current output.

Because that is what it is supposed to do.  unix(system('command'))
does exactly what system("command") would do in C, namely run the command
with the command's input coming from _STANDARD_ input and the command's
output going to _STANDARD_ output (not necessarily the terminal).

If you want to get the output of a command, what you want is 

	?- use_module(library(pipe), [popen/3]).
	?- popen(date, read, Stream),
	   read_whatever_you_want_to_from(Stream),
	   close(Stream).

This is just like popen() in UNIX+C, and it's in the "abstracts" section
of the library manual.
-- 
You can lie with statistics ... but not to a statistician.
Re: Time and Date in Quintus P.
#691
Author: Richard A. O'Keefe
Date: Tue, 08 Sep 1992 04:42
47 lines
2393 bytes
In article <1992Sep4.185308.12558@tom.rz.uni-passau.de>, baier@forwiss.uni-passau.de (Joern Baier) writes:
: gandalf:~/prolog/dp 104> prolog
: | ?- [library(date)].
: [consulting /private/projects/quintus/generic/qplib2.5.1/library/date.pl...]
:  [consulting /private/projects/quintus/generic/qplib2.5.1/library/errno.pl...]
:  [errno.pl consulted in module errno 0.500 sec 11,884 bytes]
: ld:
: Undefined:
: gmtime
: localtime
: [ERROR: Foreign interface, call to Unix "ld" failed (error 413)]
:  [Loading of foreign files NOT completed]
: [date.pl consulted in module date 1.333 sec 22,508 bytes]
: 
You have a serious problem there, because gmtime() and localtime() are
UNIX library functions.  More than that, they are required by the ANSI
C standard.  The linker should have found them.  You will need to check
that QP has been installed correctly, and especially to verify that ld
is being called with the correct command-line arguments.

: ----------------------------------------------------------------------
: gandalf:~/prolog/dp/date 111> gcc date.c

You do not want a complete program.  You want a ".o" (object, linkable)
file.  For that, the correct command is
	gcc -c date.c
	    ^^
: date.c: In function `QD4mat':
: date.c:358: warning: suggest parentheses around && within ||
Sheesh.  Does it also say "suggest parentheses around * within +"?
Ignore that message.
: ld:
: Undefined:
: main
: QP_atom_from_string
: collect: /usr/bin/ld returned 1 exit status

: It seems that 'QP_atom_from_string' is not defined.

Yes it is.  It is defined in the Quintus Prolog system itself.
The *.c files in the library area are _not_ meant to be compiled as
separate programs, but as ".o" files which will later be linked with
the Prolog system (either statically, if you so choose when using qpc,
or dynamically, if you use load_foreign_files).  Just add the "-c" option.

-- 
You can lie with statistics ... but not to a statistician.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads