This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
var s []int | |
fmt.Println(s, len(s), cap(s)) | |
if s == nil { | |
fmt.Println("nil!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defer func() { | |
if r := recover(); r != nil { | |
t.reportErrorAndStop() | |
} | |
}() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builtinActions = map[operationType]*action{ | |
asdasdd | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[]rune(input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ByteSlice []byte | |
func (p *ByteSlice) Write(data []byte) (n int, err error) { | |
slice := *p | |
// Again as above. | |
*p = slice | |
return len(data), nil | |
} | |
var b ByteSlice | |
fmt.Fprintf(&b, "This hour has %d days\n", 7) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Sequence []int | |
// Methods required by sort.Interface. | |
func (s Sequence) Len() int { | |
return len(s) | |
} | |
func (s Sequence) Less(i, j int) bool { | |
return s[i] < s[j] | |
} | |
func (s Sequence) Swap(i, j int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Sequence []int | |
// Method for printing - sorts the elements before printing | |
func (s Sequence) String() string { | |
sort.IntSlice(s).Sort() | |
return fmt.Sprint([]int(s)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str, ok := value.(string) | |
if ok { | |
fmt.Printf("string value is: %q\n", str) | |
} else { | |
fmt.Printf("value is not a string\n") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s := string(byteArray[:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if item, ok := cmd.Commands[parms[0]]; ok { |