Re: Dual conditions in D and Python

2015-05-23 Thread Andrei Alexandrescu via Digitalmars-d-learn
On 5/21/15 2:35 PM, Ali Çehreli wrote: On 05/21/2015 12:44 PM, Meta wrote: All we need is user-defined opIs and then we're really cooking with gas. if (5 is between(4, 6)) { //... } We're almost there. :) bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max) { return (what = min)

Re: Dual conditions in D and Python

2015-05-23 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2015-05-23 at 10:17 -0700, Andrei Alexandrescu via Digitalmars-d-learn wrote: […] if (ordered(4, 5, 6)) { ... } if (strictlyOrdered(4, 5, 6)) { ... } So the latter means the integers have to lashed as well as ordered? ; -) -- Russel.

Re: Dual conditions in D and Python

2015-05-23 Thread weaselcat via Digitalmars-d-learn
On Saturday, 23 May 2015 at 17:17:17 UTC, Andrei Alexandrescu wrote: On 5/21/15 2:35 PM, Ali Çehreli wrote: On 05/21/2015 12:44 PM, Meta wrote: All we need is user-defined opIs and then we're really cooking with gas. if (5 is between(4, 6)) { //... } We're almost there. :) bool

Re: Dual conditions in D and Python

2015-05-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, May 21, 2015 16:57:14 Dennis Ritchie via Digitalmars-d-learn wrote: Hi, In Python I can write this: if (4 = 5 = 6): print (OK) - http://rextester.com/NNAM70713 In D, I can only write this: import std.stdio; void main() { if (4 = 5 5 = 6)

Re: Dual conditions in D and Python

2015-05-21 Thread Manfred Nowak via Digitalmars-d-learn
Dennis Ritchie wrote: if (4 = 5 = 6): print (OK) - I would rather write: if( isSorted![4,5,6]) -manfred

Re: Dual conditions in D and Python

2015-05-21 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 21 May 2015 at 18:26:28 UTC, Dennis Ritchie wrote: elif instead of else if: http://rextester.com/WOSH30608 The parallel exchange values: http://rextester.com/TPUD51604 wow!

Re: Dual conditions in D and Python

2015-05-21 Thread John Colvin via Digitalmars-d-learn
On Thursday, 21 May 2015 at 18:26:28 UTC, Dennis Ritchie wrote: On Thursday, 21 May 2015 at 17:43:25 UTC, Jonathan M Davis wrote: No C-based language allows what python does, and based on operators work in C-based languages, what python is doing simply doesn't fit or make sense. What happens

Re: Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 21 May 2015 at 17:43:25 UTC, Jonathan M Davis wrote: No C-based language allows what python does, and based on operators work in C-based languages, what python is doing simply doesn't fit or make sense. What happens in C/C++/D/Java/C#/etc. land is that 4 = 5 results in a bool, at

Re: Dual conditions in D and Python

2015-05-21 Thread Ali Çehreli via Digitalmars-d-learn
On 05/21/2015 12:44 PM, Meta wrote: All we need is user-defined opIs and then we're really cooking with gas. if (5 is between(4, 6)) { //... } We're almost there. :) bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max) { return (what = min) (what = max); } void main() { if

Re: Dual conditions in D and Python

2015-05-21 Thread weaselcat via Digitalmars-d-learn
On Thursday, 21 May 2015 at 23:14:47 UTC, Dennis Ritchie wrote: On Thursday, 21 May 2015 at 21:35:22 UTC, Ali Çehreli wrote: We're almost there. :) bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max) { return (what = min) (what = max); } void main() { if (5.is_between(4, 6)) {

Re: Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 21 May 2015 at 21:35:22 UTC, Ali Çehreli wrote: We're almost there. :) bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max) { return (what = min) (what = max); } void main() { if (5.is_between(4, 6)) { // ... } } Ali A condition is that if, for example,

Re: Dual conditions in D and Python

2015-05-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/21/15 12:57 PM, Dennis Ritchie wrote: Hi, In Python I can write this: if (4 = 5 = 6): print (OK) - http://rextester.com/NNAM70713 In D, I can only write this: import std.stdio; void main() { if (4 = 5 5 = 6) puts(OK); } - http://rextester.com/FICP83173 I

Re: Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
Something I sometimes do for strictly personal projects: import std.typecons : ω = tuple; import std.typetuple : Ω = TypeTuple; void main() { auto a = 1, b = 2; Ω!(a, b) = ω(b, a); assert(a==2 b==1); } On Thursday, 21 May 2015 at 19:05:16 UTC, Steven Schveighoffer wrote: On

Re: Dual conditions in D and Python

2015-05-21 Thread Meta via Digitalmars-d-learn
On Thursday, 21 May 2015 at 19:05:16 UTC, Steven Schveighoffer wrote: On 5/21/15 12:57 PM, Dennis Ritchie wrote: Hi, In Python I can write this: if (4 = 5 = 6): print (OK) - http://rextester.com/NNAM70713 In D, I can only write this: import std.stdio; void main() { if (4 = 5 5

Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, In Python I can write this: if (4 = 5 = 6): print (OK) - http://rextester.com/NNAM70713 In D, I can only write this: import std.stdio; void main() { if (4 = 5 5 = 6) puts(OK); } - http://rextester.com/FICP83173 I wanted to ask what is the reason? Maybe the

Re: Dual conditions in D and Python

2015-05-21 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 21 May 2015 at 16:57:16 UTC, Dennis Ritchie wrote: Hi, In Python I can write this: if (4 = 5 = 6): print (OK) - http://rextester.com/NNAM70713 In D, I can only write this: import std.stdio; void main() { if (4 = 5 5 = 6) puts(OK); } -

Re: Dual conditions in D and Python

2015-05-21 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 21 May 2015 at 17:17:29 UTC, Alex Parrill wrote: http://wiki.dlang.org/Language_Designs_Explained#Why_does_D_not_support_chaining_comparison_operators.3F Backward compatibility with C is nice but on the other hand it is a road to nowhere! Because of this compatibility, I'm