🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1426

Re: Compiler smartness?

#1426
From: Neng Fa Zhou
Date: Tue, 20 Nov 1990 05:59
51 lines
1988 bytes
In article <DOWDING.90Nov16140150@palm.ai.sri.com> dowding@ai.sri.com (John Dowding) writes:

> I was poking around in some old code, and came across the following
> clauses (names changed to protect the inocent):
> 
> foo(Term, Term):-
> 	  (var(Term) ; atomic(Term)),
> 	  !.
> foo([Head|Tail], Result):-
> 	  ...
> 
> 
> I was wondering if the following is more efficient:
> 
> foo(Term, Term):-
> 	  var(Term),
> 	  !.
> foo(Term, Term):-
> 	  atomic(Term),
> 	  !.
> foo([Head|Tail], Result):-
> 	  ...

Yes, it is more efficient than the original one.

> 
> Are Prolog compilers (particularly, Quintus version 2.4) smart enough 
> index correctly on the 1st argument in either or both of these cases?
>

 The compiler for the TOAM is smart enough to compile this program to 
efficient code. The compiler first infers modes for a program, then 
transforms the program to a canonical form based on the inferred modes.
Suppose [d,f] is the mode of foo/2, the canonical form of the predicate is

 foo(Term, NewTerm):-
 	  var(Term),
 	  !,
	  NewTerm = Term.
 foo(Term, NewTerm):-
 	  atomic(Term),
 	  !,
	  NewTerm = Term.
 foo([Head|Tail], Result):-
 	  ...

The code of this canonical form is efficient because (1) no choice point will
be created, and (2) it does not contain instructions for the cuts.

Neng-Fa Zhou 
Kyushu University 
Technical Details
Message-ID: <ZHOU.90Nov20145919@hiromi.csce.kyushu-u.junet>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!ccut!kyu-cs!nodoka.csce.kyushu-u!zhou
References: <DOWDING.90Nov16140150@palm.ai.sri.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!ccut!kyu-cs!nodoka.csce.kyushu-u!zhou
From: zhou@hiromi.csce.kyushu-u.junet (Neng Fa Zhou)
Newsgroups: comp.lang.prolog
Subject: Re: Compiler smartness?
Message-ID: <ZHOU.90Nov20145919@hiromi.csce.kyushu-u.junet>
Date: 20 Nov 90 05:59:19 GMT
References: <DOWDING.90Nov16140150@palm.ai.sri.com>
Sender: zhou@hiromi.csce.kyushu-u.ac.jp
Distribution: comp
Organization: Dept. of Comp. Sci. and Comm. Eng., Kyushu Univ., Fukuoka, Japan
Lines: 51
In-reply-to: dowding@ai.sri.com's message of 16 Nov 90 22:01:50 GMT