句子形式Prolog的输出

时间:2015-05-26 10:17:09

标签: prolog swi-prolog

我希望此输出为字符串格式。 怎么办呢?

我得到的输出:

[[[[a]|fat]|man],[[[[[was]|walking]|quickly],to],[[[[the]]|end],[of,[[[the]|long]|corridor]]]]]

预期产出:

a fat man was walking quickly to the end of the long corridor

1 个答案:

答案 0 :(得分:3)

您可以使用flatten/2 atomic_list_concat/3

:- X = [[[[a]|fat]|man],[[[[[was]|walking]|quickly],to],[[[[the]]|end],[of,[[[the]|long]|corridor]]]]],
   flatten(X,Y),
   atomic_list_concat(Y,' ',Z).
X = [[[[a]|fat]|man], [[[[[was]|walking]|quickly], to], [[[[the]]|end], [of, [[...|...]|...]]]]],
Y = [a, fat, man, was, walking, quickly, to, the, end|...],
Z = 'a fat man was walking quickly to the end of the long corridor'.