nemerle
nemerle copied to clipboard
Support 'out def' and 'out mutable' for out parameters.
TryGet(a : out int) : bool { a = 1; true }
// #1: Regular - we get mutable variable :(
mutable a;
TryGet(out a);
mutable b;
TryGet(out b);
// #2: Same for mutable but shorter than #1
TryGet(out mutable a) && TryGet(out mutable b);
a = 1; // OK
// #3: Create one time initialization variables.
TryGet(out def a) && TryGet(out def b)
a = 1; // Error
b = 1; // Error
For what purpose you need this strange declarations in language implementation, standard out keyword is only needed for work with external changes. 2 and 3 cases declaration in out parameter, changes mutable role of a variable, this breakes language contracts for variable, hard to implement, switch to strange non-functional style of development and introduces rarely specific use of these keywords. I think this feature is unnecessary, you must think of your style of development and skip out keyword, it is for compatability with old mutable style of use, it is not needed to extend it and introduce new contracts.
Better not to use references to external parameters, but return all values in result of function.
Because all other .NET API written in C#/VB uses the pattern of Try functions which return bool and have out parameter.
Nemerle don't needed more constructs and contracts in code to work with these api functions and this mutable style. I think new keywords and logic only to prevent some errors in mutable code using old api is not correct, language have it's base syntax and keywords, new keywords for specific situation is overdesign, these situation is not common and not needed to be included in base syntax
Why not ? It is similar to C# 6 out var feature.
I don't think this is usable and similarity for questionable features in other languages is not the target
It is not a similarity , it is more ease of interoperability with other CLR languages.
It is syntactic sugar for imperative C# for it's mutable things, we can interoperate with it without this syntactic sugar in Nemerle
Ok, if it is possible to do it using macro and put it in Nemerle.Imperative it will be good enough as well.