implicit-state-passing

Applying semicontext notation for passing additional arguments

拜拜、爱过 提交于 2020-01-21 12:17:08
问题 This is a follow-on question from an earlier question from Mat's answer Starting with this e([number(0)] , t1 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([number(1)] , t2 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([number(2)] , t3 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([op(neg),[Arg]] , u1(E) , [_|Uc0], Uc1, Bc0 , Bc1) --> [_], e(Arg , E , Uc0, Uc1, Bc0, Bc1). e([op(ln),[Arg]] , u2(E) , [_|Uc0], Uc1, Bc0 , Bc1) --> [_], e(Arg , E , Uc0, Uc1, Bc0, Bc1). e([op(add),[Left,Right]], b1(E0,E1) , Uc0 , Uc2, [_|Bc0], Bc2) -

Dcg state implementation of algorithm

浪子不回头ぞ 提交于 2019-12-11 05:57:37
问题 The distance between a long sequence and a short sequence, is the minimum distance between the short sequence and any subsequence of the long sequence that is the same length as the short sequence. The distance I am using is I think the Manhattan distance . (But this should be unimportant as I would like to be able to change distance functions). This first version shows a naive implementation without early abandon. I generate all subsequence of the same length, map these to find the distance

Applying semicontext notation for passing additional arguments

偶尔善良 提交于 2019-12-01 21:36:45
This is a follow-on question from an earlier question from Mat's answer Starting with this e([number(0)] , t1 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([number(1)] , t2 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([number(2)] , t3 , Uc0 , Uc0, Bc0 , Bc0) --> []. e([op(neg),[Arg]] , u1(E) , [_|Uc0], Uc1, Bc0 , Bc1) --> [_], e(Arg , E , Uc0, Uc1, Bc0, Bc1). e([op(ln),[Arg]] , u2(E) , [_|Uc0], Uc1, Bc0 , Bc1) --> [_], e(Arg , E , Uc0, Uc1, Bc0, Bc1). e([op(add),[Left,Right]], b1(E0,E1) , Uc0 , Uc2, [_|Bc0], Bc2) --> [_,_], e(Left, E0, Uc0, Uc1, Bc0, Bc1), e(Right, E1, Uc1, Uc2, Bc1, Bc2). e([op(sub),[Left,Right]],

How to avoid using assert and retractall in Prolog to implement global (or state) variables

限于喜欢 提交于 2019-12-01 04:42:01
I often end up writing code in Prolog which involves some arithmetic calculation (or state information important throughout the program), by means of first obtaining the value stored in a predicate, then recalculating the value and finally storing the value using retractall and assert because in Prolog we cannot assign values to variable twice using is (thus making almost every variable that needs modification, global). I have come to know that this is not a good practice in Prolog. In this regard I would like to ask: Why is it a bad practice in Prolog (though i myself don't like to go through

How to avoid using assert and retractall in Prolog to implement global (or state) variables

北慕城南 提交于 2019-12-01 02:17:57
问题 I often end up writing code in Prolog which involves some arithmetic calculation (or state information important throughout the program), by means of first obtaining the value stored in a predicate, then recalculating the value and finally storing the value using retractall and assert because in Prolog we cannot assign values to variable twice using is (thus making almost every variable that needs modification, global). I have come to know that this is not a good practice in Prolog. In this

How to enumerate combinations using DCGs with CLP(FD) and multiple constraints

醉酒当歌 提交于 2019-11-28 01:33:42
This question starts from Mat's answer to Algorithm improvement for enumerating binary trees which has only one input value that determines the number of all nodes for the binary tree, and the need to be able to have two input values with one being the number of unary nodes and the other being the number of binary nodes. While I was able to derive a solution by using listing/1 and threading extra state variables: e(t, B, B, U, U). e(u(E), B0, B1, [_|U0], U1) :- e(E, B0, B1, U0, U1). e(b(E0, E1), [_|B0], B2, U0, U2) :- e(E0, B0, B1, U0, U1), e(E1, B1, B2, U1, U2). e(U,B,Es) :- length(Bs, B),

How to enumerate combinations using DCGs with CLP(FD) and multiple constraints

北战南征 提交于 2019-11-26 21:58:32
问题 This question starts from Mat's answer to Algorithm improvement for enumerating binary trees which has only one input value that determines the number of all nodes for the binary tree, and the need to be able to have two input values with one being the number of unary nodes and the other being the number of binary nodes. While I was able to derive a solution by using listing/1 and threading extra state variables: e(t, B, B, U, U). e(u(E), B0, B1, [_|U0], U1) :- e(E, B0, B1, U0, U1). e(b(E0,