Undefined values: Difference between revisions
m
→{{header|Go}}: clean up. no substantial code changes.
(Go solution) |
m (→{{header|Go}}: clean up. no substantial code changes.) |
||
Line 147:
# Successful (non panicking) use of initialized objects.
# One more quirky little feature involving a type switch on a nil interface.
<lang go>package main
▲import (
var (
Line 168 ⟶ 164:
status()
// initialize objects
s = make([]int, 1)
p = &s[0] // yes, reference element of slice just created
f = func() { fmt.Println("function call") }
i = user(0) // see user defined type just below
m = make(map[int]int)
c = make(chan int, 1)
Line 181 ⟶ 178:
type user int
func (
fmt.Println("method call")
}
func status() {
}
func reportPanic() {
Line 201 ⟶ 197:
}
func
defer reportPanic()
fmt.Println("s[0] =", s[0])
}
func
defer reportPanic()
fmt.Println("*p =", *p)
}
func
defer reportPanic()
f()
}
▲func nilInterface() {
defer reportPanic()
Line 234 ⟶ 229:
}
func
defer reportPanic()
fmt.Println("m[0] =", m[0])
}
func
defer reportPanic()
c <- 0
fmt.Println("<-c received", <-c)
}</lang>▼
▲</lang>
Output:
<pre>
|