Harshita Jhavar
Harshita Jhavar

Reputation: 145

Output in Sentence Form Prolog

I want this output to be in string format. How can it be done?

Output I am getting:

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

Expected Output:

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

Upvotes: 0

Views: 97

Answers (1)

repeat
repeat

Reputation: 18726

You could use flatten/2 and 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'.

Upvotes: 3

Related Questions