On Monday, 24 July 2017 at 13:12:17 UTC, Nick Treleaven wrote:
static if (is(E == enum; alias V)) { // this inserts "V"
V v;
}
The test comes first as it logically should, as the alias is
not being used until the following statement.
Hmm, it can be used in the test:
is(Abc U : U*)
is(AA
On Monday, 24 July 2017 at 13:12:17 UTC, Nick Treleaven wrote:
On Friday, 21 July 2017 at 21:50:02 UTC, Johan Engelen wrote:
static if (is(E V == enum)) { // this inserts "V"
V v;
}
```
Yes, but this is a bit different as the goal is to avoid
repeating V
Sigh. Repeating E.
On Friday, 21 July 2017 at 21:50:02 UTC, Johan Engelen wrote:
We do have a construct like that already:
```
static if (is(E V == enum)) { // this inserts "V"
V v;
}
```
Yes, but this is a bit different as the goal is to avoid
repeating V (as it may be complex). Repeating a local variable
On Friday, 21 July 2017 at 21:32:48 UTC, Andrei Alexandrescu
wrote:
with (auto r = makeMeARange)
if (!r.empty)
with (auto x = r.front)
{
...
}
Andrei
I'm being real nitpicky, but this in particular just seems like a
slightly worse way to write
with (auto r = makeMeARange)
if
On Friday, July 21, 2017 17:32:48 Andrei Alexandrescu via Digitalmars-d
wrote:
> On 07/19/2017 09:30 AM, sontung wrote:
> [snip]
>
> This post:
> http://forum.dlang.org/post/vfjlpvpwuyfqoljvp...@forum.dlang.org seems
> to be identical to one on November 3, 2016:
>
On Friday, 21 July 2017 at 21:32:48 UTC, Andrei Alexandrescu
wrote:
It's bizarre even lexically: "If the following ... oh wait let
me insert some stuff ... as I was saying, if the following
condition happens..."
(excuse me for muddying the waters)
We do have a construct like that already:
On 07/19/2017 09:30 AM, sontung wrote:
[snip]
This post:
http://forum.dlang.org/post/vfjlpvpwuyfqoljvp...@forum.dlang.org seems
to be identical to one on November 3, 2016:
http://forum.dlang.org/post/dejodpslmjdovstdi...@forum.dlang.org.
Hat tip for persistence!
Regarding the feature
On Thursday, 20 July 2017 at 14:18:48 UTC, Jack Stouffer wrote:
On Thursday, 20 July 2017 at 14:05:36 UTC, Iakh wrote:
It is not about reduce number of lines. It is about binding
related things in one statement.
Even so, it's already been shown in this thread that the same
effect can be
On Thursday, 20 July 2017 at 14:05:36 UTC, Iakh wrote:
It is not about reduce number of lines. It is about binding
related things in one statement.
Even so, it's already been shown in this thread that the same
effect can be achieved via a block statement (doing exactly what
it was designed
On Wednesday, 19 July 2017 at 15:41:18 UTC, Jack Stouffer wrote:
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
Thoughts on this sort of feature?
To be frank, I don't think that helping the programmer reduce
the line count in their program by one line is worth further
On Wednesday, 19 July 2017 at 15:31:08 UTC, ag0aep6g wrote:
On 07/19/2017 03:30 PM, sontung wrote:
So I was thinking of some sort of syntax like this:
if(int i = someFunc(); i >= 0)
{
// use i
}
Thoughts on this sort of feature?
I'd prefer a new variant of `with`:
On Wednesday, 19 July 2017 at 15:31:08 UTC, ag0aep6g wrote:
On 07/19/2017 03:30 PM, sontung wrote:
So I was thinking of some sort of syntax like this:
if(int i = someFunc(); i >= 0)
{
// use i
}
Thoughts on this sort of feature?
I'd prefer a new variant of `with`:
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
Thoughts on this sort of feature?
This doesn't enable anything new, and breaks readability
conventions.
On Wednesday, 19 July 2017 at 20:42:33 UTC, Steven Schveighoffer
wrote:
I remember reading a discussion about using with statements to
do this earlier as well, but I can't find it.
-Steve
I don't think this is the discussion you're talking about, but
this does bring DIP 1005 to mind:
I thought I remembered reading about this. But apparently, it was
*exactly* this.
https://forum.dlang.org/post/dejodpslmjdovstdi...@forum.dlang.org
And this is, ... well I guess I continue to have the same ideas :)
https://forum.dlang.org/post/oknvgb$2nr0$1...@digitalmars.com
On Wednesday, July 19, 2017 1:30:56 PM MDT sontung via Digitalmars-d wrote:
> So I was thinking of a way of extending if statements that have
> declarations. The following being as example of the current use
> of if statements with declarations:
>
> if(int* weDontPollute = someFunc())
>
On 7/19/17 11:47 AM, Jonathan Marler wrote:
On Wednesday, 19 July 2017 at 15:39:02 UTC, Steven Schveighoffer wrote:
On 7/19/17 9:30 AM, sontung wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use of if
On Wed, Jul 19, 2017 at 01:30:56PM +, sontung via Digitalmars-d wrote:
[...]
> if(int i = someFunc(); i >= 0)
> {
> // use i
> }
> Thoughts on this sort of feature?
I've been wanting such a feature for a long time now. Though I'd propose
a different syntax:
if
On Wednesday, 19 July 2017 at 15:31:08 UTC, ag0aep6g wrote:
I'd prefer a new variant of `with`:
Looks much cleaner to me.
On Wednesday, 19 July 2017 at 16:49:38 UTC, Jonathan Marler wrote:
This would automatically make it work with any statement:
with(auto x = 0) if(x)
{
doSomething
}
with(auto x = 0) while(x)
{
doSomething
}
Could also do multiple with statements
with(auto x = 0)
with(auto y = 0)
On Wednesday, 19 July 2017 at 16:13:28 UTC, Swoorup Joshi wrote:
On Wednesday, 19 July 2017 at 15:31:08 UTC, ag0aep6g wrote:
On 07/19/2017 03:30 PM, sontung wrote:
So I was thinking of some sort of syntax like this:
if(int i = someFunc(); i >= 0)
{
// use i
}
Thoughts
On Wednesday, 19 July 2017 at 16:13:28 UTC, Swoorup Joshi wrote:
On Wednesday, 19 July 2017 at 15:31:08 UTC, ag0aep6g wrote:
On 07/19/2017 03:30 PM, sontung wrote:
So I was thinking of some sort of syntax like this:
if(int i = someFunc(); i >= 0)
{
// use i
}
Thoughts
On Wednesday, 19 July 2017 at 15:31:08 UTC, ag0aep6g wrote:
On 07/19/2017 03:30 PM, sontung wrote:
So I was thinking of some sort of syntax like this:
if(int i = someFunc(); i >= 0)
{
// use i
}
Thoughts on this sort of feature?
I'd prefer a new variant of `with`:
On Wednesday, 19 July 2017 at 15:41:18 UTC, Jack Stouffer wrote:
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
Thoughts on this sort of feature?
To be frank, I don't think that helping the programmer reduce
the line count in their program by one line is worth further
On 7/19/17 11:41 AM, Jack Stouffer wrote:
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
Thoughts on this sort of feature?
To be frank, I don't think that helping the programmer reduce the line
count in their program by one line is worth further complicating the
language.
It's
On Wednesday, 19 July 2017 at 15:39:02 UTC, Steven Schveighoffer
wrote:
On 7/19/17 9:30 AM, sontung wrote:
[...]
I really like the idea. Only thing I don't like is the
possibility for abuse/confusion/errors:
if(int i = someFunc(); j >= 0) // typo, or weird relationship,
or just
On Wednesday, 19 July 2017 at 15:39:02 UTC, Steven Schveighoffer
wrote:
On 7/19/17 9:30 AM, sontung wrote:
So I was thinking of a way of extending if statements that
have declarations. The following being as example of the
current use of if statements with declarations:
if(int*
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
Thoughts on this sort of feature?
To be frank, I don't think that helping the programmer reduce the
line count in their program by one line is worth further
complicating the language.
On 7/19/17 9:30 AM, sontung wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use of if
statements with declarations:
if(int* weDontPollute = someFunc())
{
// use weDontPollute
}
That's
On 07/19/2017 03:30 PM, sontung wrote:
So I was thinking of some sort of syntax like this:
if(int i = someFunc(); i >= 0)
{
// use i
}
Thoughts on this sort of feature?
I'd prefer a new variant of `with`:
with (int i = someFunc()) if (i >= 0)
{
// use i
}
On Wednesday, 19 July 2017 at 14:46:31 UTC, Andrea Fontana wrote:
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
Thoughts on this sort of feature?
I think I read this topic a couple of times here, and it went
nowhere...
Andrea
Well someone must take the initiative and submit
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use
of if statements with declarations:
if(int* weDontPollute = someFunc())
{
// use
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
Thoughts on this sort of feature?
I think I read this topic a couple of times here, and it went
nowhere...
Andrea
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use
of if statements with declarations:
[...]
I like it for C++17 and I like it for D.
Atila
On Wednesday, 19 July 2017 at 14:26:52 UTC, Dukc wrote:
On Wednesday, 19 July 2017 at 13:37:50 UTC, Adam D. Ruppe wrote:
I like it.
Me too. I think this should also apply to switch and with
statements. Perhaps while statements too.
Right, C++17 has it also for a switch:
```
If
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use
of if statements with declarations:
if(int* weDontPollute = someFunc())
{
// use
On Wednesday, 19 July 2017 at 13:37:50 UTC, Adam D. Ruppe wrote:
I like it.
Me too. I think this should also apply to switch and with
statements. Perhaps while statements too.
On Wednesday, 19 July 2017 at 13:30:56 UTC, sontung wrote:
Thoughts on this sort of feature?
I like it.
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use
of if statements with declarations:
if(int* weDontPollute = someFunc())
{
// use weDontPollute
}
That's great and all, but it only works by
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use
of if statements with declarations:
if(int* weDontPollute = someFunc())
{
// use
On Sunday, 6 November 2016 at 05:07:10 UTC, Andrei Alexandrescu
wrote:
// possible future D
if ((auto variable = fun()) != 42) {
...
}
Defining a variable in an expression wouldn't be allowed
everywhere (but might be contemplated later as an possibility,
which is a nice thing about this
On Sunday, 6 November 2016 at 05:07:10 UTC, Andrei Alexandrescu
wrote:
if (auto variable = fun(); variable != 42) {
...
}
Why does the word "variable" need to appear twice? It seems
simpler to allow punctuation around existing syntax:
// possible future D
if ((auto variable = fun()) != 42)
On Sunday, 6 November 2016 at 05:07:10 UTC, Andrei Alexandrescu
wrote:
The declaration with "if" seems to be a recent fashion. I've
first seen it in Go and now C++17 took a shine to it -
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r0.html. A DIP would do good to cite that
On Sunday, 6 November 2016 at 05:07:10 UTC, Andrei Alexandrescu
wrote:
A more approachable thing to do is allow variable definitions
in switch statements:
switch (auto x = fun() { ... }
It is surprising that doesn't work, which is a good argument in
favor of the feature (removal of an undue
On 11/5/16 3:52 PM, Jonathan M Davis via Digitalmars-d wrote:
Ultimately though, the biggest hurdle is that someone needs to create a DIP
for it that strongly argues its case with real world examples of how it
would improve code (preferably with code from Phobos and code.dlang.org),
and without
On Saturday, 5 November 2016 at 19:52:05 UTC, Jonathan M Davis
wrote:
and more importantly, I don't know if Walter or Andrei would
think that it's worth it, and they're the ones who need to be
convinced.
this addition looks like needless overcomplication even for me.
and i'm usually
On Thursday, November 03, 2016 22:29:34 Jerry via Digitalmars-d wrote:
> if(int i = someFunc(); i >= 0)
> {
> // use i
> }
> Thoughts on this sort of feature?
Personally, I'd love to have it, and I think that it's been suggested before
(though I don't remember how that
On Friday, 4 November 2016 at 19:26:23 UTC, Steven Schveighoffer
wrote:
I think it makes it easier to read and it fits with how the
for-statement operates. I write code everyday that could
utilize this
if-statement syntax, so I thought I might as well bring it up.
But if
there isn't that much
On Friday, 4 November 2016 at 18:05:51 UTC, Adrian Matoga wrote:
On Friday, 4 November 2016 at 15:34:00 UTC, Jerry wrote:
On Friday, 4 November 2016 at 14:16:44 UTC, Matthias Bentrup
wrote:
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
if(int i = someFunc(); i >= 0)
{
On 04.11.2016 21:03, Andrej Mitrovic wrote:
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use of if
statements with declarations:
if(int* weDontPollute
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use
of if statements with declarations:
if(int* weDontPollute = someFunc())
{
// use
On 11/4/16 1:46 PM, Jerry wrote:
On Friday, 4 November 2016 at 16:15:21 UTC, Steven Schveighoffer wrote:
It's just a strawman type, I'm sure there's ways to handle these
things, I just didn't put a lot of effort into all the cases.
But really it's just syntax to separate the bool check from
On Friday, 4 November 2016 at 15:34:00 UTC, Jerry wrote:
On Friday, 4 November 2016 at 14:16:44 UTC, Matthias Bentrup
wrote:
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
if(int i = someFunc(); i >= 0)
{
// use i
}
Thoughts on this sort of feature?
I would
On Friday, 4 November 2016 at 16:15:21 UTC, Steven Schveighoffer
wrote:
It's just a strawman type, I'm sure there's ways to handle
these things, I just didn't put a lot of effort into all the
cases.
But really it's just syntax to separate the bool check from the
value itself. You can get
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
Thoughts on this sort of feature?
Love your name, Jerry ;)
Maybe something like this psuedo code:
struct Condition(T) {
Condition(T val, bool cond) { m_val = val; m_cond = cond; }
bool opCast(T)() if(is(T == bool)) {
On Friday, 4 November 2016 at 13:56:57 UTC, Andrea Fontana wrote:
If you don't like indentation you can simply ignore it or you
can use old goto :)
{
int i = someFunc();
if (i < 0) goto outer;
// your code here
}
outer:
BTW there is a trick to avoid goto+label:
switch (true) {
On 11/4/16 11:27 AM, Jerry wrote:
On Friday, 4 November 2016 at 14:10:51 UTC, Steven Schveighoffer wrote:
Hm... what about something like:
struct BoolCond(T, string cond)
{
T val;
bool opCast(B)() if(is(B == bool))
{
return mixin("val " ~ cond);
}
}
auto boolcond(string cond,
On Friday, 4 November 2016 at 14:10:51 UTC, Steven Schveighoffer
wrote:
On 11/3/16 6:29 PM, Jerry wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current
use of if
statements with declarations:
if(int*
On Friday, 4 November 2016 at 14:16:44 UTC, Matthias Bentrup
wrote:
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
if(int i = someFunc(); i >= 0)
{
// use i
}
Thoughts on this sort of feature?
I would prefer the syntax
if( (int i = someFunc()) >= 0 )
{
On 11/4/16 10:10 AM, Steven Schveighoffer wrote:
On 11/3/16 6:29 PM, Jerry wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use of if
statements with declarations:
if(int* weDontPollute = someFunc())
{
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
if(int i = someFunc(); i >= 0)
{
// use i
}
Thoughts on this sort of feature?
I would prefer the syntax
if( (int i = someFunc()) >= 0 )
{
// use i
}
as this matches the already existing assignment
On 11/3/16 6:29 PM, Jerry wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use of if
statements with declarations:
if(int* weDontPollute = someFunc())
{
// use weDontPollute
}
That's great
On Friday, 4 November 2016 at 13:38:30 UTC, Superstar64 wrote:
On Thursday, 3 November 2016 at 22:32:17 UTC, Stefan Koch wrote:
Just Introduce another block
{
int i = someFunc();
if (i >= 0) { ... }
}
// i is not visible here
That adds 2 indention levels after formatting.
Unfortunately
On Thursday, 3 November 2016 at 22:32:17 UTC, Stefan Koch wrote:
Just Introduce another block
{
int i = someFunc();
if (i >= 0) { ... }
}
// i is not visible here
That adds 2 indention levels after formatting.
Unfortunately this doesn't work:
---
{
int i = someFunc();
if (i >= 0):
On Friday, 4 November 2016 at 00:04:28 UTC, mogu wrote:
Introducing a block is not intuitive and cause an identation.
How is using a block to produce a sub-scope not intuitive? That's
using a standard feature to do exactly what it is supposed to do.
On Thursday, 3 November 2016 at 22:32:17 UTC, Stefan Koch wrote:
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
So I was thinking of a way of extending if statements that
have declarations. The following being as example of the
current use of if statements with declarations:
On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use
of if statements with declarations:
[...]
Just Introduce another block
{
int i = someFunc();
if (i
So I was thinking of a way of extending if statements that have
declarations. The following being as example of the current use
of if statements with declarations:
if(int* weDontPollute = someFunc())
{
// use weDontPollute
}
That's great and all, but it only works by
68 matches
Mail list logo