Hash delimiter =>

I feel like using “=>” as delimiter to associate the k/v can be confusing for new programmers coming over to enjoy the Crystal language.

What are thoughts on changing it OR being able to utilize something like “>>>” OR “<<>>” ?

I don’t think there have been any discussions around changing this, or allowing other values. => is used in a few other languages too so I can’t really imagine this being worth it.

Fair enough. Another question I have around hashes, is how come say when I want to “p!” something out for a hash.

p! {“Key” => “value”}

This will not work as I expect, will throw a error. Unless I assign it to a variable ,

But for the same thing, using arrays, this would be fine.

That’s because {} in this context is used to signify a block

def foo(&)
  yield
end

foo { "bar" } # => "bar"
2 Likes

In addition to what has been said, p!({"key" => "value"}) is a way to work around that.

1 Like