From 64b1c50ed9f13a2b409073ad5865ae61760cde7c Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Mon, 27 Aug 2012 22:28:15 -0600 Subject: [PATCH] added file to play with methods --- methods/methods.go | 27 +++++++++++++++++++++++++++ tags | 6 ++++++ 2 files changed, 33 insertions(+) create mode 100644 methods/methods.go create mode 100644 tags diff --git a/methods/methods.go b/methods/methods.go new file mode 100644 index 0000000..2405554 --- /dev/null +++ b/methods/methods.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" +) + +type vertex struct { + x, y float64 +} + +// note that this one can deal fine with a copy: +func (v vertex) abs() float64 { + return v.x + v.y +} + +// but this function needs access to the actual struct members +func (v *vertex) scale(s float64) { + v.x *= s + v.y *= s +} + +func main() { + v := vertex{1.1, 2.2} + fmt.Println(v.abs()) + v.scale(12) + fmt.Println(v.abs()) +} diff --git a/tags b/tags new file mode 100644 index 0000000..d01d39b --- /dev/null +++ b/tags @@ -0,0 +1,6 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ +!_TAG_PROGRAM_NAME Exuberant Ctags // +!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ +!_TAG_PROGRAM_VERSION 5.8 //