I have to represent [[fruits],[ ] ]
in dot notation form in Prolog, and below is how I did it ,but something tells me this is wrong because I have expanded [[ ]]
too, is this incorrect ?
.([fruits],[[ ]] )
.(.(fruits, []),.([],[])
I have to represent [[fruits],[ ] ]
in dot notation form in Prolog, and below is how I did it ,but something tells me this is wrong because I have expanded [[ ]]
too, is this incorrect ?
.([fruits],[[ ]] )
.(.(fruits, []),.([],[])
Originally in prolog there was no
[]
and thevector
was always constructed using the.
.Here is an example from a 1979y paper by David Warren [*36'footnote] :
testing and demonstration ...
The above works in yap , eclipse , gprolog , xsb. However it does not work in swipl (see appendix).
concatenated
as presented in the paper is exactly the same as the typical-modern-day prolog implementation ofappend
, but with a different name , and a different marker for the end.The general pattern is that each element is separated from it's neighbour via the
.
.The last element is a marker to indicate the end. In Warren's example
nil
is the marker that indicates the end. The use ofnil
seems to have been a convention but not a requirement. Subsequent developments in prolog replaced the use ofnil
as the marker for the end with the use of[]
as the marker for the end.Warren's seminal example can be minimally rewritten to use
[]
instead ofnil
...Warren continues ...
Warren provides this example ...
testing and demonstration ...
That implementation of
(list(L))
, now 40 years ago , does not meet the modern expectations of a "logic" program ...... I don't know how to fix those problems .
When Warren writes ...
we write the functor as a
right-associative infix operator so that ...... I think he is referring to this peculiar and useful feature of the prolog
xfy
...It is reasonable to expect the
yfx
operator to behave in reverse ; whereasxfy
allows you to grab elements from the left and ignore the rest to the right , perhapsyfx
allows you to grab elements from the right and ignore the rest to the left ...[*36'footnote] --- https://www.era.lib.ed.ac.uk/bitstream/handle/1842/6648/Warren1978.pdf
appendix
Don't bother to try playing with
.
or[]
in swipl , neither the.
nor the[]
are functional as described .I reported a bug to swipl about
.
; assuming non-conformance to traditional and standard prolog systems was of interest; it appears that it is not.https://github.com/SWI-Prolog/issues/issues/55
The author of swipl makes the suggestion of using
term_expansion
, however neither the use ofterm_expansion
norgoal_expansion
can fix the following basic compatibility issues.... suggesting to me that perhaps the author of swipl does not know prolog very well (term_expansion?!??!) or is not interested in prolog conformance or is interested in establishing vendor lock-in .
Well, the
./2
is what is in Lisp known as thecons
. It contains two parameters: a head the element, and a tail. The tail can be the empty list[]
, or anothercons
.Let us first look at the term we have to convert:
What we see is an outer list with two elements (we will ignore these elements for now). So that means that we have a structure like:
Now of course we still need to fill in
Item1
andItem2
.Item2
is not hard: it is the empty list[]
so:Item1
on the other hand is a list with one element, so the structure is:With
Item11
the item of that sublist. That item isfruits
, so that means that:If we put these all together, we obtain:
If we enter this in GNU-Prolog (
gprolog
), we get:gprolog
thus can be a tool to do verification, since it will convert the dot notation into the syntactical sugar for a list.In addition to what Willem wrote, you can always use
write_canonical/1
to obtain the canonical representation of any term.For example, in your case:
This solves the task, and shows that you have expanded the list
[[]]
correctly.In particular, we have:
That's right: This is a list with a single element, which is
[]
as indicated by the first argument of the'.'/2
term. Since it is the only element, the second argument is also[]
.