Logo

Programming-Idioms

  • Kotlin
  • Perl
  • Ruby
x = {one: 1, two: 2}
val x = mutableMapOf<String, Int>()
x["one"] = 1
x["two"] = 2
val x = mutableMapOf<String, Int>().apply { 
    this["one"] = 1
    this["two"] = 2
}
val x = mapOf("one" to 1, "two" to 2)

Only if performance isn't critical. See the docs.
my %x = ( 
    name => 'Roboticus',
    'foo bar' => 'joe'
);

The '=>' operator autoquotes the word on its left if it begins with a letter or underscore and is composed only of letters, digits and underscores. Otherwise quotes are required.
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;

use Ada.Containers;
declare
   package Maps is new Indefinite_Hashed_Maps (Key_Type => String,
                                               Element_Type => Integer,
                                               Hash => Ada.Strings.Hash,
                                               Equivalent_Keys => "=");
      
   use Maps;
      
   X : Map := Empty_Map;
begin
   X.Insert ("One", 1);
   X.Insert ("Two", 2);
   X.Insert ("Three", 3);
end;

New implementation...