Aliases in Nim

Nim doesn’t have an alias keyword, but you can still create aliases using templates. The syntax is:

alias_name: untyped = name_to_create_alias_for

Here’s an example:

template settings: untyped = my_object_1.my_logging_container.all_settings

settings.name = "test"
settings.log_level = "debug"
settings.flush_frequency = 1

he use case here is that you’re working with a complex, nested object, and you want to use an alias to reduce the amount of code on the screen without a loss of performance. Using an alias gives you exactly that.

See also: Nim Books

2 replies on “Aliases in Nim”

Leave a Reply

Your email address will not be published. Required fields are marked *