IF Computer > IF/Prolog > Manuals > IF/Prolog V4.1 マニュアル > ユーザーズ・ガイド > 初めてのPrologのセッションのための準備

初めてのPrologのセッションのための準備

IF/Prolog by Siemens
MINERVA superseeded IF/Prolog. Please see http://www.ifcomputer.co.jp/MINERVA for details.

We discontinued to sell IF/Prolog Dec 31. 2003. For current customers, we continue to provide professional support for IF/Prolog until Dec 31, 2008.

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').

document: http://www.ifcomputer.co.jp/IFProlog/Manuals/v4.1/user_guide/prepare/print_de.html
published 2008/10/6 update 1995/11/7 (c) 1996-2006 IF Computer Japan
IF Computer 5-28-2 Sendagi, Bunkyo-ku Tel +81-3-5814-3352 start (AT) ifcomputer.com
Customer Support Tokyo 113-0022 Japan   http://www.ifcomputer.com
Back> managed with ubiCMS