Collections — short form syntax

Thanks to “Programming Clojure” by Stuart Halloway and Aaron Bedra I finally found syntax for all the basic collections.

Array (fixed size):
#[ 3, 4 ]

Vector (can be resized):
[ 3, 15 ]

Dictionary (map):
[ foo: 3, bar: 17 ]

( 3, 4 )

Named tuple (OK, it is exactly the same as regular tuple, I am just showing the syntax):
( foo: 3, bar: 4 )

And the last one — list:
{ 3, 89 }

I think all of them make sense — tuple syntax should be related to passing arguments to a function. List syntax can be associated with statements block — like in C-like languages.

One thing that bothers me is spending braces just for one purpose. So maybe lists should be created with brackets after all:
~[ 3, 4 ]

Tagged , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: