Dechenjm / crack-language

Automatically exported from code.google.com/p/crack-language
Other
0 stars 0 forks source link

Implement list and map constants. #42

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
(feature request)
It would be nice to have a shorthand for some default implementations of 
commonly used types, String, Array and Map.

This can be implemented in a separate module so as to not weigh the runtime 
down if not needed.

Maybe this can be done with operators, like
oper ""(ConstantString)
oper [](ConstantArray)
oper {}(ConstantRBMap)

Original issue reported on code.google.com by Conrad.S...@gmail.com on 3 Oct 2010 at 1:55

GoogleCodeExporter commented 9 years ago
I'm not really sure what you mean by this, can you give a more detailed example?

Original comment by mind...@gmail.com on 3 Oct 2010 at 2:39

GoogleCodeExporter commented 9 years ago
The shorthand would then be:

s:="this is a constant string";
a:=(1,2,3);
d:={"key1": value1, ...};

Original comment by Conrad.S...@gmail.com on 3 Oct 2010 at 5:26

GoogleCodeExporter commented 9 years ago
s := "this is a constant string" already works (type of 's' would be 
StaticString, a subclass of String).

For the sequence and mapping types, the plan is to allow:

  # create an immutable sequence
  s := [1, 2, 3];

  # initialize a sequence type
  List l = ['first', 'second', 'third'];

  # create an immutable map
  m := [ 'key1': 'value 1', 'key2': 'value 2' ];

  # initialize a map type
  RBTree m = [ 'key1': 'value1', 'key2': 'value2' ];

I would very much prefer curly-braces for map initializers, but unfortunately 
the curlies are already heavily overloaded.  In particular, this syntax would 
be ambiguous with the use of keyword arguments in a constructor:

  SomeClass a = { parm1: 'parm 1', parm2: 100 };

Original comment by mind...@gmail.com on 3 Oct 2010 at 8:33

GoogleCodeExporter commented 9 years ago
Could there maybe be a 'decorator' to show that the sequence or map is not 
immutable?

Original comment by Conrad.S...@gmail.com on 3 Oct 2010 at 9:33

GoogleCodeExporter commented 9 years ago
I'm not entirely sure that the sequences and maps need to be immutable - I 
originally thought that this might be useful as an optimization for sequences.

The C-like syntax will definitely create non-immutable objects (the second and 
fourth examples above are normal, mutable List and RBTree instances)

And in any case, you should be able get the language to do anything you want 
with annotations (coming up in 0.3).  You could, for example define an 
annotation that works like this:

s := @mut [1, 2, 3];  # create a mutable array

Original comment by mind...@gmail.com on 4 Oct 2010 at 10:55

GoogleCodeExporter commented 9 years ago
Accepting this for the implementation of the forms described.

Original comment by mind...@gmail.com on 5 Oct 2010 at 4:42

GoogleCodeExporter commented 9 years ago
This is now partially implemented in revision ac379d4f41ee
Specifically, sequences can be defined in initialization and in expressions 
when qualified by the container type.

What remains to be done:
- support this for maps
- integrate it with type inferencing
- allow registration of a default sequence and map generic to be used when the 
type cannot be otherwise inferred.

Original comment by mind...@gmail.com on 29 Mar 2011 at 11:34