Meta-Predicates in Prolog

Sdílet
Vložit
  • čas přidán 11. 09. 2024
  • Meta-predicates, also called higher-order predicates, let us dynamically call and inspect predicates and help us write short and correct programs. Among the most useful meta-predicates are the call/N, maplist/N and foldl/N families of predicates. More information: www.metalevel....

Komentáře • 10

  • @michaelkohlhaas4427
    @michaelkohlhaas4427 Před 4 lety +9

    *Your videos are unbelievable. Treasure trove!*

  • @skc909887u
    @skc909887u Před 3 lety +5

    Such a powerful underutilised language . !!

    • @abeard1
      @abeard1 Před 2 lety +2

      Agree, totally different aproach than mainstream one

  • @p.z.8355
    @p.z.8355 Před 4 lety

    I dont understand the start of the video. What is the query in 0:33 ? Is the first predicate equal to Goal(X) :- X=1+2. ?

    • @ThePowerOfProlog
      @ThePowerOfProlog  Před 4 lety +1

      The goal is a conjunction, using the built-in predicate ','/2 with two arguments:
      The first conjunct is a goal that uses the predicate (=)/2. It is true if Goal is unifiable with the term (X #= 1+2), i.e., the compound term #=(X, +(1,2)). Since Goal is a variable, this is the case, using the substitution Goal = (X #= 1+2). Note that the only predicate that is invoked at this point (besides conjunction) is the built-in predicate (=)/2.
      The second conjunct is Goal. This is equivalent to the goal call(Goal), which - operationally speaking - invokes Goal. In this case, at this point of the execution, Goal is the term (X #= 1+2), and so invoking Goal in this case is equivalent to posting the goal X #= 1+2 directly.
      However, note that the predicate (#=)/2 is invoked dynamically in this case, and does not appear as a goal at compilation time anywhere in the query.
      This example shows that invoking goals dynamically "ships" as built-in feature of Prolog: We can simply form an arbitrary goal G we want to invoke, denoted as a Prolog term, and then invoke it by posting G, or - equivalently - the goal call(G).

  • @douglasmennella4525
    @douglasmennella4525 Před 2 lety

    I'm a little confused by the term "partial goal". Isn't the first argument to call/2 in call(=(X),a), the functor =/1 and not =/2 with the second arg missing? Does call/2 rewrite this =/1 predicate to be =/2?

    • @douglasmennella4525
      @douglasmennella4525 Před 2 lety

      I guess this is the definition of a partial goal, but the pendant in me wants to know if this is strictly speaking re-writing of a predicate with fewer arguments. I suppose I should simply understand that as an implementation goal.

    • @ThePowerOfProlog
      @ThePowerOfProlog  Před 2 lety

      @@douglasmennella4525 In the goal call(=(X), a), the first argument is a term with principal functor = and arity 1. There is no connection between the term =(X) and any predicate that - one could say: coincidentally - has the same name as the functor of this term, such as the predicate (=)/2 or any other predicate with predicate name =. Only when call/N actually calls the predicate that is indicated by the first argument (and additional arguments specified via call/N) does a connection become apparent, in the sense that the predicate that is indicated by the given name and arguments is called. The term =(X) in itself is not intended as a goal, and there is not even a predicate (=)/1 defined in this example. We say it is a partial goal, because it becomes the intended goal when an additional argument is added to this term.

    • @douglasmennella4525
      @douglasmennella4525 Před 2 lety

      @@ThePowerOfProlog Thanks for replying so many years after the original post. I think I follow. I was latching on hard to the idea that =/1 has no relation to =/2 so much so that I missed the intent.