func icon indicating copy to clipboard operation
func copied to clipboard

Compile limited lambda syntax into predicates

Open mndrix opened this issue 11 years ago • 1 comments

Teach library(func) how to compile a predicate defined using lambda syntax and assigned to a variable. Like,

F = \X^Y^foo(stuff,Y,X),
...

% becomes

F = func:'5ecbc7c6883139e60b5db16550e8b5fc5da0244a',
...

func:'5ecbc7c6883139e60b5db16550e8b5fc5da0244a'(X,Y) :-
    foo(stuff,Y,X).

In certain circumstances, this technique can improve performance.

However, the main goal is to give users a convenient way to define predicates that are local to a clause. Without this feature, one must create a globally unique name for the predicate and risk it being called where it wasn't intended. This approach effectively keeps the auxiliary predicate definition local to the clause that uses it.

mndrix avatar Aug 07 '14 18:08 mndrix

Be very careful about captured variables. Those work fine with library(lambda), but won't work as described above. Until that's supported, throw an exception at compile time so users know they've done something that's not supported.

mndrix avatar Aug 07 '14 18:08 mndrix