February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | 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
|
February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | Or even more obvious (VBA,TSQL): set (x,y,z) = [1,2,3]; |
February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to thedeemon | 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.
|
February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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.
|
February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | 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 |
February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to thedeemon | 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.typetuple.TypeTuple can be used instead of let: http://forum.dlang.org/post/op.wa4vn6lgsqugbd@localhost > If a range or array doesn't have enough elements, this thing will throw, > and if it's not desired there's > let (x,y,z)[] = ... > variant that uses just the available data and keeps the rest variables > unchanged. With these functions you can skip certain elements: http://forum.dlang.org/post/jjnmh2$27o5$1@digitalmars.com |
February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | 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
>>
>> SomeStruct s;
>> let (s.a, s.b) = tuple(3, "piggies");
>
> Alternatively std.typetuple.TypeTuple can be used instead of let
not for ranges and arrays though
|
February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile Attachments:
| "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 point... So "tie" could be a better name after all. > > Bye, > bearophile > |
February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | 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) = [1,2,3]; // array
>>>
>>> SomeStruct s;
>>> let (s.a, s.b) = tuple(3, "piggies");
>>
>> 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. Tuple already supports construction from a static array:
int a, b;
TypeTuple!(a, b) = Tuple!(int, int)([3, 4]);
|
February 19, 2015 Re: let (x,y) = ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | 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 static array: > > int a, b; > TypeTuple!(a, b) = Tuple!(int, int)([3, 4]); I'm hacking std.typecons so this does work: TypeTuple!(a, b) = [4, 5].tuple; |
Copyright © 1999-2021 by the D Language Foundation