RCHQ9+/Go: Difference between revisions
< RCHQ9+
Content added Content deleted
(Go solution) |
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.)) |
||
Line 72: | Line 72: | ||
var a int |
var a int |
||
var q = `</lang> |
var q = `</lang> |
||
{{out|Example session building and running program}} |
|||
(Gosh that made cut and paste easier...cut once, paste twice...) |
|||
Anyway, example session: |
|||
<pre> |
<pre> |
||
$ go build HQ9+.go |
|||
$ HQ9+ H+H |
$ ./HQ9+ H+H |
||
hello, world |
hello, world |
||
hello, world |
hello, world |
||
</pre> |
</pre> |
||
Another, |
{{out|Another, running Q output}} |
||
<pre> |
<pre> |
||
$ HQ9+ Q >q.go |
$ ./HQ9+ Q >q.go |
||
$ |
$ go run q.go H |
||
$ 8l q.8 |
|||
$ 8.out H |
|||
hello, world |
hello, world |
||
</pre> |
</pre> |
Revision as of 19:11, 18 April 2018
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. <lang go>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 = `</lang>
- 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