Subject: Re: [SWIPL] About Applying a predicate to all the elements of alist

From: Jan Wielemaker <[email-masked]>
Date: Thu, 14 Dec 2000 16:07:01 +0100

> 
> 
> 
> 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