🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1500

Re: Writing portable code.

#1500
From: Jose Alberto Fernandez R
Date: Mon, 28 Sep 1992 15:35
50 lines
2285 bytes
In article <1a3srjINNsgm@darkstar.UCSC.EDU> kjell@cse.ucsc.edu (Kjell Post) writes:

   Let me explain by an example what I'm looking for.  I want to write a
   program that works for both SICStus Prolog and Sepia.  The problem is
   that I need to retract all clauses foo/n when the program is started.
   Now, in SICStus the procedure is called retractall/2, but in Sepia it
   is retract_all/2.  That extra underscore (or absence of it) is really 
   annoying!  So I'd like to hear about efficient and portable tricks to
   write code that works in both languages.

One way to solve this is to use in the code macro commands that
expand to the right thing for each system. Assume that your
distributed source code is in files with extensions `.pli'. 
In your case, the macro definitions look something like this:

	#ifdef SEPIA
	#define RETRACTALL(x) retract_all(x)
	#else
	#define RETRACTALL(x) retractall(x)
	#endif

and in your code you use the macro RETRACTALL(x):

	...:- ..., RETRACTALL(foo(X,Y)), ....

To generate the right code, provide a makefile which contains
the following:

	PROLOG = QUINTUS
	    :
	all: list of source files with .pl extension.
	    :
	    :
	.pli.pl: 
		/lib/cpp -C -P -D$(PROLOG) $*.pli $*.pl

So if you want to generate code for SEPIA you just need to change one
line in the makefile or just do:

	make PROLOG=SEPIA

It would be nice if a facility like this would have been provided as
part of the language. Then we wouldn't need to borrow tools from 'C'.

	Jose Alberto.
--
:/       \ Jose Alberto Fernandez R | INTERNET: alberto@cs.umd.edu
:| o   o | Dept. of Computer Sc.    | BITNET: alberto@cs.umd.edu
:|   ^   | University of Maryland   | UUCP: {...}!mimsy!alberto
:\  \_/  / College Park, MD 20742   | 
Technical Details
Message-ID: <ALBERTO.92Sep28113506@karna.cs.umd.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!ames!haven.umd.edu!mimsy!mimsy.umd.edu!alberto
References: <1a3srjINNsgm@darkstar.UCSC.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!ames!haven.umd.edu!mimsy!mimsy.umd.edu!alberto
From: alberto@cs.umd.edu (Jose Alberto Fernandez R)
Newsgroups: comp.lang.prolog
Subject: Re: Writing portable code.
Message-ID: <ALBERTO.92Sep28113506@karna.cs.umd.edu>
Date: 28 Sep 92 15:35:06 GMT
References: <1a3srjINNsgm@darkstar.UCSC.EDU>
Sender: news@mimsy.umd.edu
Organization: University of Maryland Computer Sc.
Lines: 50
In-reply-to: kjell@cse.ucsc.edu's message of 27 Sep 92 08:54:11 GMT