Skip to content

Instantly share code, notes, and snippets.

@naranyala
Last active July 28, 2025 16:28
Show Gist options
  • Select an option

  • Save naranyala/92f33c4d9f56d98d0a6eb5ee7db8a0c3 to your computer and use it in GitHub Desktop.

Select an option

Save naranyala/92f33c4d9f56d98d0a6eb5ee7db8a0c3 to your computer and use it in GitHub Desktop.
for the community, a getter setter implementation of nim programming
type
Person* = object
name*: string
# Getter and setter procedures
proc getName*(p: Person): string =
## Getter for person's name
p.name
proc setName*(p: var Person, value: string): bool =
## Setter for person's name with validation
if value.len == 0:
return false # Validation failed
p.name = value
true # Validation succeeded
when isMainModule:
var person: Person
if person.setName("Alice"):
echo person.getName() # Outputs: Alice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment