Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like anonymous predicates in SWI Prolog?

Can I define an anonymous predicate in SWI Prolog, bind it to a variable, and call it later? Something like this:

?- F = {(X, Y) :- Y is 2 * X}, call(F, 2.0, Y).
like image 251
Michael Avatar asked Jun 19 '19 07:06

Michael


People also ask

Is Prolog a predicate?

Prolog predicate is the method to contain the argument and return the boolean values such as true or false. It is a function to operate and return given values, variables, or arguments using a prolog programming language.

What does /+ mean in Prolog?

It's the 'not provable' operator. It succeeds if its argument is not provable (and fails if its argument is provable).

How are strings defined in SWI-Prolog?

As of SWI-Prolog version 7, text enclosed in double quotes (e.g., "Hello world" ) is read as objects of the type string. A string is a compact representation of a character sequence that lives on the global (term) stack. Strings represent sequences of Unicode characters including the character code 0 (zero).

How do you check if something is a list in Prolog?

In Prolog list elements are enclosed by brackets and separated by commas. Another way to represent a list is to use the head/tail notation [H|T]. Here the head of the list, H, is separated from the tail of the list, T, by a vertical bar. The tail of a list is the original list with its first element removed.


1 Answers

That´s what lambdas are for:

?- use_module(library(lambda)).
true.

?- F_2 = (\X^Y^ ( Y is 2*X )), call(F_2,2.0,Y).
F_2 = \X^4.0^(4.0 is 2*X),
Y = 4.0.
like image 95
false Avatar answered Oct 14 '22 06:10

false