sitelogo
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. For current customers, we continue to provide professional support for IF/Prolog until Dec 31, 2008.

以下の表で左側は、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; }


Up read on...
scroll to top managed with ubiCMS