Re: [OT] Converting booleans to numbers

2017-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/21/17 3:24 PM, Timon Gehr wrote: This is a good alternative, maybe arrange it like this: dfs(a + 1, b); dfs(a, b + 1); dfs(a - 1, b); dfs(a, b - 1); Yes, better! Just need to make sure no code is duplicated. (For example, there could be more work to do in each loop iteration, and then

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Timon Gehr via Digitalmars-d-learn
On 21.09.2017 17:53, Steven Schveighoffer wrote: On 9/21/17 11:48 AM, Steven Schveighoffer wrote: On 9/21/17 11:06 AM, Timon Gehr wrote:     foreach(i; 0 .. 4){     dfs(a + (i==0) - (i==1),     b + (i==2) - (i==3));     } So am I, but I wasn't commenting on

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Mark via Digitalmars-d-learn
On Wednesday, 20 September 2017 at 19:25:58 UTC, Timon Gehr wrote: Actually, it is useful enough to have a Wikipedia page: https://en.wikipedia.org/wiki/Iverson_bracket Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { if (a<0 ||

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/21/17 11:48 AM, Steven Schveighoffer wrote: On 9/21/17 11:06 AM, Timon Gehr wrote:     foreach(i; 0 .. 4){     dfs(a + (i==0) - (i==1),     b + (i==2) - (i==3));     } So am I, but I wasn't commenting on trade-offs, only the view that there are no good

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/21/17 11:06 AM, Timon Gehr wrote: foreach(i; 0 .. 4){ dfs(a + (i==0) - (i==1), b + (i==2) - (i==3)); } ... So am I, but I wasn't commenting on trade-offs, only the view that there are no good uses. This seems way easier for me to grok, and

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Timon Gehr via Digitalmars-d-learn
On 20.09.2017 23:13, nkm1 wrote: Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) {     void dfs(int a, int b) { Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { if (a<0 || a >= data.length) return;

Re: [OT] Converting booleans to numbers

2017-09-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, September 20, 2017 21:13:58 nkm1 via Digitalmars-d-learn wrote: > OTOH, booleans being numbers is a source of some bugs (just like > other cases of weak typing). Not a ton of bugs, but the utility > of implicit conversion to numbers is so unnoticeable that I'm > sure it's just not

Re: [OT] Converting booleans to numbers

2017-09-20 Thread nkm1 via Digitalmars-d-learn
On Wednesday, 20 September 2017 at 19:25:58 UTC, Timon Gehr wrote: Actually, it is useful enough to have a Wikipedia page: https://en.wikipedia.org/wiki/Iverson_bracket Mmmm... "The notation was originally introduced by Kenneth E. Iverson in his programming language APL". APL... yeah :)

Re: [OT] Converting booleans to numbers

2017-09-20 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 20 September 2017 at 19:25:58 UTC, Timon Gehr wrote: On 19.09.2017 23:17, nkm1 wrote: ... OTOH, booleans converting to numbers is a very questionable feature. > I certainly have never seen any good use for it. ... Actually, it is useful enough to have a Wikipedia page:

[OT] Converting booleans to numbers

2017-09-20 Thread Timon Gehr via Digitalmars-d-learn
On 19.09.2017 23:17, nkm1 wrote: ... OTOH, booleans converting to numbers is a very questionable feature. > I certainly have never seen any good use for it. ... Actually, it is useful enough to have a Wikipedia page: https://en.wikipedia.org/wiki/Iverson_bracket Example of a good use: void