Magic 8-ball: Difference between revisions

Added Magic 8-ball example with CFEngine
(Magic 8-ball in various BASIC dialents)
(Added Magic 8-ball example with CFEngine)
Line 725:
 
</lang>
 
=={{header|CFEngine}}==
 
<lang cfengine3>
#!/usr/bin/env cf-agent --no-lock
bundle agent __main__
{
methods: "rosettacode_org:magic_8_ball";
}
body file control
{
namespace => "rosettacode_org";
}
bundle agent magic_8_ball
{
vars:
"_responses"
slist => {
"It is certain", "It is decidedly so", "Without a doubt",
"Yes definitely", "You may rely on it", "As I see it yes",
"Most likely", "Outlook good", "Signs point to yes", "Yes",
"Reply hazy try again", "Ask again later",
"Better not tell you now", "Cannot predict now",
"Concentrate and ask again", "Don't bet on it",
"My reply is no", "My sources say no", "Outlook not so good",
"Very doubtful",
};
"_selected_response"
int => randomint( 0, length( _responses) ),
unless => isvariable( "$(this.namespace):$(this.promiser)" );
 
"_consideration_time"
int => randomint( 3, 5),
unless => isvariable( "$(this.namespace):$(this.promiser)" );
 
commands:
"/bin/sleep $(_consideration_time)"
inform => "false",
handle => "consider",
depends_on => { "think" },
comment => "This magic 8 ball takes a few seconds to consider the answer
after you bring your question to mind.";
 
reports:
"Think about your question ..."
handle => "think";
 
"Response: $(with)"
with => nth( _responses, $(_selected_response) );
}</lang>
 
See https://docs.cfengine.com/docs/master/examples.html for a more complete example and introduction.
 
=={{header|Clojure}}==