Quick actions

cmd+k|ctrl+k

Navigation

Languages

Untitled

Snippet info

Language

Nim

Visibility

unlisted

Author

legacy-anonymous

Created

2017-01-13T19:38:39Z

Updated

2017-01-13T19:38:39Z

type
  Person = ref object of RootObj
    name*: string  # the * means that `name` is accessible from other modules
    age*: int       # no * means that the field is hidden from other modules
  ValidPerson = concept x
    x.name.isEmptyOrNil() == false
    x.age >= 0

proc printPerson(person: ValidPerson) =
  echo person.name
  echo person.age

var a = Person(name: "bob", age: 5)
var b = Person(name: "", age: 5)
var c = Person(name: "bob", age: -1)

echo (a is ValidPerson)
echo (b is ValidPerson)
echo (c is ValidPerson)

#printPerson(a)
#printPerson(b)
#printPerson(c)
INFO