Skip to content

Map exploration #23

@mattbasta

Description

@mattbasta

I've been compiling this list for a while and would rather keep it here, since I need to reboot my computer.

Once panics are implemented, the next big thing to do is implement maps. Functionally, maps don't need to be perfect for the first iteration, but ideally the syntax for map literals should remain fairly stable. Here's what the manual instantiation of a map would look like:

var m = new Map<string, int>(100);  # First param is initial capacity
m.set('foo', 123);
var y = m.get('foo');
var a = m.has('foo');

Additionally, I've considered adding a few new sugar operators:

var doesContain = m has 'foo'; # Similar to `in` but reversed
var value = m['foo'];  # [] operator overload

Literal syntax ideas:

  • JS:

    var x = {foo: 'bar', 'abc': 'def', [1 + 2]: 'zap'};
  • Python:

    x = {'foo': 'bar', 1 + 2: 'zap'}
  • Go:

    var x = map[string]int {"foo": 123, "x" + "y": 456}
  • PHP:

    $x = array('foo' => 123, 'x' . 'y' => 456);
    $y = ['foo' => 123, 'x' . 'y' => 456];
  • Ruby:

    x = {'foo' => 123, 'x' + 'y' => 456}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions