Last active
March 28, 2026 13:07
-
-
Save cocoa1231/6c05f7d81da85933efed3d089569a2d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
| type Scalable interface { | |
| Scale(float64) | |
| } | |
| type Point struct { | |
| X, Y float64 | |
| } | |
| func (p *Point) Scale(s float64) { | |
| p.X *= s | |
| p.Y *= s | |
| } | |
| func Reverse(s Scalable) { | |
| s.Scale(-1) | |
| } | |
| func main() { | |
| p := &Point{1., 2.} | |
| fmt.Printf("Reversal of %v =", p) | |
| Reverse(p) | |
| fmt.Printf(" %v\n", p) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Runtime output
Build output