RCHQ9+/Go: Difference between revisions
< RCHQ9+
Content added Content deleted
m (Update example session for current go tooling. (Remarkably, the source code does not need an update. It was posted in 2011, pre-Go 1.0, and still compiles and runs just fine today with the most recent version of Go.)) |
m (Fixed syntax highlighting.) |
||
Line 1: | Line 1: | ||
{{implementation|HQ9+}}{{collection|RCHQ9+}} |
{{implementation|HQ9+}}{{collection|RCHQ9+}} |
||
This interpreter accepts HQ9+ source as the first command line argument. |
This interpreter accepts HQ9+ source as the first command line argument. |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 71: | Line 71: | ||
var a int |
var a int |
||
var q = `</ |
var q = `</syntaxhighlight> |
||
{{out|Example session building and running program}} |
{{out|Example session building and running program}} |
||
<pre> |
<pre> |
Latest revision as of 10:14, 1 September 2022
RCHQ9+/Go is an implementation of HQ9+.
Other implementations of HQ9+.
RCHQ9+/Go is part of RCHQ9+. You may find other members of RCHQ9+ at Category:RCHQ9+.
This interpreter accepts HQ9+ source as the first command line argument.
package main
import (
"fmt"
"os"
)
func main() {
if len(os.Args) < 2 {
return
}
for _, c := range os.Args[1] {
switch c {
case 'H':
fmt.Println("hello, world")
case 'Q':
fmt.Printf("%s%c%s%c\n", q, 96, q, 96)
case '9':
const l1t = " of beer on the wall"
const l2t = " of beer.\nTake one down, pass it around,\n"
const l1p = " bottles"+l1t
const l2p = " bottles"+l2t
fmt.Print(99, l1p, ",\n", 99, l2p)
for n := 98; n > 1; n-- {
fmt.Print(n, l1p, ".\n\n", n, l1p, ",\n", n, l2p)
}
fmt.Print("One bottle"+l1t+".\n\n")
fmt.Print("One bottle"+l1t+",\nOne bottle"+l2t+"No"+l1p+".\n")
case '+':
a++
}
}
}
var a int
var q = `package main
import (
"fmt"
"os"
)
func main() {
if len(os.Args) < 2 {
return
}
for _, c := range os.Args[1] {
switch c {
case 'H':
fmt.Println("hello, world")
case 'Q':
fmt.Printf("%s%c%s%c\n", q, 96, q, 96)
case '9':
const l1t = " of beer on the wall"
const l2t = " of beer.\nTake one down, pass it around,\n"
const l1p = " bottles"+l1t
const l2p = " bottles"+l2t
fmt.Print(99, l1p, ",\n", 99, l2p)
for n := 98; n > 1; n-- {
fmt.Print(n, l1p, ".\n\n", n, l1p, ",\n", n, l2p)
}
fmt.Print("One bottle"+l1t+".\n\n")
fmt.Print("One bottle"+l1t+",\nOne bottle"+l2t+"No"+l1p+".\n")
case '+':
a++
}
}
}
var a int
var q = `
- Example session building and running program:
$ go build HQ9+.go $ ./HQ9+ H+H hello, world hello, world
- Another, running Q output:
$ ./HQ9+ Q >q.go $ go run q.go H hello, world