Guest User

Untitled

a guest
Sep 9th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.37 KB | None | 0 0
  1. type
  2.   # An object which will be allocated on stack
  3.   Animal = object
  4.     name: string
  5.     legs: int
  6.  
  7. # Non ref objects (stack objects) cannot be mutated
  8. # inside methods
  9. proc setName(a: Animal, name: string) =
  10.   a.name = name
  11.  
  12. var dog = Animal(name: "shadow", legs: 4)
  13. dog.name = "lucy"
  14. dog.setName("jimmy")
  15. # Object types can be converted to string with $
  16. echo $dog
Add Comment
Please, Sign In to add comment