/*
 * types.go
 *-------------------------------------------------------
 * Illustrate use of types and methods
 * Jim Fawcett, CSE775 - Distributed Objects, Spring 2016
 *-------------------------------------------------------
 *
 * The links below show how to build an almost generic container
 * https://golang.org/pkg/container/list/#example_   example use of list
 * https://golang.org/src/container/list/list.go     list.go source code
 */
 package main
 
 import (
   "fmt"
 )
 
 // Note:
 // Variables and functions with names that have lower-case first letter
 // are not visible outside defining package. If first letter is capitalized
 // they are visible.
 
 type Person struct {
   first string
   last string
   city string
 }
 
 // methods take type declaration before function names
 
 func (p Person) FirstName() string { 
   return p.first 
 }
 func (p Person) LastName() string { 
   return p.last 
 }
 func (p Person) City() string { 
   return p.city 
 }
 func (p Person) Init(firstName, lastName, city string) Person {
   p.first = firstName
   p.last = lastName
   p.city = city
   return p
 }
 func main() {
 
   tom := new(Person).Init("Thomas", "Smith", "Syracuse")
   fmt.Printf("\n  %v %v, %v", tom.FirstName(), tom.LastName(), tom.City())
   
   // this works too
   
   Sally := Person{"Sally", "Fields", "Los Angeles"}
   fmt.Printf("\n  %v %v, %v", Sally.FirstName(), Sally.LastName(), Sally.City())
   
   fmt.Println()
 }