空集文字语法

0 crystal-lang

寻找正确的语法或者是否存在错误/粗略边缘:

Set{}

for empty hashes use '{} of KeyType => ValueType' <-wrong

Set{} of Char

expecting token '=>', not 'EOF' <-wrong

Set(Char){}

for empty hashes use '{} of KeyType => ValueType' <-wrong

Set(Char).new # not a literal

Set{'a'} # not an empty Set literal
Run Code Online (Sandbox Code Playgroud)

RX1*_*X14 6

没有一个,使用Set(Char).new.

设置文字,例如Set{'a'}实际编译为:

__tmp_var = Set(typeof('a')).new
__tmp_var << 'a'
__tmp_var
Run Code Online (Sandbox Code Playgroud)

因此使用空文字而不是使用时没有性能优势 Set(Char).new