1 | % evaluate ProB AST sequence expressions | |
2 | ||
3 | % returns indexed avl_set | |
4 | seqint_avl(Expression,avl_set(AVL)) :- | |
5 | seqint(Expression,Value) , | |
6 | gen_indexed_couple_list(1,Value,CoupleList) , | |
7 | findall(Key-true,member(Key,CoupleList),AVLList) , | |
8 | list_to_avl(AVLList,AVL). | |
9 | ||
10 | seqint(b(value(Seq),seq(_),_),Seq) :- | |
11 | is_list(Seq). | |
12 | ||
13 | seqint(b(value(avl_set(Seq)),seq(_),_),Value) :- | |
14 | avl_to_list(Seq,List) , | |
15 | findall(Key,member(Key-true,List),Value). | |
16 | ||
17 | seqint(b(sequence_extension([Seq]),seq(seq(_)),_),[Value]) :- | |
18 | seqint(Seq,Value). | |
19 | ||
20 | seqint(b(sequence_extension(Set),seq(_),_),Value) :- | |
21 | maplist(ast_to_prob_value,Set,Value). | |
22 | ||
23 | seqint(b(general_concat(SeqOfSeq),seq(_),_),Value) :- | |
24 | seqint(SeqOfSeq,Temp) , | |
25 | flatten(Temp,Value). | |
26 | ||
27 | seqint(b(front(Seq),seq(_),_),Value) :- | |
28 | seqint(Seq,Temp) , | |
29 | remove_last(Temp,Value). | |
30 | ||
31 | seqint(b(tail(Seq),seq(_),_),Value) :- | |
32 | seqint(Seq,[_|Value]). | |
33 | ||
34 | seqint(b(rev(Seq),seq(_),_),Value) :- | |
35 | seqint(Seq,Temp) , | |
36 | reverse(Temp,Value). | |
37 | ||
38 | seqint(b(restrict_front(Seq,RestrictBy),seq(_),_),Value) :- | |
39 | seqint(Seq,Temp) , | |
40 | int(RestrictBy,RestrictValue) , | |
41 | get_first_n(Temp,RestrictValue,Value). | |
42 | ||
43 | seqint(b(restrict_tail(Seq,RestrictBy),seq(_),_),Value) :- | |
44 | seqint(Seq,Temp) , | |
45 | int(RestrictBy,RestrictValue) , | |
46 | rem_first_n(Temp,RestrictValue,Value). | |
47 | ||
48 | seqint(b(concat(Seq1,Seq2),seq(_),_),Value) :- | |
49 | seqint(Seq1,ValueSeq1) , | |
50 | seqint(Seq2,ValueSeq2) , | |
51 | append(ValueSeq1,ValueSeq2,Value). | |
52 | ||
53 | seqint(b(insert_tail(Val,Seq),seq(_),_),Value) :- | |
54 | sint(Val,Insert) , | |
55 | seqint(Seq,ValueSeq) , | |
56 | ( Insert = true -> NInsert = [pred_true] | |
57 | ; Insert = false -> NInsert = [pred_false] | |
58 | ; NInsert = [Insert]) , | |
59 | append(NInsert,ValueSeq,Value). | |
60 | ||
61 | seqint(b(insert_front(Seq,Val),seq(_),_),Value) :- | |
62 | sint(Val,Insert) , | |
63 | seqint(Seq,ValueSeq) , | |
64 | ( Insert = true -> NInsert = [pred_true] | |
65 | ; Insert = false -> NInsert = [pred_false] | |
66 | ; NInsert = [Insert]) , | |
67 | append(ValueSeq,NInsert,Value). | |
68 | ||
69 | % return the first n elements of a list | |
70 | get_first_n([],_,[]). | |
71 | get_first_n(_,0,[]). | |
72 | get_first_n([H|T],N,[H|NT]) :- | |
73 | N1 is N - 1 , | |
74 | get_first_n(T,N1,NT). | |
75 | ||
76 | % removes the first n elements of a list | |
77 | rem_first_n([],_,[]). | |
78 | rem_first_n(L,0,L). | |
79 | rem_first_n([_|T],N,NL) :- | |
80 | N1 is N - 1 , | |
81 | rem_first_n(T,N1,NL). |