Gathering results of methods in one List with Prolog
up vote
1
down vote
favorite
So I am trying to
I am defining the sets with is_a(b, a), is_a(c, a)
, which for simplicity would look visually something like this:
a
b c
d e f g
I want to give in the list [b, c]
and as a result get the list [d, e, f, g]
At the moment when I give in a node
or a variable, then it can find everything that is underneath it with this method:
find_nodes(Root, Root) :-
+ is_a(_, Root).
find_nodes(Root, X) :-
is_a(Node, Root),
find_nodes(Node, X).
Which when run gives me the result I need :
?- find_nodes(b, X).
X = d.
X = e.
But it is not in a list, so I have tried :
?- all_nodes([b, c], X).
all_nodes(, _).
all_nodes([H|T], [R|Res]):-
findall(L, find_nodes(H, L), R),
all_nodes(T, Res).
Which gives me - X = [[d, e], [f, g]|_4040]
, which consists of lists within lists, but I need just 1 list, that would be X = [d, e, f, g]
.
What am I doing wrong here?
EDIT
Like @lurker said findall
returns a list and adding list to a list will give the result I get right now.
The one thing I also tried was using:
all_nodes(, _).
all_nodes([H|T], [R|Res]):-
find_nodes(H, R),
all_nodes(T, Res).
But well that one does not work either because It only gives me 1 element, which in this case is d
and then f
.
list prolog
add a comment |
up vote
1
down vote
favorite
So I am trying to
I am defining the sets with is_a(b, a), is_a(c, a)
, which for simplicity would look visually something like this:
a
b c
d e f g
I want to give in the list [b, c]
and as a result get the list [d, e, f, g]
At the moment when I give in a node
or a variable, then it can find everything that is underneath it with this method:
find_nodes(Root, Root) :-
+ is_a(_, Root).
find_nodes(Root, X) :-
is_a(Node, Root),
find_nodes(Node, X).
Which when run gives me the result I need :
?- find_nodes(b, X).
X = d.
X = e.
But it is not in a list, so I have tried :
?- all_nodes([b, c], X).
all_nodes(, _).
all_nodes([H|T], [R|Res]):-
findall(L, find_nodes(H, L), R),
all_nodes(T, Res).
Which gives me - X = [[d, e], [f, g]|_4040]
, which consists of lists within lists, but I need just 1 list, that would be X = [d, e, f, g]
.
What am I doing wrong here?
EDIT
Like @lurker said findall
returns a list and adding list to a list will give the result I get right now.
The one thing I also tried was using:
all_nodes(, _).
all_nodes([H|T], [R|Res]):-
find_nodes(H, R),
all_nodes(T, Res).
But well that one does not work either because It only gives me 1 element, which in this case is d
and then f
.
list prolog
findall(...)
has a list as its third argument. So when you callfindall(L, find_nodes(H, L), R)
.R
is a list. So[R|Res]
is a list whose first element is itself a list,R
. Your other issue is your base case.all_nodes(, _)
says that all nodes of an empty list is anything you want since_
is an anonymous variable. It can be anything.
– lurker
Nov 8 at 1:06
@lurkerall_nodes(, _)
didnt really know what else to put there, probablycould also work. But how can I do it without using
findall
because when i do it without and call the function recursively while replacingfindall
to justfind_nodes
then it takes only thed
and goes to the next head.
– user9441470
Nov 8 at 1:14
1
Well,_
does not work because it really does mean that your rule says, finding the nodes for the empty list is anything is a successful result, which obviously isn't logical.would be more logical, would it not? Isn't the result of finding all nodes in an empty tree an empty list specifically?
– lurker
Nov 8 at 1:59
1
You can usefindall
. You just can't directly use the result the way you are trying to use it. You would need to concatenate the result to your current list of known nodes.
– lurker
Nov 8 at 2:00
1
SWI Prolog also hasappend(ListOfLists, List)
you can check out.
– lurker
Nov 8 at 2:07
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
So I am trying to
I am defining the sets with is_a(b, a), is_a(c, a)
, which for simplicity would look visually something like this:
a
b c
d e f g
I want to give in the list [b, c]
and as a result get the list [d, e, f, g]
At the moment when I give in a node
or a variable, then it can find everything that is underneath it with this method:
find_nodes(Root, Root) :-
+ is_a(_, Root).
find_nodes(Root, X) :-
is_a(Node, Root),
find_nodes(Node, X).
Which when run gives me the result I need :
?- find_nodes(b, X).
X = d.
X = e.
But it is not in a list, so I have tried :
?- all_nodes([b, c], X).
all_nodes(, _).
all_nodes([H|T], [R|Res]):-
findall(L, find_nodes(H, L), R),
all_nodes(T, Res).
Which gives me - X = [[d, e], [f, g]|_4040]
, which consists of lists within lists, but I need just 1 list, that would be X = [d, e, f, g]
.
What am I doing wrong here?
EDIT
Like @lurker said findall
returns a list and adding list to a list will give the result I get right now.
The one thing I also tried was using:
all_nodes(, _).
all_nodes([H|T], [R|Res]):-
find_nodes(H, R),
all_nodes(T, Res).
But well that one does not work either because It only gives me 1 element, which in this case is d
and then f
.
list prolog
So I am trying to
I am defining the sets with is_a(b, a), is_a(c, a)
, which for simplicity would look visually something like this:
a
b c
d e f g
I want to give in the list [b, c]
and as a result get the list [d, e, f, g]
At the moment when I give in a node
or a variable, then it can find everything that is underneath it with this method:
find_nodes(Root, Root) :-
+ is_a(_, Root).
find_nodes(Root, X) :-
is_a(Node, Root),
find_nodes(Node, X).
Which when run gives me the result I need :
?- find_nodes(b, X).
X = d.
X = e.
But it is not in a list, so I have tried :
?- all_nodes([b, c], X).
all_nodes(, _).
all_nodes([H|T], [R|Res]):-
findall(L, find_nodes(H, L), R),
all_nodes(T, Res).
Which gives me - X = [[d, e], [f, g]|_4040]
, which consists of lists within lists, but I need just 1 list, that would be X = [d, e, f, g]
.
What am I doing wrong here?
EDIT
Like @lurker said findall
returns a list and adding list to a list will give the result I get right now.
The one thing I also tried was using:
all_nodes(, _).
all_nodes([H|T], [R|Res]):-
find_nodes(H, R),
all_nodes(T, Res).
But well that one does not work either because It only gives me 1 element, which in this case is d
and then f
.
list prolog
list prolog
edited Nov 8 at 1:22
asked Nov 8 at 1:04
user9441470
findall(...)
has a list as its third argument. So when you callfindall(L, find_nodes(H, L), R)
.R
is a list. So[R|Res]
is a list whose first element is itself a list,R
. Your other issue is your base case.all_nodes(, _)
says that all nodes of an empty list is anything you want since_
is an anonymous variable. It can be anything.
– lurker
Nov 8 at 1:06
@lurkerall_nodes(, _)
didnt really know what else to put there, probablycould also work. But how can I do it without using
findall
because when i do it without and call the function recursively while replacingfindall
to justfind_nodes
then it takes only thed
and goes to the next head.
– user9441470
Nov 8 at 1:14
1
Well,_
does not work because it really does mean that your rule says, finding the nodes for the empty list is anything is a successful result, which obviously isn't logical.would be more logical, would it not? Isn't the result of finding all nodes in an empty tree an empty list specifically?
– lurker
Nov 8 at 1:59
1
You can usefindall
. You just can't directly use the result the way you are trying to use it. You would need to concatenate the result to your current list of known nodes.
– lurker
Nov 8 at 2:00
1
SWI Prolog also hasappend(ListOfLists, List)
you can check out.
– lurker
Nov 8 at 2:07
add a comment |
findall(...)
has a list as its third argument. So when you callfindall(L, find_nodes(H, L), R)
.R
is a list. So[R|Res]
is a list whose first element is itself a list,R
. Your other issue is your base case.all_nodes(, _)
says that all nodes of an empty list is anything you want since_
is an anonymous variable. It can be anything.
– lurker
Nov 8 at 1:06
@lurkerall_nodes(, _)
didnt really know what else to put there, probablycould also work. But how can I do it without using
findall
because when i do it without and call the function recursively while replacingfindall
to justfind_nodes
then it takes only thed
and goes to the next head.
– user9441470
Nov 8 at 1:14
1
Well,_
does not work because it really does mean that your rule says, finding the nodes for the empty list is anything is a successful result, which obviously isn't logical.would be more logical, would it not? Isn't the result of finding all nodes in an empty tree an empty list specifically?
– lurker
Nov 8 at 1:59
1
You can usefindall
. You just can't directly use the result the way you are trying to use it. You would need to concatenate the result to your current list of known nodes.
– lurker
Nov 8 at 2:00
1
SWI Prolog also hasappend(ListOfLists, List)
you can check out.
– lurker
Nov 8 at 2:07
findall(...)
has a list as its third argument. So when you call findall(L, find_nodes(H, L), R)
. R
is a list. So [R|Res]
is a list whose first element is itself a list, R
. Your other issue is your base case. all_nodes(, _)
says that all nodes of an empty list is anything you want since _
is an anonymous variable. It can be anything.– lurker
Nov 8 at 1:06
findall(...)
has a list as its third argument. So when you call findall(L, find_nodes(H, L), R)
. R
is a list. So [R|Res]
is a list whose first element is itself a list, R
. Your other issue is your base case. all_nodes(, _)
says that all nodes of an empty list is anything you want since _
is an anonymous variable. It can be anything.– lurker
Nov 8 at 1:06
@lurker
all_nodes(, _)
didnt really know what else to put there, probably
could also work. But how can I do it without using findall
because when i do it without and call the function recursively while replacing findall
to just find_nodes
then it takes only the d
and goes to the next head.– user9441470
Nov 8 at 1:14
@lurker
all_nodes(, _)
didnt really know what else to put there, probably
could also work. But how can I do it without using findall
because when i do it without and call the function recursively while replacing findall
to just find_nodes
then it takes only the d
and goes to the next head.– user9441470
Nov 8 at 1:14
1
1
Well,
_
does not work because it really does mean that your rule says, finding the nodes for the empty list is anything is a successful result, which obviously isn't logical.
would be more logical, would it not? Isn't the result of finding all nodes in an empty tree an empty list specifically?– lurker
Nov 8 at 1:59
Well,
_
does not work because it really does mean that your rule says, finding the nodes for the empty list is anything is a successful result, which obviously isn't logical.
would be more logical, would it not? Isn't the result of finding all nodes in an empty tree an empty list specifically?– lurker
Nov 8 at 1:59
1
1
You can use
findall
. You just can't directly use the result the way you are trying to use it. You would need to concatenate the result to your current list of known nodes.– lurker
Nov 8 at 2:00
You can use
findall
. You just can't directly use the result the way you are trying to use it. You would need to concatenate the result to your current list of known nodes.– lurker
Nov 8 at 2:00
1
1
SWI Prolog also has
append(ListOfLists, List)
you can check out.– lurker
Nov 8 at 2:07
SWI Prolog also has
append(ListOfLists, List)
you can check out.– lurker
Nov 8 at 2:07
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You can take advantage of the de facto standard findall/4
(*) predicate to solve the problem. This predicate is a variant of the standard findall/3
predicate that allows passing a tail for the list of solutions collected by the predicate. For example:
?- findall(N, (N=1; N=2; N=3), L, [4,5]).
L = [1, 2, 3, 4, 5].
In the following solution, I have renamed predicates and variables for clarity and modified your node leaf predicate:
is_a(a, b).
is_a(a, c).
is_a(b, d).
is_a(b, e).
is_a(c, f).
is_a(c, g).
leaf(Leaf, Leaf) :-
+ is_a(Leaf, _).
leaf(Node, Leaf) :-
is_a(Node, Child),
leaf(Child, Leaf).
all_nodes(, ).
all_nodes([Node| Nodes], Leaves):-
findall(Leaf, leaf(Node, Leaf), Leaves, Tail),
all_nodes(Nodes, Tail).
Sample calls:
?- all_nodes([b, c], X).
X = [d, e, f, g].
?- all_nodes([a], X).
X = [d, e, f, g].
?- all_nodes([b], X).
X = [d, e].
(*) It's a built-in predicate in GNU Prolog, JIProlog, Lean Prolog, O-Prolog, SICStus Prolog, SWI-Prolog, XSB, and YAP (possibly others).
With this method if I am calling the leaf nodeall_nodes([d, e], X)
then it returnsX = [d, e]
, is there a way to not return the nodes that were called, even if they are leaves?.
– user9441470
Nov 8 at 10:54
1
Try modifying thefindall/4
goal argument to(leaf(Node, Leaf), Node == Leaf)
.
– Paulo Moura
Nov 8 at 10:57
It does not work at all with this
– user9441470
Nov 8 at 10:59
1
Yes, it does. Likely you made a typo modifying thefindall/4
goal argument. You wantfindall(Leaf, (leaf(Node, Leaf), Node == Leaf), Leaves, Tail)
. With this change your getL =
for the queryall_nodes([d, e], L)
.
– Paulo Moura
Nov 8 at 11:03
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can take advantage of the de facto standard findall/4
(*) predicate to solve the problem. This predicate is a variant of the standard findall/3
predicate that allows passing a tail for the list of solutions collected by the predicate. For example:
?- findall(N, (N=1; N=2; N=3), L, [4,5]).
L = [1, 2, 3, 4, 5].
In the following solution, I have renamed predicates and variables for clarity and modified your node leaf predicate:
is_a(a, b).
is_a(a, c).
is_a(b, d).
is_a(b, e).
is_a(c, f).
is_a(c, g).
leaf(Leaf, Leaf) :-
+ is_a(Leaf, _).
leaf(Node, Leaf) :-
is_a(Node, Child),
leaf(Child, Leaf).
all_nodes(, ).
all_nodes([Node| Nodes], Leaves):-
findall(Leaf, leaf(Node, Leaf), Leaves, Tail),
all_nodes(Nodes, Tail).
Sample calls:
?- all_nodes([b, c], X).
X = [d, e, f, g].
?- all_nodes([a], X).
X = [d, e, f, g].
?- all_nodes([b], X).
X = [d, e].
(*) It's a built-in predicate in GNU Prolog, JIProlog, Lean Prolog, O-Prolog, SICStus Prolog, SWI-Prolog, XSB, and YAP (possibly others).
With this method if I am calling the leaf nodeall_nodes([d, e], X)
then it returnsX = [d, e]
, is there a way to not return the nodes that were called, even if they are leaves?.
– user9441470
Nov 8 at 10:54
1
Try modifying thefindall/4
goal argument to(leaf(Node, Leaf), Node == Leaf)
.
– Paulo Moura
Nov 8 at 10:57
It does not work at all with this
– user9441470
Nov 8 at 10:59
1
Yes, it does. Likely you made a typo modifying thefindall/4
goal argument. You wantfindall(Leaf, (leaf(Node, Leaf), Node == Leaf), Leaves, Tail)
. With this change your getL =
for the queryall_nodes([d, e], L)
.
– Paulo Moura
Nov 8 at 11:03
add a comment |
up vote
1
down vote
accepted
You can take advantage of the de facto standard findall/4
(*) predicate to solve the problem. This predicate is a variant of the standard findall/3
predicate that allows passing a tail for the list of solutions collected by the predicate. For example:
?- findall(N, (N=1; N=2; N=3), L, [4,5]).
L = [1, 2, 3, 4, 5].
In the following solution, I have renamed predicates and variables for clarity and modified your node leaf predicate:
is_a(a, b).
is_a(a, c).
is_a(b, d).
is_a(b, e).
is_a(c, f).
is_a(c, g).
leaf(Leaf, Leaf) :-
+ is_a(Leaf, _).
leaf(Node, Leaf) :-
is_a(Node, Child),
leaf(Child, Leaf).
all_nodes(, ).
all_nodes([Node| Nodes], Leaves):-
findall(Leaf, leaf(Node, Leaf), Leaves, Tail),
all_nodes(Nodes, Tail).
Sample calls:
?- all_nodes([b, c], X).
X = [d, e, f, g].
?- all_nodes([a], X).
X = [d, e, f, g].
?- all_nodes([b], X).
X = [d, e].
(*) It's a built-in predicate in GNU Prolog, JIProlog, Lean Prolog, O-Prolog, SICStus Prolog, SWI-Prolog, XSB, and YAP (possibly others).
With this method if I am calling the leaf nodeall_nodes([d, e], X)
then it returnsX = [d, e]
, is there a way to not return the nodes that were called, even if they are leaves?.
– user9441470
Nov 8 at 10:54
1
Try modifying thefindall/4
goal argument to(leaf(Node, Leaf), Node == Leaf)
.
– Paulo Moura
Nov 8 at 10:57
It does not work at all with this
– user9441470
Nov 8 at 10:59
1
Yes, it does. Likely you made a typo modifying thefindall/4
goal argument. You wantfindall(Leaf, (leaf(Node, Leaf), Node == Leaf), Leaves, Tail)
. With this change your getL =
for the queryall_nodes([d, e], L)
.
– Paulo Moura
Nov 8 at 11:03
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can take advantage of the de facto standard findall/4
(*) predicate to solve the problem. This predicate is a variant of the standard findall/3
predicate that allows passing a tail for the list of solutions collected by the predicate. For example:
?- findall(N, (N=1; N=2; N=3), L, [4,5]).
L = [1, 2, 3, 4, 5].
In the following solution, I have renamed predicates and variables for clarity and modified your node leaf predicate:
is_a(a, b).
is_a(a, c).
is_a(b, d).
is_a(b, e).
is_a(c, f).
is_a(c, g).
leaf(Leaf, Leaf) :-
+ is_a(Leaf, _).
leaf(Node, Leaf) :-
is_a(Node, Child),
leaf(Child, Leaf).
all_nodes(, ).
all_nodes([Node| Nodes], Leaves):-
findall(Leaf, leaf(Node, Leaf), Leaves, Tail),
all_nodes(Nodes, Tail).
Sample calls:
?- all_nodes([b, c], X).
X = [d, e, f, g].
?- all_nodes([a], X).
X = [d, e, f, g].
?- all_nodes([b], X).
X = [d, e].
(*) It's a built-in predicate in GNU Prolog, JIProlog, Lean Prolog, O-Prolog, SICStus Prolog, SWI-Prolog, XSB, and YAP (possibly others).
You can take advantage of the de facto standard findall/4
(*) predicate to solve the problem. This predicate is a variant of the standard findall/3
predicate that allows passing a tail for the list of solutions collected by the predicate. For example:
?- findall(N, (N=1; N=2; N=3), L, [4,5]).
L = [1, 2, 3, 4, 5].
In the following solution, I have renamed predicates and variables for clarity and modified your node leaf predicate:
is_a(a, b).
is_a(a, c).
is_a(b, d).
is_a(b, e).
is_a(c, f).
is_a(c, g).
leaf(Leaf, Leaf) :-
+ is_a(Leaf, _).
leaf(Node, Leaf) :-
is_a(Node, Child),
leaf(Child, Leaf).
all_nodes(, ).
all_nodes([Node| Nodes], Leaves):-
findall(Leaf, leaf(Node, Leaf), Leaves, Tail),
all_nodes(Nodes, Tail).
Sample calls:
?- all_nodes([b, c], X).
X = [d, e, f, g].
?- all_nodes([a], X).
X = [d, e, f, g].
?- all_nodes([b], X).
X = [d, e].
(*) It's a built-in predicate in GNU Prolog, JIProlog, Lean Prolog, O-Prolog, SICStus Prolog, SWI-Prolog, XSB, and YAP (possibly others).
edited Nov 8 at 10:28
answered Nov 8 at 9:31
Paulo Moura
10.6k21325
10.6k21325
With this method if I am calling the leaf nodeall_nodes([d, e], X)
then it returnsX = [d, e]
, is there a way to not return the nodes that were called, even if they are leaves?.
– user9441470
Nov 8 at 10:54
1
Try modifying thefindall/4
goal argument to(leaf(Node, Leaf), Node == Leaf)
.
– Paulo Moura
Nov 8 at 10:57
It does not work at all with this
– user9441470
Nov 8 at 10:59
1
Yes, it does. Likely you made a typo modifying thefindall/4
goal argument. You wantfindall(Leaf, (leaf(Node, Leaf), Node == Leaf), Leaves, Tail)
. With this change your getL =
for the queryall_nodes([d, e], L)
.
– Paulo Moura
Nov 8 at 11:03
add a comment |
With this method if I am calling the leaf nodeall_nodes([d, e], X)
then it returnsX = [d, e]
, is there a way to not return the nodes that were called, even if they are leaves?.
– user9441470
Nov 8 at 10:54
1
Try modifying thefindall/4
goal argument to(leaf(Node, Leaf), Node == Leaf)
.
– Paulo Moura
Nov 8 at 10:57
It does not work at all with this
– user9441470
Nov 8 at 10:59
1
Yes, it does. Likely you made a typo modifying thefindall/4
goal argument. You wantfindall(Leaf, (leaf(Node, Leaf), Node == Leaf), Leaves, Tail)
. With this change your getL =
for the queryall_nodes([d, e], L)
.
– Paulo Moura
Nov 8 at 11:03
With this method if I am calling the leaf node
all_nodes([d, e], X)
then it returns X = [d, e]
, is there a way to not return the nodes that were called, even if they are leaves?.– user9441470
Nov 8 at 10:54
With this method if I am calling the leaf node
all_nodes([d, e], X)
then it returns X = [d, e]
, is there a way to not return the nodes that were called, even if they are leaves?.– user9441470
Nov 8 at 10:54
1
1
Try modifying the
findall/4
goal argument to (leaf(Node, Leaf), Node == Leaf)
.– Paulo Moura
Nov 8 at 10:57
Try modifying the
findall/4
goal argument to (leaf(Node, Leaf), Node == Leaf)
.– Paulo Moura
Nov 8 at 10:57
It does not work at all with this
– user9441470
Nov 8 at 10:59
It does not work at all with this
– user9441470
Nov 8 at 10:59
1
1
Yes, it does. Likely you made a typo modifying the
findall/4
goal argument. You want findall(Leaf, (leaf(Node, Leaf), Node == Leaf), Leaves, Tail)
. With this change your get L =
for the query all_nodes([d, e], L)
.– Paulo Moura
Nov 8 at 11:03
Yes, it does. Likely you made a typo modifying the
findall/4
goal argument. You want findall(Leaf, (leaf(Node, Leaf), Node == Leaf), Leaves, Tail)
. With this change your get L =
for the query all_nodes([d, e], L)
.– Paulo Moura
Nov 8 at 11:03
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53200160%2fgathering-results-of-methods-in-one-list-with-prolog%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
findall(...)
has a list as its third argument. So when you callfindall(L, find_nodes(H, L), R)
.R
is a list. So[R|Res]
is a list whose first element is itself a list,R
. Your other issue is your base case.all_nodes(, _)
says that all nodes of an empty list is anything you want since_
is an anonymous variable. It can be anything.– lurker
Nov 8 at 1:06
@lurker
all_nodes(, _)
didnt really know what else to put there, probablycould also work. But how can I do it without using
findall
because when i do it without and call the function recursively while replacingfindall
to justfind_nodes
then it takes only thed
and goes to the next head.– user9441470
Nov 8 at 1:14
1
Well,
_
does not work because it really does mean that your rule says, finding the nodes for the empty list is anything is a successful result, which obviously isn't logical.would be more logical, would it not? Isn't the result of finding all nodes in an empty tree an empty list specifically?
– lurker
Nov 8 at 1:59
1
You can use
findall
. You just can't directly use the result the way you are trying to use it. You would need to concatenate the result to your current list of known nodes.– lurker
Nov 8 at 2:00
1
SWI Prolog also has
append(ListOfLists, List)
you can check out.– lurker
Nov 8 at 2:07