Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!info.ucla.edu!ihnp4.ucsd.edu!munnari.OZ.AU!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: Generating Prolog source code.
Message-ID: <9602911.317@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <4e7hem$e1a@goanna.cs.rmit.EDU.AU>
Date: Mon, 29 Jan 1996 00:42:55 GMT
Lines: 56

ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe) writes:

>In a great many cases, composition from higher order fragments followed by
>partial execution does the trick nicely.
>
>However, some of the things I want to try involve
>    - variable numbers of clauses
>    - variable numbers of conjuncts/disjuncts/if-then-parts
>    - variable numbers of arguments in goals
>or the like.

It seems to me that these can all fit in the framework of higher order
code and partial evaluation.  You just need a sufficiently good
partial evaluator.

For example, variable numbers of arguments in goals can be handled
by passing a list; if the partial evaluator notices that the list
is always the same length, then it can use a separate argument
for each list element.  

If you need variable numbers of clauses, write the code recursively, or
using a higher-order predicate disj/1 that takes a list of goals and
evaluates their disjunction.

	disj([X|Xs]) :- call(X) ; disj(Xs).

If the partial evaluator notices that the argument to disj/1 is
always of the same length, then it can fully unfold such calls.

Now, if your next question is "where can I get such a partial evaluator?",
I'm afraid I don't have a good answer for you.

>    integer(K), K > 0,
>    N is 1 << K,
>    M is N - 1,
>    length(Xs, N),
>    length(Ys, N),
>    [_|Zs] = Xs,
[...]
>        (radb`K`''(Input, Offset, Output) :-
>            radb`K`''(Input, Offset, Output, for(memb(Zs, Z), [Z, Z]), [])),

You could write this instead as

        radb(K, Input, Offset, Output) :-
		N is 1 << K,
		length([_|Zs], N),
		for(List, memb(Zs, Z), [Z, Z]),
		radb(Input, Offset, Output, List, []).

and rely on your partial evaluator to optimize this in the case
when K is known at compile time.

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3
