[mercury-users] pragma compiled_memo for compile-time tabled evaluation
André Platzer
api at gmx.de
Sat Sep 6 00:03:42 AEST 2003
Hello Mercury users!
Is there any way to extend tabled evaluation to compile-time? As far as
I understand, normal tabled evaluation memorises values computed at
run-time. On an invocation with the same arguments, then mercury reuses
those values instead of a second computation. This is very cool.
However, I wonder if there is a way to extend this idea to compile-time.
So in case of a constant function like
%% computes the number pi with a precision of 500 digits.
:- func pi_to_500_digits = string.
:- mode pi_to_500_digits = out is det.
:- pragma memo(pi_to_500_digits/0).
after compilation, the program will compute pi to 500 digits only at the
first time this constant is used, but repeat this computation for every
program run. An improvement in this situation of constant functions (or
at least functions depending upon arguments of a small finite domain)
would be to perform the respective computation only once, at
compile-time instead of repeatedly at each new program run. The compiler
would evaluate the function at compile-time and store its tabled value
instead of the machine code for performing the computation.
Of course, in case of numerical computations of different precisions and
with different operand sizes, the result may depend on the particular
machine. But the compiler could rely on the programmer to explicitly
specify something like
:- pragma compiled_memo(pi_to_500_digits/0).
if he wants compile-time tabled evaluation.
Are there any plans to include this into mercury, and is there any way
to achieve similar things with the current mercury implementation?
Storing terms with io__write/4 is not an option in case of
data-structures containing functions or predicates.
Thanks for your comments and advice
André
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list