Primitive type is not a struct type?

code

def is_struct?(t : T) : Bool forall T
  {% begin %}
    {{ T.struct? }}
  {% end %}
end

p! is_struct? 1
p! is_struct? 1.0
p! is_struct? StaticArray[0]

output

is_struct?(1) # => false
is_struct?(1.0) # => false
is_struct?(StaticArray[0]) # => true

how to detect primitive type?

T.primitive?

I don’t think there’s a built-in way to do this?

Could you check whether it’s a sub-type of Value ?

def is_value?(t : T) : Bool forall T
  {% begin %}
    {{ T < Value }}
  {% end %}
end
2 Likes

thank you very much