[mercury-users] Higher order (was The Logic of Mercury)

Richard A. O'Keefe ok at hermes.otago.ac.nz
Fri Sep 10 09:18:22 AEST 1999


	For example, the
	builtin version of call/1 in Prolog has to deal with conjunctions
	containing cuts.  A user-defined version which doesn't deal with cuts is
	faster in most systems.
	
Lee may be referring to something like

caul(p(X,Y,Z)) :- p(X, Y, Z).
...
caul(q(X,Y))   :- q(X, Y).

where p/3, ..., q/2 are the predicates you intend to call this way.

The funny thing is that the same technique *could* be used by the
implementation:

    call(X) :-
        (   callable(X) -> call1(X)
        ;   must_be_callable(X, 1, call(X))
        ).

    call1(true).
    call1(fail) :- fail.
    call1((X,Y)) :- call2((X,Y)).
    ...
    call1(\+(X)) :- call2(\+(X)).

and then one
   
    call1(p(X,Y,Z)) :- p(X, Y, Z).

clause for each defined predicate.  The real issue is that call/1 has to
do additional things that caul/1 does not:  detect and report calls to
unbound variables, numbers, and undefined predicates, maintain depth and
call number for debugging, ...

The important thing in this thread is that stashing a token in a data
structure instead of stashing a closure doesn't help.  In fact, it can
make things worse.

Why doesn't it help?  Because the token that gets stashed *is* a closure.
A built in closure would have to identify what code to call and what
presupplied arguments to provide.  The token must provide the same
information; it is simply a different *representation* for a closure.

How can it make things worse?  Because a really smart optimizer might be
able to track *something* about closures that are stashed in data structures,
but it wouldn't understand that a programmer-designed token was a closure,
and would miss the reference.
--------------------------------------------------------------------------
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