79788720

Date: 2025-10-12 18:50:21
Score: 0.5
Natty:
Report link

is there a way to create array of Any?

Here are two ways to create an array of Any initialized with the named tuple (;some=missing):

These forms are not interchangeable when the value of the filling expression is mutable. The first with the fill! expression will use the same value for all elements. The second with the array comprehension will create a separate value for each element. For example, if the value expression is [], the first creates one empty mutable array used in all elements, and the second creates a separate empty mutable array for each element.

Why Vector{Any}((; some=missing), 10) fails?

The expression Vector{Any}((; some=missing), 10) fails because no method is defined for this case.
Constructor methods are only defined (as of Julia 1.12.0) for

Here is a try to define one:

Vector{T}(value::V, n) where {T, V <: T} = fill!(Vector{T}(undef, n), value)

With this definition, the expression Vector{Any}((; some=missing), 10) works.

Reasons:
  • Blacklisted phrase (1): is there a way
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): is there a
Posted by: user9712582