I am trying to write a program which make the following:

?- g([2,3, [22,[3],9] ,4,[5],99],X).

X= [2,3,22,[3],9 ,4,5,99]

so it searches for lists in the given list and replace it by their elements without brackets [].

so I wrote this program:

The first block just searches for the first element in the list which is list
If there is no such element it returns [there_is_no_list].


The first block works in prolog perfectly.

The second block just search in the list for an element X and then split the list into a two lists one is the list of all elements before X and the second is the elements after X.


it also works fine in Prolog.

and the third block is append, and it joins two list together in a new list.

append([H|T],L,[H|U1]):- append(T,L,U1).

and the last part is:


when I give a query [2,[3],5] I get also [2,[3],5] and I really don't understand why it does this.

closed as off-topic by user40980, Jalayn, Dan Pichelman, BЈовић, Kilian Foth Aug 9 '13 at 7:27

  • This question does not appear to be about software engineering within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • why didn't you ask at Stack Overflow? – gnat Aug 8 '13 at 14:19

Your logic is flawed. Your first_list_in_the_list function looks for an empty list or a list with more than one element. The one element list gets ignored.

  • i didn't get what your idea is, when i apply the code first_list_in_the_list([1],X), i get the crrect answer which is X=[the_is_no_list], and if I apply first_list_in_the_list([[1]],X), i get X=[1], i don't think the fault is in first_list_in_the_list . – Kemo Aug 8 '13 at 16:20
  • There is a list [3] is a list with one element. – Michael Brown Aug 8 '13 at 17:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.