Dropping one extra =
from declarations to make them less divergent from Cpp1 syntax
#742
Replies: 6 comments 9 replies
-
More explanations
I have to explain that in this example, the default return type with Additional considerationsYou could ignore this part.Considering
|
Beta Was this translation helpful? Give feedback.
-
That's a Lines 8140 to 8143 in 3512ecd |
Beta Was this translation helpful? Give feedback.
-
Concept declaration syntax in Cpp2 from this file is already like this: arithmetic: <T> concept = std::integral<T> || std::floating_point<T>; But it looks different from declaraing type and namespace aliases because of v: <T> type == std::vector<T>; |
Beta Was this translation helpful? Give feedback.
-
By dropping the extra // {...} is a block statement.
fnc1: () {...}
// {...} is an initializer list.
fnc2: () -> ret = {...}; Also all control structures can be directly used inside an expression with // It's similar to Rust.
// {...} is a block expression, because `if` is placed on the right side of `=` inside an expression.
var1: = 2 + if x < 10 { x } else { x - 10 };
// {...} is a block statement, because `if` is placed stand-alone outside an expression.
var2: = 2;
if x < 10 {
var2 += x;
}
else {
var2 += x - 10;
} And it's consistent with var3: = inspect x < 10 -> bool { is true = x; is _ = x - 10; }; And lambda syntax would be consistent with new terser syntax (as discussed in #793): var4: = call(: (x) x + 1);
var5: = call(: (x) { print(x); });
var6: = call(: (x) -> i32 { return x + 1; }); But it's a breaking change, considering Cpp2 is in development, and it's not finalized yet. |
Beta Was this translation helpful? Give feedback.
-
It also simplifies the meaning of '=' I suppose, to only mean variable assignment/construction, because assigning a function to a name isn't really the same thing unless you're making a function pointer, but then you're actually assigning something so I suppose it makes function pointer assignment slightly harder to mix up with a function with a single statement?
Fptr: (x: int, y:int) -> bool = foo&;
I forget the reasons for adding the = to function declaration, and I don't dislike it, but if there are good reasons (beyond it saves a character here and there) to remove it then I won't particularly miss it either.
On 11 November 2023 07:20:28 Sadeq ***@***.***> wrote:
By dropping the extra = from declarations, it's possible to make {...} to be visually separated as either block statement or list of items. Therefore as discussion in #637<#637>, {...} may mean list initialization in addition to block statement:
// {...} is a block statement.
fnc1: () {...}
// {...} is an initializer list.
fnc1: () = {...};
Also all control structures can be directly used inside an expression with {...}:
// It's similar to Rust.
// {...} is a block expression, because `if` is placed on the right side of `=` inside an expression.
var1: = 2 + if x < 10 { x } else { x - 10 };
// {...} is a block statement, because `if` is placed stand-alone outside an expression.
var2: = 2;
if x < 10 {
var2 += x;
}
else {
var2 += x - 10;
}
And it's consistent with inspect too:
var3: = inspect x < 10 -> bool { is true = x; is _ = x - 10; };
And lambda syntax would be consistent with new terser syntax (as discussed in #793<#793>):
var4: = call(: (x) x + 1);
var5: = call(: (x) { print(x); });
var6: = call(: (x) -> i32 { return x + 1; });
But it's a breaking change, considering Cpp2 is in development, and it's not finalized yet.
—
Reply to this email directly, view it on GitHub<#742 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALUZQJICZGGEX4WLLCLCQTYD4RLTAVCNFSM6AAAAAA5Z2JK2CVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TKMZZGIZDA>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I've created issue #824 from our discussion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
After introducing the new terser syntax for lambdas, I think sooner or later, this topic will be discussed by someone else (maybe by the author of Cpp2 @hsutter himself). BTW sooner is better than later. So let's discuss it please.
Currently, we use
=
to declare stuff (types, namespaces, functions and variables), and we use==
to alias stuff.As you see, the
=
always followed by:
and it doesn't have a special meaning for each declaration. Also the reason of those errors is that intentionally they are not allowed yet. Would it be possible to consider dropping one extra=
from them (except for variable declarations)?As you see in this way:
=
will have the right meaning in the right place:=
won't harm readability. So it leads to less typing to write Cpp2 programs.==
which is inspired fromoperator==
already cannot be used to compare types and namespaces. So it can be the reason to don't use==
to create type and namespace aliases, while we can use=
as a good candidate for them.Thanks for your patience.
Beta Was this translation helpful? Give feedback.
All reactions