Created
February 27, 2015 23:12
-
-
Save scizzorz/91f00f0635fe5595f7d1 to your computer and use it in GitHub Desktop.
Testing nim constructors
This file contains 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
type Person = object | |
name: string | |
type Animal = object | |
kind: string | |
proc new(this: type Person, name: string): Person = | |
result.name = name | |
proc new(this: type Animal, kind: string): Animal = | |
result.kind = kind | |
var p = new(Person, "Hello!") | |
var a = Animal.new("Bear") | |
var b = Animal.new "Bunny" | |
echo(p.name) | |
echo(a.kind) | |
echo(b.kind) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment