nemerle icon indicating copy to clipboard operation
nemerle copied to clipboard

Support 'out def' and 'out mutable' for out parameters.

Open NN--- opened this issue 9 years ago • 9 comments

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

NN--- avatar Nov 20 '14 09:11 NN---

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.

ghost avatar Nov 20 '14 09:11 ghost

Better not to use references to external parameters, but return all values in result of function.

ghost avatar Nov 20 '14 09:11 ghost

Because all other .NET API written in C#/VB uses the pattern of Try functions which return bool and have out parameter.

NN--- avatar Nov 20 '14 09:11 NN---

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

ghost avatar Nov 20 '14 10:11 ghost

Why not ? It is similar to C# 6 out var feature.

NN--- avatar Nov 20 '14 10:11 NN---

I don't think this is usable and similarity for questionable features in other languages is not the target

ghost avatar Nov 20 '14 10:11 ghost

It is not a similarity , it is more ease of interoperability with other CLR languages.

NN--- avatar Nov 20 '14 12:11 NN---

It is syntactic sugar for imperative C# for it's mutable things, we can interoperate with it without this syntactic sugar in Nemerle

ghost avatar Nov 20 '14 13:11 ghost

Ok, if it is possible to do it using macro and put it in Nemerle.Imperative it will be good enough as well.

NN--- avatar Nov 21 '14 14:11 NN---