Logic Paradigm - Prolog

  • Declarative languages: Logic (Prolog) and Functional (Haskell)
  • Always recursions! No loops!
  • Syntax differences:
  • Prolog Others such as Java
    Atom/Idea (Constant) abc ABC
    Variable UpperCase camelCase
    Rule/Function foo(stuff, return):- body. foo(stuff { body; return value; }
    Fact foo(stuff, return). See above
    Query/Function Call foo(Variables) foo(variables);
  • Comment a line: using %

Logic Paradigm - Prolog

  • All queries (like the code in a main method) return true/false.
  • If you have variables w/o values, the query gives them values.
  • The print function:
  • 
                  write(X):= "Magic built-in code that prints X". % This returns true
                  write(false). % it prints "false" and returns true
                
  • Rules
  • 
                  rule().
                  rule(..):= ... % runs them in order: from top to bottom
                  rule(..):- ... % keeps the 1st one to return true