gpt-4-0314· openai
Suzhen/CodeChat
Write a haiku generator in Prolog.
- User
Write a haiku generator in Prolog.
- Assistant
Here is a basic haiku generator in Prolog:
haiku_generator.pl:% 5 syllable lines line5(["the", "summer", "moon"]). line5(["mountain", "trail", "hello"]). line5(["fresh", "snow", "on", "grass"]). % 7 syllable lines line7(["reflects", "on", "the", "glassy", "lake"]). line7(["hear", "a", "distant", "bird", "calling"]). line7(["mingling", "with", "green", "leaves"]). % Haiku generator haiku(L1, L2, L3) :- line5(L1), line7(L2), line5(L3).To use this haiku generator, follow these steps:
- Save the above code to a file named
haiku_generator.pl. - Open the SWI-Prolog compiler.
- Load the saved file using the following command:
[haiku_generator]. - Query the haiku generator using the following command:
haiku(FirstLine, SecondLine, ThirdLine).
Sample output for the haiku generator:
?- haiku(FirstLine, SecondLine, ThirdLine). FirstLine = ['the', 'summer', 'moon'], SecondLine = ['hear', 'a', 'distant', 'bird', 'calling'], ThirdLine = ['fresh', 'snow', 'on', 'grass'] ; FirstLine = ['mountain', 'trail', 'hello'], SecondLine = ['reflects', 'on', 'the', 'glassy', 'lake'], ThirdLine = ['the', 'summer', 'moon']. - Save the above code to a file named