Re: let (x,y) = ...

2015-11-24 Thread visitor via Digitalmars-d-announce
On Tuesday, 24 November 2015 at 05:45:55 UTC, thedeemon wrote: Well, I believe it's a matter of taste. By allowing different number of elements there you allow more errors to sink in without gaining anything at all. You lose the choice between strict and loose operators, erase the difference. I

Re: let (x,y) = ...

2015-11-23 Thread thedeemon via Digitalmars-d-announce
On Monday, 23 November 2015 at 22:32:57 UTC, visitor wrote: On Monday, 23 November 2015 at 20:10:49 UTC, visitor wrote: Andrea Fontana(s allows let (hello, world) = ["hi", "there", "!"]; of course in your version let (hello, world)[] = ["hi", "there", "!"] works but for consistency with range

Re: let (x,y) = ...

2015-11-23 Thread visitor via Digitalmars-d-announce
On Monday, 23 November 2015 at 20:10:49 UTC, visitor wrote: Andrea Fontana(s allows let (hello, world) = ["hi", "there", "!"]; of course in your version let (hello, world)[] = ["hi", "there", "!"] works but for consistency with range, i think Fontana's note is relevant

Re: let (x,y) = ...

2015-11-23 Thread visitor via Digitalmars-d-announce
On Monday, 23 November 2015 at 18:38:45 UTC, thedeemon wrote: let (hello, world)[] = arr; i think what Andrea Fontana is talking is the other way around your solution allows let (hello, world)[] = ["hi"]; Andrea Fontana(s allows let (hello, world) = ["hi", "there", "!"];

Re: let (x,y) = ...

2015-11-23 Thread thedeemon via Digitalmars-d-announce
On Monday, 23 November 2015 at 16:58:43 UTC, Andrea Fontana wrote: Nice. Why first enforce is "==" rather than ">=" ? This prevents something like: auto arr = ["hello", "world", "!"]; let (hello, world) = arr; The very first post of this thread should have answered this. Two options are availa

Re: let (x,y) = ...

2015-11-23 Thread visitor via Digitalmars-d-announce
On Monday, 23 November 2015 at 16:58:43 UTC, Andrea Fontana wrote: Nice. Why first enforce is "==" rather than ">=" ? This prevents something like: auto arr = ["hello", "world", "!"]; string hello; string world; let (hello, world) = arr; note that this is thedeemon's work ! (sorry couldn't r

Re: let (x,y) = ...

2015-11-23 Thread Andrea Fontana via Digitalmars-d-announce
On Monday, 23 November 2015 at 11:12:33 UTC, visitor wrote: this work fine with your unittest : auto let(Ts...)(ref Ts vars) { struct Let { void opAssign( Tuple!Ts xs ) { foreach(i, t; Ts) vars[i] = xs[i]; } static if (sameTypes!Ts) {

Re: let (x,y) = ...

2015-11-23 Thread visitor via Digitalmars-d-announce
On Monday, 23 November 2015 at 14:54:15 UTC, thedeemon wrote: Yep, this way it works too, by capturing input vars in a closure. So the main difference is that your variant allocates GC memory while original variant does not allocate anything in the heap (only on stack). Thanks for clarifying

Re: let (x,y) = ...

2015-11-23 Thread thedeemon via Digitalmars-d-announce
On Monday, 23 November 2015 at 11:12:33 UTC, visitor wrote: My original solution remembers in the constructor addresses of variables to fill, then does the filling in opAssign operator, so I needed a way to store the references and used pointers for that. yes, but you are using ref : "auto l

Re: let (x,y) = ...

2015-11-23 Thread visitor via Digitalmars-d-announce
On Monday, 23 November 2015 at 10:28:53 UTC, thedeemon wrote: On Sunday, 22 November 2015 at 18:47:34 UTC, visitor wrote: What is the reason for using pointers (alias pointerOf(T) = T* etc...) it works without ! what am i missing ? What and how exactly works without? My original solution rem

Re: let (x,y) = ...

2015-11-23 Thread thedeemon via Digitalmars-d-announce
On Sunday, 22 November 2015 at 18:47:34 UTC, visitor wrote: What is the reason for using pointers (alias pointerOf(T) = T* etc...) it works without ! what am i missing ? What and how exactly works without? My original solution remembers in the constructor addresses of variables to fill, the

Re: let (x,y) = ...

2015-11-23 Thread karabuta via Digitalmars-d-announce
On Friday, 20 February 2015 at 09:12:26 UTC, Jacob Carlborg wrote: On 2015-02-19 05:38, thedeemon wrote: Creating tuples and returning them from functions is trivial in D: auto getTuple() { return tuple("Bob", 42); } but using them afterwards can be confusing and error prone auto t = getTupl

Re: let (x,y) = ...

2015-11-22 Thread visitor via Digitalmars-d-announce
hello, Learning here, hope i don"t excavate unnecessarily an old post What is the reason for using pointers (alias pointerOf(T) = T* etc...) it works without ! what am i missing ? Thanks

Re: let (x,y) = ...

2015-02-24 Thread Leandro Lucarella via Digitalmars-d-announce
Nick Treleaven, el 19 de February a las 17:25 me escribiste: > On 19/02/2015 17:00, Nick Treleaven wrote: > >>>Alternatively std.typetuple.TypeTuple can be used instead of let > >> > >>not for ranges and arrays though > > > >Yes, but `tuple` overloads could be added for those. > > Or not - the len

Re: let (x,y) = ...

2015-02-20 Thread via Digitalmars-d-announce
On Friday, 20 February 2015 at 09:12:26 UTC, Jacob Carlborg wrote: On 2015-02-19 05:38, thedeemon wrote: Creating tuples and returning them from functions is trivial in D: auto getTuple() { return tuple("Bob", 42); } but using them afterwards can be confusing and error prone auto t = getTupl

Re: let (x,y) = ...

2015-02-20 Thread Jacob Carlborg via Digitalmars-d-announce
On 2015-02-19 05:38, thedeemon wrote: Creating tuples and returning them from functions is trivial in D: auto getTuple() { return tuple("Bob", 42); } but using them afterwards can be confusing and error prone auto t = getTuple(); writeln("name is ", t[0], " age is ", t[1]); I really missed th

Re: let (x,y) = ...

2015-02-19 Thread Nick Treleaven via Digitalmars-d-announce
On 19/02/2015 17:00, Nick Treleaven wrote: Alternatively std.typetuple.TypeTuple can be used instead of let not for ranges and arrays though Yes, but `tuple` overloads could be added for those. Or not - the length isn't known at compile-time. Tuple already supports construction from a sta

Re: let (x,y) = ...

2015-02-19 Thread Nick Treleaven via Digitalmars-d-announce
On 19/02/2015 14:59, John Colvin wrote: On Thursday, 19 February 2015 at 13:52:29 UTC, Nick Treleaven wrote: On 19/02/2015 04:38, thedeemon wrote: int x, y, z, age; string name; let (name, age) = getTuple(); // tuple let (x,y,z) = argv[1..4].map!(to!int); // lazy range let (x,y,z) =

Re: let (x,y) = ...

2015-02-19 Thread Rory McGuire via Digitalmars-d-announce
"let" reads better either way I think. "let this and that equal this other thing". On Thu, Feb 19, 2015 at 2:00 PM, bearophile via Digitalmars-d-announce < digitalmars-d-announce@puremagic.com> wrote: > Kagamin: > > Doesn't "let" normally declare a new variable? >> > > You are right, yours is a

Re: let (x,y) = ...

2015-02-19 Thread John Colvin via Digitalmars-d-announce
On Thursday, 19 February 2015 at 13:52:29 UTC, Nick Treleaven wrote: On 19/02/2015 04:38, thedeemon wrote: int x, y, z, age; string name; let (name, age) = getTuple(); // tuple let (x,y,z) = argv[1..4].map!(to!int); // lazy range let (x,y,z) = [1,2,3]; // array Some

Re: let (x,y) = ...

2015-02-19 Thread Nick Treleaven via Digitalmars-d-announce
On 19/02/2015 04:38, thedeemon wrote: int x, y, z, age; string name; let (name, age) = getTuple(); // tuple let (x,y,z) = argv[1..4].map!(to!int); // lazy range let (x,y,z) = [1,2,3]; // array SomeStruct s; let (s.a, s.b) = tuple(3, "piggies"); Alternatively std.ty

Re: let (x,y) = ...

2015-02-19 Thread bearophile via Digitalmars-d-announce
Kagamin: Or even more obvious (VBA,TSQL): set (x,y,z) = [1,2,3]; I prefer to use "set" as in Python, to define sets: s = set([1, 2, 3]) 2 in s True Bye, bearophile

Re: let (x,y) = ...

2015-02-19 Thread Martin Nowak via Digitalmars-d-announce
On 02/19/2015 11:04 AM, thedeemon wrote: SML, OCaml, Haskell, F#, ATS, Rust, Swift and others have it as "let" keyword, so personally I'd prefer continuing that tradition. It's semantically different though because it doesn't declare the variables.

Re: let (x,y) = ...

2015-02-19 Thread Martin Nowak via Digitalmars-d-announce
On 02/19/2015 12:59 PM, bearophile wrote: It's also a great way to show what's missing in D syntax. True that.

Re: let (x,y) = ...

2015-02-19 Thread Kagamin via Digitalmars-d-announce
Or even more obvious (VBA,TSQL): set (x,y,z) = [1,2,3];

Re: let (x,y) = ...

2015-02-19 Thread bearophile via Digitalmars-d-announce
Kagamin: Doesn't "let" normally declare a new variable? You are right, yours is a valid point... So "tie" could be a better name after all. Bye, bearophile

Re: let (x,y) = ...

2015-02-19 Thread Kagamin via Digitalmars-d-announce
On Thursday, 19 February 2015 at 10:52:40 UTC, Kagamin wrote: On Thursday, 19 February 2015 at 09:50:25 UTC, bearophile wrote: I prefer "let", it's much more traditional and descriptive. C++ standard library is often a bad example to follow... Doesn't "let" normally declare a new variable? h

Re: let (x,y) = ...

2015-02-19 Thread bearophile via Digitalmars-d-announce
Mengu: that's a great example to show d's strength. thank you. It's also a great way to show what's missing in D syntax. Bye, bearophile

Re: let (x,y) = ...

2015-02-19 Thread Mengu via Digitalmars-d-announce
On Thursday, 19 February 2015 at 04:38:32 UTC, thedeemon wrote: Creating tuples and returning them from functions is trivial in D: auto getTuple() { return tuple("Bob", 42); } but using them afterwards can be confusing and error prone auto t = getTuple(); writeln("name is ", t[0], " age is ",

Re: let (x,y) = ...

2015-02-19 Thread Kagamin via Digitalmars-d-announce
On Thursday, 19 February 2015 at 09:50:25 UTC, bearophile wrote: I prefer "let", it's much more traditional and descriptive. C++ standard library is often a bad example to follow... Doesn't "let" normally declare a new variable?

Re: let (x,y) = ...

2015-02-19 Thread thedeemon via Digitalmars-d-announce
On Thursday, 19 February 2015 at 09:46:13 UTC, Ola Fosheim Grøstad wrote: On Thursday, 19 February 2015 at 04:38:32 UTC, thedeemon wrote: let (name, age) = getTuple(); Maybe change the name to tie: http://www.cplusplus.com/reference/tuple/tie/ ? SML, OCaml, Haskell, F#, ATS, Rust, Swift and

Re: let (x,y) = ...

2015-02-19 Thread thedeemon via Digitalmars-d-announce
On Thursday, 19 February 2015 at 09:31:59 UTC, ponce wrote: That's pretty neat! May I turn this code into a d-idioms? Name and link will be kept of course. Sure, if you wish. There was just one person using this thing until today, so I dunno whether it deserves to be in that list.

Re: let (x,y) = ...

2015-02-19 Thread bearophile via Digitalmars-d-announce
Ola Fosheim Grøstad: Maybe change the name to tie: http://www.cplusplus.com/reference/tuple/tie/ ? I prefer "let", it's much more traditional and descriptive. C++ standard library is often a bad example to follow... Bye, bearophile

Re: let (x,y) = ...

2015-02-19 Thread via Digitalmars-d-announce
On Thursday, 19 February 2015 at 04:38:32 UTC, thedeemon wrote: let (name, age) = getTuple(); Maybe change the name to tie: http://www.cplusplus.com/reference/tuple/tie/ ?

Re: let (x,y) = ...

2015-02-19 Thread ponce via Digitalmars-d-announce
On Thursday, 19 February 2015 at 04:38:32 UTC, thedeemon wrote: Creating tuples and returning them from functions is trivial in D: auto getTuple() { return tuple("Bob", 42); } but using them afterwards can be confusing and error prone auto t = getTuple(); writeln("name is ", t[0], " age is ",