From jan@swi.psy.uva.nl  Thu Dec 14 16:07:11 2000
Received: from gollem.swi.psy.uva.nl (gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA14134;
	Thu, 14 Dec 2000 16:07:11 +0100 (MET)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id QAA14930;
	Thu, 14 Dec 2000 16:07:01 +0100
Date: Thu, 14 Dec 2000 16:07:01 +0100
Message-Id: <200012141507.QAA14930@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: [SWIPL] About Applying a predicate to all the elements of alist
To: Nicos Angelopoulos <nicos@soi.city.ac.uk>,
        Jan Wielemaker <jan@swi.psy.uva.nl>
In-Reply-To: Nicos Angelopoulos's message of Thu, 14 Dec 2000 14:48:54 +0000 (GMT)
Phone: +31 - 20 - 525 6121
Cc: prolog@swi.psy.uva.nl

> 
> 
> 
> On Thu, 14 Dec 2000, Jan Wielemaker wrote:
> 
> > For those interested, using maplist doesn't make your programs faster.
> > If you are in a hurry, simply write the loop yourself.  The trouble
> > is call/3, performing a rather expensive meta-call.
> > 
> > 	--- Jan
> > 
> 
> 	alternatively one might use syntactic transformations
> 	during compile time and factor out the meta call,
> 	(term_expansion/2) 
> 
> 	the transformation is straight forward since 
> 	it doesnt depend on any other information,
> 
> 	the drawback of course is that you get
> 	extra clauses in your database and that these
> 	clauses are dynamic (due to use of assert)

Using assert is not very desirable.  term_expansion however may return
a list of clauses rather then just a simple claure.  Now the only trouble
is that the generated clauses come between the users predicate and thus
you need to use the discontiguous directive to fix this.

Alternatively you can use goal_expansion/2 and store some info in the
database on what predicates to generate and then use term_expansion on
end_of_file to generate the clauses.

None of this is really clean.  There has been a lot of discussion on
macro-expansion in Prolog ...

	Regards --- Jan

