Can the head of a list in prolog consist of multiple elements? -
for example if have list [1, 2| 3]
, head 1
, 2
, tail 3
? or head still 1
, tail 2, 3
?
note:
[1, 2| 3]
not list;[1, 2 | [3]]
is.
short answer: there one element in head, [1, 2| [3]]
syntactical sugar [1 | [2 | [3]]]
, list [1, 2, 3]
.
prolog's lists lisp lists: consist out of 2 possible values: empty list []
, , "cons" [h|t]
h
*head, , t
tail.
most prolog interpreters allow syntactical sugar [e1, e2, e3]
, [e1, e2, e3 | t]
. make more convient list processing.
Comments
Post a Comment