IF/Prologインタプリタは、すでにあなたのシステムにインストールしてありますね。手始めにPrologのサンプルプログラムを編集してみることにしましょう。
colleague.proというファイルでエディタを呼び出してください。以下のようなPrologプログラムを打ち込みセーブしたら、エディタから抜け出て下さい。Prologでは、"%"から行の終わりまで、あるいは、"/*"と"*/"で囲まれた部分はプログラムのコメントです。
/* operators : define both functors as infix operators */
:- op(100,xfy,reports_to). :- op(100,xfy,is_subordinate_to).
/* rules : this procedure consists of two clauses */
C1 is_subordinate_to C2 :- /* 1 */ C1 reports_to C2.
C1 is_subordinate_to C2 :- /* 2 */ C1 reports_to C3, C3 is_subordinate_to C2.
/* facts : each fact has two arguments */
'White' reports_to 'Jones'. 'McDonald' reorts_to 'Jones'. 'Hill' reports_to 'Smith'. 'Newman' reports_to 'Smith'. 'Nixon' reports_to 'Smith'. 'Smith' reports_to 'New'. 'Jones' reports_to 'New'.
ここでは関数子を中置演算子として定義しておいたので、構文チェッカにひっかかることなく、2つの項の間に演算子を書くことができます。
中置演算子を定義していない場合は、関数子が先にきて、その後に()で囲まれた引数がくる通常のIF/Prologの述語の構文に従ってください。この場合、上のプログラムと同じ意味のPrologプログラムは以下のようになります。
/* rules : this procedure consists of two clauses */
is_subordinate_to(C1,C2) :- /* 1 */ reports_to(C1,C2).
is_subordinate_to(C1,C2) :- /* 2 */ reports_to(C1,C3), is_subordinate_to(C3,C2).
/* facts : each fact has two arguments */ reports_to('White', 'Jones'). reports_to('McDonald', 'Jones'). reports_to('Hill', 'Smith'). reports_to('Newman', 'Smith'). reports_to('Nixon', 'Smith'). reports_to('Smith', 'New'). reports_to('Jones', 'New').
IF/Prologの起動
データの読み込み
データベースのリスティング
データの削除
構文エラー
質問と命令
入力/出力
IF/Prologの終了
制御の流れ
戻る
続く..