Closed lyj18688610256 closed 2 years ago
Let's assume you have an upper bound on the number of list elements and the upper bound is three. As simple FIFO queue can be simulated as follows,
.type List = [l:List, n:number]
.decl A(x:number, l:List )
A(1, [nil, 1]).
A(2, [[nil, 1],2]).
A(3, [[[nil, 1],2],3]).
A(i+1, [[[nil, x2], x3], i+1]) :- A(i, [[[nil, _x1], x2], x3]), i < 10.
.output A
and produces following result:
---------------
A
x l
===============
1 [nil, 1]
2 [[nil, 1], 2]
3 [[[nil, 1], 2], 3]
4 [[[nil, 2], 3], 4]
5 [[[nil, 3], 4], 5]
6 [[[nil, 4], 5], 6]
7 [[[nil, 5], 6], 7]
8 [[[nil, 6], 7], 8]
9 [[[nil, 7], 8], 9]
10 [[[nil, 8], 9], 10]
===============
yes,it indeed works if I know the upper bound on the number of list elements but my occasion is that the number of list elements for different variables will change with the flow of the program. Does that mean every time I will count for the number of the list? and then follow your way?
what the program can give you is only a list of a variable: list_var1 ([[[[[[nil,2],3],4],5],6],7]) list_var2([[[[[[[nil,4,],7],11],3],2],5],8]) ........ what the program wish to get is a new list of a varibale: new_list_var1( [[[[[nil,3],4],5],6],7] ) new_list_var2([[[[[[nil,7],11],3],2],5],8]) ........ so for different variables,they have different numbers of elements,I need to acquire the new_list_var for every varible,that's what I need
You can achieve this by flattening and reconstructing the lists. We have some examples in the test-benchmark.
May I ask for what you need it in DOOP (is this research or a study assignment)?
You can achieve this by flattening and reconstructing the lists. We have some examples in the test-benchmark.
Ok,thanks a lot
May I ask for what you need it in DOOP (is this research or a study assignment)?
I want to publish a paper using doop tool,this problem is one part of my algorithm
No worries - perhaps you get familiar with logic programming first. My suggestion is to flatten and reverse lists etc. You have various options. Try to solve this problem in isolation. Also, you can extend the previous solution, up to a certain bound by having for each length a pattern.
You can achieve this by flattening and reconstructing the lists. We have some examples in the test-benchmark.
Can you specify the concrete path for me?I can't find it
Have a look in the tests/example and tests/evaluation directories. Also, please work through Souffle's tutorial. Good luck!
Have a look in the tests/example and tests/evaluation directories. Also, please work through Souffle's tutorial. Good luck!
OK,thanks a lot!
For example,if I have a recrusive record like this : mList( [[[[[[nil,2],3],4],5],6],7]) how I can get a record mList2( [[[[[nil,3],4],5],6],7] ) conviently? I want to remove the first element,the remain elements consist a new list. Certainly mList here is a unknow list,you don't know how many elements in the List