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).
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.
It's the 'not provable' operator. It succeeds if its argument is not provable (and fails if its argument is provable).
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With