1
votes

First of all, if the answer to my question is here or here I couldn't find it so please don't kill me.

I want to write a Prolog predicate which returns a list of this form:

(list[elem, elem2], list[elem3, elem4], list[elem5, elem6]).  

now I can think of several ways to return a list of this form:

([elem, elem2], [elem3, elem4],[elem5, elem6]).

but how do I make the word "list" appear there as well? what is it even? a fact? another predicate?

Thanks in advance!

1
Welcome to StackOverflow where we don't kill OP.Guy Coder
Why do you need the word "list" to designate the lists?lurker

1 Answers

0
votes

You can create a compound term using the standard =../3 built-in predicate. For example:

| ?- Term =.. [list, [1,2,3]].

Term = list([1,2,3])
yes

But note that the syntax that you're trying to use, list[elem5, elem6], is not valid. Are you trying to mimic an array representation? If so, maybe use instead list(elem5, elem6)? For example:

| ?- Term =.. [list, elem5, elem6].

Term = list(elem5, elem6)
yes