Implementing Custom Arithmetic Functions

How can I add a function (e.g. hammingweight) and use it in the expressions on the right side, is this some purpose (is)/2?

Is there something like a goal_expansion or term_expansion function here?

I admit that this is not a big feature, but it can increase the readability of some of my Prolog programs.

Writing a custom predicate (is)/2(implementing a specialized expression evaluator) is feasible, but I would like the runtime overhead to be low, since I don't want to sacrifice the readability of service resources at runtime.

+4
source share
3

ISO Prolog , (is)/2 . , , , . , (my_is)/2 .

, (is)/2, , . , (8.7 ) (. ).

+2

(~ 20 LOC) , lifter, goal_expansion.

longer(A,B) :-
    length(A,ΒΊ) > length(B,ΒΊ).

longer(A, B) :-
    length(A, C),
    length(B, D),
    C > D.
+2

Logtalk, Prolog (*). Logtalk Prolog Prolog. , , , , source.pl term_expansion/2 goal_expansion/2 expansions.pl, - :

% first, load the expansion hooks:
| ?- [expansions].
...

% second, expand a file using those hooks:
| ?- logtalk_compile(source, [hook(user)]).
...

, ( ) source_pl.pl ( , scratch_directory Logtalk). Prolog, user. source.pl Prolog, term_expansion/2, Logtalk . , , .

Logtalk, , , , , {}/1.

(*) Please note that the term extension mechanism is not standard, is not provided by all Prolog implementations and with significant differences between implementations.

+1
source

All Articles