我有一个对列表,并希望找到具有相应第一个值的元素.
?- findconn1(9, [(9,[23,33]),(42,[21,322])], R).
Run Code Online (Sandbox Code Playgroud)
因此,在这种情况下,我希望得到的结果是(9,[23,23])在R.
代码是
findconn(X, [], R).
findconn(X, [(H,T)|Y], R) :-
member(X, H),
findConn(X, Y),
append(T, T, R).
Run Code Online (Sandbox Code Playgroud)
false尽管元素存在,它总是返回.还有其他方法可以返回,因为我对Prolog很新.
我是标准ML的新手并尝试编写以下代码
fun whilestat test stmt1 =
(fn x => if (test x) then (stmt1 x;whilestat test stmt1 ) else (x) );
Run Code Online (Sandbox Code Playgroud)
问题是它给了我以下错误
w.sml:21.6-22.82 Error: right-hand-side of clause doesn't agree with function result type [circularity]
expression: ('Z -> 'Y) -> 'Z -> 'Z
result type: ('Z -> 'Y) -> 'Z
in declaration:
whilestat2 = (fn arg => (fn <pat> => <exp>))
uncaught exception Error
raised at: ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27
../compiler/TopLevel/interact/evalloop.sml:44.55
../compiler/TopLevel/interact/evalloop.sml:292.17-292.20
Run Code Online (Sandbox Code Playgroud)
我只是试图通过电子邮件发送一段时间,如果staement为真,那么它会递归,否则返回值.