Execute HQ9+: Difference between revisions

Content added Content deleted
(Added Julia language)
Line 1,075: Line 1,075:
return out;
return out;
}</lang>
}</lang>

=={{header|Julia}}
{{works with|Julia|0.6}}
<lang julia>hello() = println("Hello, world!")
quine() = println(src)
bottles() = for i = 99:-1:1 print("\n$i bottles of beer on the wall\n$i bottles of beer\nTake one down, pass it around\n$(i-1) bottles of beer on the wall\n") end
acc = 0
incr() = global acc += 1

const dispatch = Dict(
'h' => hello,
'q' => quine,
'9' => bottles,
'+' => incr)

if length(ARGS) < 1
println("Usage: julia ./HQ9+.jl file.hq9")
exit(1)
else
file = ARGS[1]
end

try
open(file) do s
global src = readstring(s)
end
catch
warning("can't open $file")
exit(1)
end

for i in lowercase(src)
if haskey(dispatch, i) dispatch[i]() end
end</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==