Declarative programming
Declarative programming
There are three basic constructs in Prolog: facts, rules and queries.
1. The program logic is expressed using clauses (facts and rules). A
collection of clauses is called a 'knowledge base'. Writing a Prolog
program means writing a knowledge base as a collection of clauses.
2. Problems are solved by running a query (goal).
3. Prolog is case sensitive.
A clause is of the form:
Head: -Body.
Example-1
savingsRate(stefan,X).
And here is the result:
fivePercent
Example-2
bankAccount(laila,X,Y).
bankAccount(victor,X,Y).
And here is the result:
current, 500.00
false
Activity-2 language(fortran,highLevel).
language(cobol,highLevel).
Use the knowledge base below to answer the language(visualBasic,highLevel).
following questions: language(visualBasic,oop).
a) Write two new facts about Java, showing that it language(python,highLevel).
is a high-level language and uses OOP. language(python,oop).
language(java, highLevel) language(assembly,lowLevel).
language(java, oop) language(masm,lowLevel).
a) Show the results from these queries translator(assembler,lowLevel).
i) teaching(X). translator(compiler,highLevel).
visualBasic;
Python teaching(X):-
ii) teaching(masm). language(X,oop),
false language(X,highLevel).
a) Write a query to show all programming
languages translated by an assembler.
language(Language,lowlevel).