使用 library(real) 的序言程序可以关联吗?
can prolog programs using library(real) be made relational?
在这样的程序中使用库(real):
:- use_module( library(real) ).
:- use_module( library(lists) ).
:- use_module( library(apply_macros) ).
:- use_module( library(readutil) ).
my_sum(L, S):-
i <- L,
<- i,
S <- sum(i).
有没有办法修改程序,使其能够 运行 倒退?
目前,这有效:
?- my_sum([1,2,3],X).
X = 6.
但这会导致异常:
?- my_sum(L,2).
ERROR: Arguments are not sufficiently instantiated
ERROR: In:
ERROR: [13] _6776=..[_6782|_6784]
ERROR: [12] real:r_call(_6814,[rvar(i),...|_6832]) at /home/raoul/lib/swipl/pack/real/prolog/real.pl:1101
ERROR: [8] my_sum(_6862++[...|_6870],2) at /home/raoul/Bureau/prolog_relational_stats/relational_R.pl:16
ERROR: [7] <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.
从页。 the manual 中的 4 个:
The <-/1 predicate sends an R expression, represented as a ground Prolog
term, to R, without getting any results back to Prolog. The <-/2 operator
facilitates bi-directional communication. If the left-hand side is a free
variable, the library assumes that we are passing data from R to Prolog.
If the left-hand side is bound, Real assumes that we are passing data or
function calls to R.
因此,如果 L
未实例化,您的代码将失败。
你可以这样处理:
my_sum(L,S) :-
( ground(L), var(S) ->
i <- L, <- i, S <- sum(i)
; var(L), ground(S) ->
% your code here
; % error?
).
那么my_sum/2
两个方向都可以用
在这样的程序中使用库(real):
:- use_module( library(real) ).
:- use_module( library(lists) ).
:- use_module( library(apply_macros) ).
:- use_module( library(readutil) ).
my_sum(L, S):-
i <- L,
<- i,
S <- sum(i).
有没有办法修改程序,使其能够 运行 倒退? 目前,这有效:
?- my_sum([1,2,3],X).
X = 6.
但这会导致异常:
?- my_sum(L,2).
ERROR: Arguments are not sufficiently instantiated
ERROR: In:
ERROR: [13] _6776=..[_6782|_6784]
ERROR: [12] real:r_call(_6814,[rvar(i),...|_6832]) at /home/raoul/lib/swipl/pack/real/prolog/real.pl:1101
ERROR: [8] my_sum(_6862++[...|_6870],2) at /home/raoul/Bureau/prolog_relational_stats/relational_R.pl:16
ERROR: [7] <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.
从页。 the manual 中的 4 个:
The <-/1 predicate sends an R expression, represented as a ground Prolog term, to R, without getting any results back to Prolog. The <-/2 operator facilitates bi-directional communication. If the left-hand side is a free variable, the library assumes that we are passing data from R to Prolog. If the left-hand side is bound, Real assumes that we are passing data or function calls to R.
因此,如果 L
未实例化,您的代码将失败。
你可以这样处理:
my_sum(L,S) :-
( ground(L), var(S) ->
i <- L, <- i, S <- sum(i)
; var(L), ground(S) ->
% your code here
; % error?
).
那么my_sum/2
两个方向都可以用