2021年1月28日星期四

CHR: How do you call Prolog code inside a rule

CHR: How do you call Prolog code inside a rule ? I assume it is like DCG !!! but doesn't seem right

:- use_module(library(chr)).  :- chr_constraint move/2,pos/2, next/0.  :- [utils].      main :- pos(5,5).    rand(X,Y) :- random(0,2,X), random(0,2,Y), say("~w,~w",[X,Y]).    pos(X,Y), move(A,B) <=> pos(6,6).%X1 > 0, X1 < 10, Y1 > 0, Y1 < 10 |  pos(X1,Y1), {X1 is X + A, Y1 is Y + B}.    next <=> move(X,Y), {rand(X,Y)}.  <<<-----  

error :

?- pos(5,5),next.  ERROR: Unknown procedure: {}/1  ERROR: In:  ERROR:   [13] {rand(_35671298,_35671300)}  ERROR:   [12] next___0__0(suspension(470241,removed,_35671332,0,user: ...,next)) at grid.pl:12  ERROR:    [9] <user>  ERROR:   ERROR: Note: some frames are missing due to last-call optimization.  ERROR: Re-run your program in debug mode (:- debug.) to get more detail.     Exception: (13) {rand(_35670676, _35670678)} ? abort  % Execution Aborted  
https://stackoverflow.com/questions/65947830/chr-how-do-you-call-prolog-code-inside-a-rule January 29, 2021 at 10:06AM

没有评论:

发表评论