Forums

Does cobra have special syntax for immutable types?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Does cobra have special syntax for immutable types?

Postby Nefarel » Fri Mar 22, 2013 7:31 am

In C# it is very verbose to create immutable type. Does Cobra have some shorter syntax?:)
Nefarel
 
Posts: 6

Re: Does cobra have special syntax for immutable types?

Postby Charles » Fri Mar 22, 2013 8:38 am

It does not. Do you have suggestions?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Does cobra have special syntax for immutable types?

Postby torial » Fri Mar 22, 2013 1:39 pm

Charles wrote:It does not. Do you have suggestions?


How about using the "is readonly" attribute for classes? Coupled with any properties must be set by the constructor (or object initializer), and are automatically readonly (kind of like static class in C#, except I think you have to explicitly say each item in the class is static).
torial
 
Posts: 229
Location: IA

Re: Does cobra have special syntax for immutable types?

Postby hopscc » Sat Mar 23, 2013 4:04 am

What type of immutability are you looking for ?

Kinds of Immutability

For MP perhaps better to default to immutable objects and have some syntax to explicitly relax that....
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Does cobra have special syntax for immutable types?

Postby kirai84 » Sat Mar 23, 2013 4:36 am

hopscc wrote:What type of immutability are you looking for ?

Kinds of Immutability

For MP perhaps better to default to immutable objects and have some syntax to explicitly relax that....


Simply all the fields are readonly, at least by default, when a class is marked as "is readonly". They did it in Oxygen and its great when you try to make things in more functional way. It's still far from make Cobra a really handy language for that type of programming though.
kirai84
 
Posts: 24

Re: Does cobra have special syntax for immutable types?

Postby Charles » Tue Mar 26, 2013 11:51 pm

What about collections? If I create a list like so:
var name = ['abc', 'python', 'cobra']

And I want the list to be immutable, what idiom/syntax should we use?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Does cobra have special syntax for immutable types?

Postby kirai84 » Thu Mar 28, 2013 2:45 am

Charles wrote:What about collections? If I create a list like so:
var name = ['abc', 'python', 'cobra']

And I want the list to be immutable, what idiom/syntax should we use?

It could be
var name = readonly ['abc', 'python', 'cobra']

or
var name = const ['abc', 'python', 'cobra']
kirai84
 
Posts: 24

Re: Does cobra have special syntax for immutable types?

Postby hopscc » Fri Mar 29, 2013 8:26 pm

Why not use the existing declaration forms (augmented) instead of a variant syntax form for this one construct ?
extend the isname set ...

#No opinion on the exact keyword - for 'readonly' could use 'const' or 'immutable' 

# augment/provide a clarifying isname declaration
var name is readonly = ['abc', 'python', 'cobra']
# or
var name = ['abc', 'python', 'cobra'] to readonly


'to' is for casting type (and nilability) - casting immutability in the same way isnt a big step...

..
You can take the position that literals are already immutable anyway - just used for assignment/initialisation of a (modifiable) variable ...
In that case the casting/inference-from-assignment would be casting away the immutability.

var name = ['abc', 'python', 'cobra'] to mutable # or 'variable'/'nonconst'/'var',....


Similarly to casting to and from nilable, provide some punctuation for to and from mutability
var name = ['abc', 'python', 'cobra'] to * # '*' for mutable, '|' for immutable say - read as fuzzy vs rigid
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand


Return to Discussion

Who is online

Users browsing this forum: No registered users and 18 guests