Logic Paradigm - Prolog

  • "=": Unify
  • "==": Equality
  • "is": Evaluate then unify

  • Example Meaning Explanation
    x is 3 + 4 x gets 7 is does math, then assigns to the left side
    x = 3 + 4 x gets 3 + 4 = assigns to both sides
    x == 3 + 4 false, it wasn't already true == like Java just sees if things are already equal

Logic Paradigm - Prolog

  • Provided functions
  • returns returns returns
    integer(3) true float(3) true string(3) false
    integer(3.14) false float(3.14) true string(3.14) false
    integer("hi") false float("hi") false string("hi") true

    returns returns returns
    not(true) false +(3, 4) 7 string_concat("a", "b") "ab"
    not(false) true 3 + 4 7
    not(integer(3)) false +(3.1, 4.2) 7.3
    not(string(3)) true 3.1 + 4.2 7.3
  • Try #1: to add
  • 
                  foo(A, B):- A + B.
                  foo(3, 4). % ERROR undefined procedure (+)/2
                
    Cannot find a rule named + which takes 2 parameters. It was expecting a normal rule which returns a boolean.
  • Try #2: to add
  • 
                  foo(A, B, C):- C _____ A + B % =, ==, or is?
                
    Which operator to make C be the answer of adding two ints?