以下の表で左側は、for_pred/3に対するCのプログラムを示しています。右側は、cpred.hの中のマクロ定義がC-プリプロセッサによって展開された後の同一のファイルを表しています。...
Move to
Next Prev
Up Top
See also
for_predのソースコード
for_predの説明
IF Computer > IF/Prolog > Manuals > IF/Prolog V4.1 マニュアル > IF/Prolog Interfaces > IF/PrologからC言語へのインタフェ−ス > バックトラックするProlog述語をC言語で書く > バックトラックをするプログラム例 > for_predのソースコード

for_predのソースコード

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

We discontinued to sell IF/Prolog Dec 31. 2003. Dedicated technical support for IF/Prolog ended Dec 31 2008. This site is maintained as a community service only.

以下の表で左側は、for_pred/3に対するCのプログラムを示しています。右側は、cpred.hの中のマクロ定義がC-プリプロセッサによって展開された後の同一のファイルを表しています。

/* ------------------------------------------------------- */ /* filename : $PROROOT/demos/c/for_pred.c */ /* for_pred(Min_int, N, Max_int): produces the series of */ /* integers [Min_int,Max_int]. test with (in ./for_test): */ /* go :- M=3,N=6, for(M,I,N),write('I='),write(I),nl,fail.*/ /* --------------------------------------------------------*/ #include "cpred.h"

typedef struct {int i; int max;} FORSTATE;

Cboot(){ CPRED("for_pred", 3, Forpred, sizeof(FORSTATE)); }

/*--------------------------------*/

COROUTINE(Forpred, FORSTATE, state)

RESUME(1, res1);

BEGIN if( !XChk(IsInt(Arg(1)) && IsInt(GoalArg(3)), "integer_expected")) { FAIL; } state->i = IntPC(Arg(1)); state->max = IntPC(Arg(3)); while(state->i <= state->max) { if (UnifyArg(2, IntCP((INT)state->i))) { DETACH(1,res1); } state->i++; } END

after C preprocessor

typedef struct {int i; int max;} FORSTATE;

Cboot(){ { {int Forpred (); Cpred("for_pred", 3, Forpred, sizeof(FORSTATE)); };}

/*--------------------------------*/

int Forpred(port, state) int port; FORSTATE * state;{switch(port){ case 0:break; case 1: goto res1; default: return 0;};{ if( !XChk(IsInt(Arg(1)) && IsInt(Arg(3)), "integer_expected")) { return 0; } state->i = IntPC(GoalArg(1)); state->max = IntPC(GoalArg(3)); while(state->i <= state->max) { if (UnifyArg(2, IntCP((INT)state->i))) { { return 1; res1: ; }; } state->i++; } } return 0; }

read on...
IF/Prolog by Siemens
Language
English
Japanese
German
Server
USA
Japan
Site Access
Local Index
Local Contents
Site Contents
Site Index
Printer Friendly
For imode
For PDA
Search
document: http://www.ifcomputer.co.jp/IFProlog/Manuals/v4.1/advanced_feature/c_interface/cpredbw/exampb/lst/home_en.html
published 2012/5/21 update 1995/11/6 (c) 1996-2009 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
scroll to top managed with ubiCMS