[m-dev.] Partial evaluation

Ralph Becket rbeck at microsoft.com
Tue Oct 24 04:14:28 AEDT 2000


How does one set about finding out what sorts of constant expressions
get evaluated at compile time or `just once' at run time?  One assumes
that constant integer and float arithmetic expressions are pre-computed
by the compiler.  What about other things?

For example, at the moment I'm having trouble getting the fact table
stuff to work (I think it's a bug - I've sent in a report).  I have
a largish set of integer pairs (ooh, at least 450 of them) that I wish 
to do fast lookups on:

:- pred edge(int::in, int::in) is semidet.
edge(1, 2).
edge(1, 7).
edge(1, 28).
...

This approach takes *forever* to compile and the compiler runs out
of memory in the debugging grades.

I've been considering recasting this as an array of arrays:

edge(X, Y) :- binary_search(lookup(edges, X - 1), Y) = yes(_).

:- func edges = array(array(int)).
edges = array([
/* row 1 */ array([...]),
/* row 2 */ array([...]),
...
]).

but I have a sneaky suspicion that this would be the worst
possible solution at the moment.  It just occurred to me that
pragma memoing edges/0 might do the trick.

What would the Mercury black-belts out there do?

Ralph

--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list