🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1502

Re: Writing portable code.

#1502
From: Paul Singleton
Date: Tue, 29 Sep 1992 00:57
43 lines
1949 bytes
From article <ALBERTO.92Sep28113506@karna.cs.umd.edu>, by alberto@cs.umd.edu (Jose Alberto Fernandez R):

> 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)), ....
>... 
> 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'.

Prolog is a sufficiently wide-spectrum language that we don't need to
borrow bolt-on programming-in-the-large languages.  I think if we write

	retract_all_unit_clause( X) :-
		(	dialect( sepia)
		->	retract_all( X)
		;	dialect( sicstus)
		->	retractall( X)
		).

then add either

	dialect( sepia).
or
	dialect( sicstus).

as a fact, and partially evaluate the program, we get the effect of macro
substitution.  Isn't this a neater way of doing things?  
----
  __   __    Paul Singleton (Mr)           JANET: paul@uk.ac.keele.cs
 |__) (__    Computer Science Dept.        other: paul@cs.keele.ac.uk
 |  .  __).  Keele University, Newcastle,    tel: +44 (0)782 621111 x7355
             Staffs ST5 5BG, ENGLAND         fax: +44 (0)782 713082
Technical Details
Message-ID: <BvBEny.4M8@gabriel.keele.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!keele!news
References: <ALBERTO.92Sep28113506@karna.cs.umd.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!keele!news
From: csa09@seq1.keele.ac.uk (Paul Singleton)
Newsgroups: comp.lang.prolog
Subject: Re: Writing portable code.
Message-ID: <BvBEny.4M8@gabriel.keele.ac.uk>
Date: 29 Sep 92 00:57:33 GMT
References: <ALBERTO.92Sep28113506@karna.cs.umd.edu>
Sender: news@gabriel.keele.ac.uk (UseNet News Service)
Organization: Keele University, England
Lines: 43
Nntp-Posting-Host: seq1.cc.keele.ac.uk