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.
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
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
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", "!"];
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
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,
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 =
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
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
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
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) {
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
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 length isn't known
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 =
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 the ML
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);
If a range or array doesn't have enough elements, this thing
will throw, and if it's
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
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
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?
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
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/
?
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?
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);
If a range or array doesn't have enough elements, this thing
will throw, and if it's
Or even more obvious (VBA,TSQL):
set (x,y,z) = [1,2,3];
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
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.
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.
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.
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
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
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 valid
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
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
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
) = getTuple();
Turns out this is ridiculously easy to implement in D, so here's
my very tiny module for this:
https://bitbucket.org/infognition/dstuff/src (scroll down to
letassign.d)
It allows you to write:
int x, y, z, age;
string name;
let (name, age) = getTuple(); // tuple
let (x,y,z
35 matches
Mail list logo