Jump to content

Execute HQ9+: Difference between revisions

Line 1,207:
$hq9.run($in)
}</lang>
 
=={{header|Phix}}==
copied from [[99_Bottles_of_Beer#Phix|99_Bottles_of_Beer]]
<lang Phix>constant ninetynine = 99 -- (set this to 9 for testing)
 
function bottles(integer count)
if count=0 then return "no more bottles"
elsif count=1 then return "1 bottle" end if
if count=-1 then count = ninetynine end if
return sprintf("%d bottles",count)
end function
 
function bob(integer count)
return bottles(count)&" of beer"
end function
 
function up1(string bob)
-- Capitalise sentence start (needed just the once, "no more"=>"No more")
bob[1] = upper(bob[1])
return bob
end function
 
procedure ninetyninebottles()
string this = bob(ninetynine)
string that = "Take one down, pass it around,\n"
for i=ninetynine to 0 by -1 do
puts(1,up1(this)&" on the wall,\n")
puts(1,this&".\n")
if i=0 then that = "Go to the store, buy some more,\n"
elsif i=1 then that[6..8] = "it" end if
this = bob(i-1)
puts(1,that&this&" on the wall.\n\n")
end for
-- if getc(0) then end if
end procedure</lang>
the interpreter
<lang Phix>procedure hq9(string code)
integer accumulator = 0
for i=1 to length(code) do
switch(upper(code[i]))
case 'H': printf(1,"Hello, world!\n")
case 'Q': printf(1,"%s\n", code);
case '9': ninetyninebottles()
case '+': accumulator += 1
end switch
end for
end procedure
 
hq9("hq9+HqQ+Qq")</lang>
 
=={{header|PicoLisp}}==
7,820

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.