-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
Consider the following object type:
type
User = object
name: string
age: int
last_online: float
It's very common to write a constructor for such types, some may have many more fields than the above, having to write the name of each field gets tedious:
proc initUser(name: string, age: int): User =
User(
name: name,
age: age,
last_online: epochTime()
)
This RFC proposes to implement a short-hand syntax for the object construction syntax to simplify this code:
proc initUser(name: string, age: int): User =
User(
name,
age,
last_online: epochTime()
)
The variable names have to match that of the field name, so User(foo, age)
won't work even if foo
is a string.
konsumlamm, planetis-m, a-mr, slangmgh, bluenote10 and 15 morejuancarlospaco, beef331 and avahe-kellenbergerhaxscramper and juancarlospacoxigoi and ghoomfrog
Metadata
Metadata
Assignees
Labels
No labels