跳到主要内容

Labs · 9618 A2 20.1

Facts and Rules

Declarative programming: a knowledge base of facts and rules. Ask goals, find the matching clauses, and write your own facts, goals and rules.

11 levelsFree bench

In the exam

9618/31 May/June 2024 · Question 8(c) · 4 marks

F may be available for B if F is a feature and B is a body style and F is not unavailable for that body style. Write this as a rule: may_choose_option(F, B).

Points that gain marks

  • feature(F)
  • bodystyle(B)
  • NOT unavailable(F, B)
  • All the operators and punctuation right (a comma is fine for AND), and nothing extra.
  • For example: may_choose_option(F, B) IF feature(F) AND bodystyle(B) AND NOT unavailable(F, B).

In this lab: Level 8 runs your rule on the whole knowledge base and shows every answer it gives, so you can see what a missing NOT does.

9618/31 May/June 2021 · Question 9(b) · 2 marks

Describe what is meant by a declarative programming language.

Points that gain marks

  • The program says what is to be done, not how to do it.
  • It uses facts and rules.
  • It uses queries (goals) that the facts and rules satisfy.
  • It can be logical (a set of logical relations) or functional (functions applied to arguments).

In this lab: In every level, you give facts, rules and goals; Prolog does the searching.

More real experiments

登录或创建账户

IGCSE, A-Level & AP