sergiotaborda / lense-lang

The Lense Language Compiler
1 stars 0 forks source link

Add support for Indexers #19

Closed sergiotaborda closed 8 years ago

sergiotaborda commented 8 years ago

Add support for indexers. Indexers are like properties but have any number parameters. These parameters are used to index the property value. This is used in sequences , tuples and maps and can be extented for other uses like matrices, for example.

String name = array[1]; Integer v = matrix[2, 3];

class Matriz {

private Array array = new Array(100);

constructor Matriz (maxRows: Integer, maxColumns : Integer);

public [row : Integer, col : Integer ] : Integer { get { return array [col + row * maxColumns ]; } set(value){ array [col + row * maxColumns ] = value; } } }

Indexes are differentiated from properties because have no name and have parameters and from methods because parameters are enclosed in [ ] and not ( ). This acts as a mnemonic to how to invoke them.

sergiotaborda commented 8 years ago

This is currently supported. Both get and set block are mandatory when definition is not abstract.