News for hackers. Stuff that matters.
Re:Namedtuple in a Post-Dataclasses World by msravi on Wednesday July 21, 2021 @12:09PM (#27908104)
The syntax is a lot more intuitive in Julia:

julia> point = (x=1, y=2)

(x = 1, y = 2)

julia> point.x

1

julia> point.y

2

julia> dump(point)

NamedTuple{(:x, :y), Tuple{Int64, Int64}}

  x: Int64 1

  y: Int64 2
Re:Namedtuple in a Post-Dataclasses World by bobbylarrybobby on Wednesday July 21, 2021 @12:16PM (#27908221)
And to create one as an anonymous type, you can use the `@NamedTuple` macro:

    julia> @NamedTuple{x::Int, y::String}
    NamedTuple{(:x, :y), Tuple{Int64, String}}
Re:Namedtuple in a Post-Dataclasses World by rdtsc on Wednesday July 21, 2021 @03:49PM (#27911187)
I guess one difference is that when you inspect it, it doesn't indicate that it is a `point`, just that it's named tuple of two variables, so it's not exactly equivalent.
Re:Namedtuple in a Post-Dataclasses World by mdcfrancis on Wednesday July 21, 2021 @03:21PM (#27910825)
they are also, type stable, strongly typed and have the same overhead as a struct. So an array of NamedTuples takes the minimal space and allocation.