The list [[a,b]|c] in Prolog -
during exploration of different ways write down lists, intrigued following list [[a,b]|c]
appears in book 'prolog , natural language analysis' pereira , shieber (page 42 of digital edition).
at first thought such notation syntactically incorrect, have had [[a,b]|[c]]
, after using write_canonical/1
prolog returned '.'('.'(a,'.'(b,[])),c)
.
as far can see, corresponds following tree structure (although seems odd me structure end c
, without empty list @ end):
i cannot seem find corresponding notation using comma's , brackets though. thought correspond [[a,b],c]
(but returns different result write_canonical/1
).
is there no corresponding notation [[a,b]|c]
or looking @ wrong way?
i cannot seem find corresponding notation using comma's , brackets though.
there no corresponding notation, since technically speaking not real list.
prolog has syntacical sugar lists. list in prolog is, lisp list, linked list: every element either empty list []
, or node .(h,t)
h
head , t
tail. lists not "special" in prolog in sense intepreter handles them differently other term. of course lot of prolog libraries list processing, , use convention defined above.
to make complex lists more convenient, syntactical sugar invented. can write node .(h,t)
[h|t]
well. means in [[a,b]|c]
. have outer list, has 1 node .(h,c)
, ?
another list, 2 nodes , empty list h = .(a,.(b,[]))
.
technically speaking not consider "real" list, since tail of list should have either node ./2
, or empty list.
you can use variables like: [[a,b]|c]
in order unify tail c
further. here have sort of list [a,b]
first element (so list containing list) , open tail c
. if later instance ground c
c = []
, list [[a,b]]
.
Comments
Post a Comment