Advertisement
Guest User

Untitled

a guest
May 5th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. package main
  2. //go program to implement a portable VM
  3.  
  4. import (
  5. "fmt"
  6. )
  7. //int object struct
  8. type Int struct {
  9. value []int
  10. }
  11. //constructor for int struct
  12. func CreateInt(val int) Int {
  13. num := Int{value:[]int{val}}
  14. return num
  15. }
  16.  
  17. //adds an integer to the struct
  18. func (in Int) Addto(amount int) {
  19. in.value[0] += amount
  20. }
  21.  
  22.  
  23.  
  24. func main(){
  25. tester := CreateInt(8)
  26. tester.Addto(7)
  27. fmt.Println(tester)
  28. //{[15]}
  29. fmt.Println(len(tester.value))
  30. //1
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement