digitalmars.D - Declaring Ref Variables Inside Function Calls
- dsimcha (13/13) Mar 30 2009 At times, like when trying to write a syntactically sweet tuple unpacker...
- Denis Koroskin (8/24) Mar 30 2009 It seems loogically that "foo" should die right after doStuff returns,
- dsimcha (11/40) Mar 30 2009 Nothing wrong with auto, but you need to specify something, even if it's...
- Simen Kjaeraas (6/19) Mar 31 2009 If foo and bar die right after this line, I feel this is acceptable.
- Jarrett Billingsley (5/11) Mar 31 2009 Cute, but uh, I'd much rather see tuples just be returnable. That
- dsimcha (7/19) Mar 31 2009 Well, apparently, alias this is getting implemented soon (see Phobos cha...
- Andrei Alexandrescu (3/13) Mar 31 2009 They are.
- Jarrett Billingsley (12/26) Mar 31 2009 template Tuple(T...)
- Andrei Alexandrescu (9/36) Mar 31 2009 import std.typecons;
- Jarrett Billingsley (4/11) Mar 31 2009 Cool, but..
- Andrei Alexandrescu (3/19) Mar 31 2009 Why not not?
- grauzone (13/34) Mar 31 2009 Why not remove return values in favour of out parameters?
- Daniel Keep (4/26) Mar 31 2009 Because people keep having to invent hacks to work around the fact that
- Andrei Alexandrescu (5/30) Mar 31 2009 "It's not a hack, it's a feature."
- Daniel Keep (7/27) Mar 31 2009 Only if the language itself has lists except you can't return them from
- Sergey Gromov (7/47) Mar 31 2009 Unfair---std.typecons.Tuple is actually a struct!
- Bill Baxter (15/62) Mar 31 2009 Right. In my ideal world I could use tuples like this:
- Andrei Alexandrescu (11/75) Mar 31 2009 That sucks. Is int(int, float) a function type or a juxtaposition of two...
- Bill Baxter (5/91) Mar 31 2009 ,
- Bill Baxter (18/94) Mar 31 2009 ,
- Andrei Alexandrescu (5/98) Mar 31 2009 Yah, sorry for the dismissive comments... what I meant was that the
- Sergey Gromov (9/106) Mar 31 2009 Comma expression is not ambiguous. It's a comma expression. Renaming
- Andrei Alexandrescu (5/13) Mar 31 2009 I don't understand. So are you suggesting that the comma expression gets...
- Sergey Gromov (6/20) Mar 31 2009 Now comma expression drops all the results but the last one. You lose
- Andrei Alexandrescu (7/28) Mar 31 2009 That won't work because you'd paste C code into your D code and it'll
- Sergey Gromov (4/31) Mar 31 2009 It should be possible to make the C pattern work as expected. I need to
- Leandro Lucarella (17/27) Apr 01 2009 First class object, according to Wikipedia[1], means, among other things...
- Leandro Lucarella (7/27) Mar 31 2009 Agree. They should be first class citizen as dynamic arrays or hashes.
- Andrei Alexandrescu (3/26) Mar 31 2009 Why? Not grokking it.
- Leandro Lucarella (17/42) Mar 31 2009 It's perfectly explained in this thread why, all I have to say will
- Andrei Alexandrescu (19/31) Mar 31 2009 Well I don't agree, but maybe there's more arguments that could improve
- Leandro Lucarella (20/46) Apr 01 2009 This is all very nice theory, but in the practice, my 2 previos points
- Bill Baxter (15/62) Mar 31 2009 For me the distinction is that I would only consider writing a
- Andrei Alexandrescu (5/68) Mar 31 2009 Well I think a language can only have so many built-in types. We can't
- Leandro Lucarella (13/24) Mar 31 2009 You don't have to. There are very few types that are extremely useful to
- Andrei Alexandrescu (3/21) Mar 31 2009 So we must add lists too.
- Leandro Lucarella (12/30) Mar 31 2009 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- bearophile (21/26) Mar 31 2009 Notice the the python "list" is an array dynamic on the right, it's not ...
- Andrei Alexandrescu (9/20) Mar 31 2009 I know. My point was that I might want to add a reasonable data
- bearophile (14/16) Mar 31 2009 May I ask what ones?
- Max Samukha (4/24) Apr 01 2009 Why is that a typelist when it can contain almost any entity in the
- bearophile (24/27) Mar 31 2009 Too many built-ins become confusing (see Fortress), but D is quite far f...
- Andrei Alexandrescu (7/54) Mar 31 2009 Would the special set syntax look a ton better than
- Bill Baxter (5/6) Mar 31 2009 I'd actually be a heck of a lot happier with that than Tuple!(1,2).
- dsimcha (12/19) Mar 31 2009 Yeah, IMHO, some of the really basic library functions that would be bui...
- Andrei Alexandrescu (3/13) Mar 31 2009 Tuple!(...) tuple(...) { ... } is already in std.typecons.
- Bill Baxter (7/20) Mar 31 2009 Ok,didn't realize that. But with that tuple(int,float) doesn't
- Bill Baxter (20/99) Mar 31 2009 ,
- dsimcha (14/19) Mar 31 2009 Aren't builtin complex types on the way out anyhow? (See
- Bill Baxter (19/36) Mar 31 2009 Right. That's what I meant. But I feared my tuple for complex
- Andrei Alexandrescu (6/10) Mar 31 2009 Ironic as that might be, I wouldn't mind it. The syntax of associative
At times, like when trying to write a syntactically sweet tuple unpacker, I've wanted to be able to declare a variable that will be passed by reference to a function inside the function call. For example: void doStuff(out uint num) { // Could also be ref uint num. num = 666; } import std.stdio; void main() { doStuff(uint foo); // Declare foo as uint, passes it to doStuff. writeln(foo); // Prints 666. } Is it feasible, at least in principle, to allow this, or would this create issues with parsing, odd ambiguities that I haven't thought of, etc.?
Mar 30 2009
On Tue, 31 Mar 2009 06:46:32 +0400, dsimcha <dsimcha yahoo.com> wrote:At times, like when trying to write a syntactically sweet tuple unpacker, I've wanted to be able to declare a variable that will be passed by reference to a function inside the function call. For example: void doStuff(out uint num) { // Could also be ref uint num. num = 666; } import std.stdio; void main() { doStuff(uint foo); // Declare foo as uint, passes it to doStuff. writeln(foo); // Prints 666. } Is it feasible, at least in principle, to allow this, or would this create issues with parsing, odd ambiguities that I haven't thought of, etc.?It seems loogically that "foo" should die right after doStuff returns, because its scope is limited to parens. It's also redundant to specify type of foo, it can be deduced from function signature (auto foo?). That said, I don't think there is a need for something like this. Certainly no speedup and little clarity compared to declaring variable right before invoking doStuff.
Mar 30 2009
== Quote from Denis Koroskin (2korden gmail.com)'s articleOn Tue, 31 Mar 2009 06:46:32 +0400, dsimcha <dsimcha yahoo.com> wrote:Nothing wrong with auto, but you need to specify something, even if it's just auto, to make it clear that you're declaring a type.At times, like when trying to write a syntactically sweet tuple unpacker, I've wanted to be able to declare a variable that will be passed by reference to a function inside the function call. For example: void doStuff(out uint num) { // Could also be ref uint num. num = 666; } import std.stdio; void main() { doStuff(uint foo); // Declare foo as uint, passes it to doStuff. writeln(foo); // Prints 666. } Is it feasible, at least in principle, to allow this, or would this create issues with parsing, odd ambiguities that I haven't thought of, etc.?It seems loogically that "foo" should die right after doStuff returns, because its scope is limited to parens. It's also redundant to specify type of foo, it can be deduced from function signature (auto foo?).That said, I don't think there is a need for something like this. Certainly no speedup and little clarity compared to declaring variable right before invoking doStuff.Here's an example of where it would be a useful piece of sugar, given an unpack function that I was playing with: // How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();
Mar 30 2009
dsimcha <dsimcha yahoo.com> wrote:== Quote from Denis Koroskin (2korden gmail.com)'s articleIf foo and bar die right after this line, I feel this is acceptable. But declaring variables inside a function call seems to me hard to decipher and hardly ever a good idea. -- SimenThat said, I don't think there is a need for something like this. Certainly no speedup and little clarity compared to declaring variable right before invoking doStuff.Here's an example of where it would be a useful piece of sugar, given an unpack function that I was playing with: // How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();
Mar 31 2009
2009/3/30 dsimcha <dsimcha yahoo.com>:// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable. That would practically remove the need for out parameters, and would remove the need for this request as well (since that's about the only time you'd need it).
Mar 31 2009
== Quote from Jarrett Billingsley (jarrett.billingsley gmail.com)'s article2009/3/30 dsimcha <dsimcha yahoo.com>:Well, apparently, alias this is getting implemented soon (see Phobos changelog on dsource), which for all practical purposes gives returnable tuples because the Tuple struct in std.typetyple can be made to look exactly like a builtin tuple. I assume you mean automatic unpacking of tuples. Not sure if there's any good reason other than higher priority stuff to implement first why this doesn't already exist.// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable. That would practically remove the need for out parameters, and would remove the need for this request as well (since that's about the only time you'd need it).
Mar 31 2009
Jarrett Billingsley wrote:2009/3/30 dsimcha <dsimcha yahoo.com>:They are. Andrei// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable.
Mar 31 2009
On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Jarrett Billingsley wrote:template Tuple(T...) { alias T Tuple; } Tuple!(int, float) foo() { return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable.
Mar 31 2009
Jarrett Billingsley wrote:On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { alias T Tuple; } Tuple!(int, float) foo() { return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable.
Mar 31 2009
On Tue, Mar 31, 2009 at 3:18 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { =A0 =A0return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better.Cool, but.. Why not just make tuples first-class types? <_<
Mar 31 2009
Jarrett Billingsley wrote:On Tue, Mar 31, 2009 at 3:18 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Why not not? Andreiimport std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better.Cool, but.. Why not just make tuples first-class types? <_<
Mar 31 2009
Andrei Alexandrescu wrote:Jarrett Billingsley wrote:Why not remove return values in favour of out parameters? That makes overloading on return values instantly possible, and removes complexity from the language and the compiler. The disadvantage of not being able to use functions in expressions could be removed by library support. We can use string mixins and CTFE to do this: void add(T)(T a, T b, out T result); mixin(expr("assert(add(1, 2, #ret) == 3)); This is an advantage over the old design, because the complex issue about handling return values is moved from the compiler into the library, and thus is more flexible and more customizable. Users could even write their own expr() template to support multiple return values.On Tue, Mar 31, 2009 at 3:18 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Why not not?import std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better.Cool, but.. Why not just make tuples first-class types? <_<Andrei
Mar 31 2009
Andrei Alexandrescu wrote:Jarrett Billingsley wrote:Because people keep having to invent hacks to work around the fact that we can't return tuples. std.typecons.Tuple is a perfect example of this. -- DanielOn Tue, Mar 31, 2009 at 3:18 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Why not not? Andreiimport std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better.Cool, but.. Why not just make tuples first-class types? <_<
Mar 31 2009
Daniel Keep wrote:Andrei Alexandrescu wrote:"It's not a hack, it's a feature." If you don't have a list in the language and build it as a user-defined type, is that a hack? AndreiJarrett Billingsley wrote:Because people keep having to invent hacks to work around the fact that we can't return tuples. std.typecons.Tuple is a perfect example of this.On Tue, Mar 31, 2009 at 3:18 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Why not not? Andreiimport std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better.Cool, but.. Why not just make tuples first-class types? <_<
Mar 31 2009
Andrei Alexandrescu wrote:Daniel Keep wrote:Only if the language itself has lists except you can't return them from functions, and you have to wrap them in a struct to make that work. Except then you can't index them, so you have to add "alias this;" to make *that* work. :P -- DanielAndrei Alexandrescu wrote:"It's not a hack, it's a feature." If you don't have a list in the language and build it as a user-defined type, is that a hack? AndreiJarrett Billingsley wrote:Because people keep having to invent hacks to work around the fact that we can't return tuples. std.typecons.Tuple is a perfect example of this.... Why not just make tuples first-class types? <_<Why not not? Andrei
Mar 31 2009
Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:Jarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. While typecons.Tuple is sorta OK for construction, things are still pretty ugly on the "decomposition" end.On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { alias T Tuple; } Tuple!(int, float) foo() { return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable.
Mar 31 2009
On Wed, Apr 1, 2009 at 5:03 AM, Sergey Gromov <snake.scaly gmail.com> wrote= :Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:Right. In my ideal world I could use tuples like this: (int,float) a; a =3D returns_tuple(); a[0] =3D 2; a[1] =3D 3.4; (int,float) z =3D returns_tuple(); (int x, float y) =3D returns_tuple(); auto tup =3D (2, 3.4); takes_int_and_float(unpack!(tup)); I think experience with tuples in Python and ML (and probably elsewhere -- heck even D) shows that tuples are incredibly useful. So useful that they deserve better syntax than Tuple!(...). --bbJarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. =A0While typecons.Tuple is sorta OK for construction, things are still pretty ugly on the "decomposition" end.On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { =A0 =A0 =A0return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { =A0 =A0 =A0alias T Tuple; } Tuple!(int, float) foo() { =A0 =A0 =A0return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) =3D someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) =3D someFunction();Cute, but uh, I'd much rather see tuples just be returnable.
Mar 31 2009
Bill Baxter wrote:On Wed, Apr 1, 2009 at 5:03 AM, Sergey Gromov <snake.scaly gmail.com> wrote:That sucks. Is int(int, float) a function type or a juxtaposition of two types? Is (A, B) an expression or a type? And so on.Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:Right. In my ideal world I could use tuples like this: (int,float) a;Jarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. While typecons.Tuple is sorta OK for construction, things are still pretty ugly on the "decomposition" end.On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { alias T Tuple; } Tuple!(int, float) foo() { return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable.a = returns_tuple(); a[0] = 2; a[1] = 3.4;That works in my tree already due to alias this.(int,float) z = returns_tuple();Blech.(int x, float y) = returns_tuple();I'd like that too, but what we should have is make any definition an expression.auto tup = (2, 3.4);Belch (sic).takes_int_and_float(unpack!(tup));Meh.I think experience with tuples in Python and ML (and probably elsewhere -- heck even D) shows that tuples are incredibly useful. So useful that they deserve better syntax than Tuple!(...).Ehm. Andrei
Mar 31 2009
On Wed, Apr 1, 2009 at 6:16 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Bill Baxter wrote:,On Wed, Apr 1, 2009 at 5:03 AM, Sergey Gromov <snake.scaly gmail.com> wrote:Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:Jarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. =A0While typecons.Tuple is sorta OK for construction=On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { =A0 =A0 return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { =A0 =A0 alias T Tuple; } Tuple!(int, float) foo() { =A0 =A0 return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) =3D someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) =3D someFunction();Cute, but uh, I'd much rather see tuples just be returnable.Thanks for that insightful analysis and commentary. :) --bbThat sucks. Is int(int, float) a function type or a juxtaposition of two types? Is (A, B) an expression or a type? And so on.things are still pretty ugly on the "decomposition" end.Right. =A0In my ideal world I could use tuples like this: (int,float) a;a =3D returns_tuple(); a[0] =3D 2; a[1] =3D 3.4;That works in my tree already due to alias this.(int,float) z =3D returns_tuple();Blech.(int x, float y) =3D returns_tuple();I'd like that too, but what we should have is make any definition an expression.auto tup =3D (2, 3.4);Belch (sic).takes_int_and_float(unpack!(tup));Meh.I think experience with tuples in Python and ML (and probably elsewhere -- heck even D) shows that tuples are incredibly useful. =A0So useful that they deserve better syntax than Tuple!(...).Ehm.
Mar 31 2009
On Wed, Apr 1, 2009 at 6:16 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Bill Baxter wrote:,On Wed, Apr 1, 2009 at 5:03 AM, Sergey Gromov <snake.scaly gmail.com> wrote:Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:Jarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. =A0While typecons.Tuple is sorta OK for construction=On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { =A0 =A0 return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { =A0 =A0 alias T Tuple; } Tuple!(int, float) foo() { =A0 =A0 return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) =3D someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) =3D someFunction();Cute, but uh, I'd much rather see tuples just be returnable.I should say that by "in my ideal world" what I meant was "forgetting about all the baggage that D already has for a moment and starting from a more or less clean slate". Things like the useless comma operator. But isn't a juxtaposition of two types a syntax error? So the above would be a function type, not a juxtaposition of two types.That sucks. Is int(int, float) a function type or a juxtaposition of two types?things are still pretty ugly on the "decomposition" end.Right. =A0In my ideal world I could use tuples like this: (int,float) a;Is (A, B) an expression or a type? And so on.How does that differ from asking "Is A an expression or a type?" If A and B are types, then (A,B) is a type.Blech to that, but you like Tuple!(int,float) z =3D returns_tuple(); correct?(int,float) z =3D returns_tuple();Blech.Belch to that, but again, you're saying this is great auto tup =3D Tuple!(2, 3.4); correct? --bb(int x, float y) =3D returns_tuple();I'd like that too, but what we should have is make any definition an expression.auto tup =3D (2, 3.4);Belch (sic).
Mar 31 2009
Bill Baxter wrote:On Wed, Apr 1, 2009 at 6:16 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Yah, sorry for the dismissive comments... what I meant was that the literal you suggested is so ambiguous grammatically, it's a non-improvement compared to just writing Tuple! there. AndreiBill Baxter wrote:I should say that by "in my ideal world" what I meant was "forgetting about all the baggage that D already has for a moment and starting from a more or less clean slate". Things like the useless comma operator. But isn't a juxtaposition of two types a syntax error? So the above would be a function type, not a juxtaposition of two types.On Wed, Apr 1, 2009 at 5:03 AM, Sergey Gromov <snake.scaly gmail.com> wrote:That sucks. Is int(int, float) a function type or a juxtaposition of two types?Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:Right. In my ideal world I could use tuples like this: (int,float) a;Jarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. While typecons.Tuple is sorta OK for construction, things are still pretty ugly on the "decomposition" end.On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { alias T Tuple; } Tuple!(int, float) foo() { return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable.Is (A, B) an expression or a type? And so on.How does that differ from asking "Is A an expression or a type?" If A and B are types, then (A,B) is a type.Blech to that, but you like Tuple!(int,float) z = returns_tuple(); correct?(int,float) z = returns_tuple();Blech.Belch to that, but again, you're saying this is great auto tup = Tuple!(2, 3.4); correct? --bb(int x, float y) = returns_tuple();I'd like that too, but what we should have is make any definition an expression.auto tup = (2, 3.4);Belch (sic).
Mar 31 2009
Tue, 31 Mar 2009 17:54:30 -0700, Andrei Alexandrescu wrote:Bill Baxter wrote:Comma expression is not ambiguous. It's a comma expression. Renaming it into a tuple constructor expression does not add any ambiguity. Parentheses here are only required to separate the comma expression from an assignment expression which otherwise would become a part of comma expression. Sure there are problems with making tuples first-class, but this is certainly not one of them. I'm putting together a blog post about a possible design of first-class tuples in D. Hope it won't take too long.On Wed, Apr 1, 2009 at 6:16 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Yah, sorry for the dismissive comments... what I meant was that the literal you suggested is so ambiguous grammatically, it's a non-improvement compared to just writing Tuple! there.Bill Baxter wrote:I should say that by "in my ideal world" what I meant was "forgetting about all the baggage that D already has for a moment and starting from a more or less clean slate". Things like the useless comma operator. But isn't a juxtaposition of two types a syntax error? So the above would be a function type, not a juxtaposition of two types.On Wed, Apr 1, 2009 at 5:03 AM, Sergey Gromov <snake.scaly gmail.com> wrote:That sucks. Is int(int, float) a function type or a juxtaposition of two types?Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:Right. In my ideal world I could use tuples like this: (int,float) a;Jarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. While typecons.Tuple is sorta OK for construction, things are still pretty ugly on the "decomposition" end.On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { alias T Tuple; } Tuple!(int, float) foo() { return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable.Is (A, B) an expression or a type? And so on.How does that differ from asking "Is A an expression or a type?" If A and B are types, then (A,B) is a type.Blech to that, but you like Tuple!(int,float) z = returns_tuple(); correct?(int,float) z = returns_tuple();Blech.Belch to that, but again, you're saying this is great auto tup = Tuple!(2, 3.4); correct? --bb(int x, float y) = returns_tuple();I'd like that too, but what we should have is make any definition an expression.auto tup = (2, 3.4);Belch (sic).
Mar 31 2009
Sergey Gromov wrote:Comma expression is not ambiguous. It's a comma expression. Renaming it into a tuple constructor expression does not add any ambiguity. Parentheses here are only required to separate the comma expression from an assignment expression which otherwise would become a part of comma expression. Sure there are problems with making tuples first-class, but this is certainly not one of them.I don't understand. So are you suggesting that the comma expression gets sacked?I'm putting together a blog post about a possible design of first-class tuples in D. Hope it won't take too long.What does "first-class" mean? Andrei
Mar 31 2009
Tue, 31 Mar 2009 18:38:35 -0700, Andrei Alexandrescu wrote:Sergey Gromov wrote:Now comma expression drops all the results but the last one. You lose nothing by making it keep other results as well. Then you can make it extract the last element as a result of an implicit cast. Disallowing the C-style usage of comma expression is also an option.Comma expression is not ambiguous. It's a comma expression. Renaming it into a tuple constructor expression does not add any ambiguity. Parentheses here are only required to separate the comma expression from an assignment expression which otherwise would become a part of comma expression. Sure there are problems with making tuples first-class, but this is certainly not one of them.I don't understand. So are you suggesting that the comma expression gets sacked?First-class values, like, native, with built-in compiler support.I'm putting together a blog post about a possible design of first-class tuples in D. Hope it won't take too long.What does "first-class" mean?
Mar 31 2009
Sergey Gromov wrote:Tue, 31 Mar 2009 18:38:35 -0700, Andrei Alexandrescu wrote:That won't work because you'd paste C code into your D code and it'll compile with different results.Sergey Gromov wrote:Now comma expression drops all the results but the last one. You lose nothing by making it keep other results as well. Then you can make it extract the last element as a result of an implicit cast.Comma expression is not ambiguous. It's a comma expression. Renaming it into a tuple constructor expression does not add any ambiguity. Parentheses here are only required to separate the comma expression from an assignment expression which otherwise would become a part of comma expression. Sure there are problems with making tuples first-class, but this is certainly not one of them.I don't understand. So are you suggesting that the comma expression gets sacked?Disallowing the C-style usage of comma expression is also an option.Ok.A tuple is a parameterized type, not a value. And first-class doesn't mean with built-in compiler support. AndreiFirst-class values, like, native, with built-in compiler support.I'm putting together a blog post about a possible design of first-class tuples in D. Hope it won't take too long.What does "first-class" mean?
Mar 31 2009
Tue, 31 Mar 2009 18:55:10 -0700, Andrei Alexandrescu wrote:Sergey Gromov wrote:It should be possible to make the C pattern work as expected. I need to think about this in more detail to be sure.Tue, 31 Mar 2009 18:38:35 -0700, Andrei Alexandrescu wrote:That won't work because you'd paste C code into your D code and it'll compile with different results.Sergey Gromov wrote:Now comma expression drops all the results but the last one. You lose nothing by making it keep other results as well. Then you can make it extract the last element as a result of an implicit cast.Comma expression is not ambiguous. It's a comma expression. Renaming it into a tuple constructor expression does not add any ambiguity. Parentheses here are only required to separate the comma expression from an assignment expression which otherwise would become a part of comma expression. Sure there are problems with making tuples first-class, but this is certainly not one of them.I don't understand. So are you suggesting that the comma expression gets sacked?Probably I've mis-used the first-class thing here.A tuple is a parameterized type, not a value. And first-class doesn't mean with built-in compiler support.First-class values, like, native, with built-in compiler support.I'm putting together a blog post about a possible design of first-class tuples in D. Hope it won't take too long.What does "first-class" mean?
Mar 31 2009
Sergey Gromov, el 1 de abril a las 06:08 me escribiste:First class object, according to Wikipedia[1], means, among other things, that is "being expressible as an anonymous literal value". Since in D there is no way to define new literals in library code (until macros are implemented, I hope =), the only way to add tuple literals that I know of is adding built-in compiler support. Then assuming, as discussed in this thread, that you'll propose tuples to have literal values in your blog post, I don't think you mis-used the term here =) [1] http://en.wikipedia.org/wiki/First-class_object -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- Are you nervy, irritable, depressed, tired of life. Keep it up. -- Monty PythonProbably I've mis-used the first-class thing here.A tuple is a parameterized type, not a value. And first-class doesn't mean with built-in compiler support.First-class values, like, native, with built-in compiler support.I'm putting together a blog post about a possible design of first-class tuples in D. Hope it won't take too long.What does "first-class" mean?
Apr 01 2009
Bill Baxter, el 1 de abril a las 05:22 me escribiste:Right. In my ideal world I could use tuples like this: (int,float) a; a = returns_tuple(); a[0] = 2; a[1] = 3.4; (int,float) z = returns_tuple(); (int x, float y) = returns_tuple(); auto tup = (2, 3.4); takes_int_and_float(unpack!(tup)); I think experience with tuples in Python and ML (and probably elsewhere -- heck even D) shows that tuples are incredibly useful. So useful that they deserve better syntax than Tuple!(...).Agree. They should be first class citizen as dynamic arrays or hashes. -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ----------------------------------------------------------------------------
Mar 31 2009
Leandro Lucarella wrote:Bill Baxter, el 1 de abril a las 05:22 me escribiste:Why? Not grokking it. AndreiRight. In my ideal world I could use tuples like this: (int,float) a; a = returns_tuple(); a[0] = 2; a[1] = 3.4; (int,float) z = returns_tuple(); (int x, float y) = returns_tuple(); auto tup = (2, 3.4); takes_int_and_float(unpack!(tup)); I think experience with tuples in Python and ML (and probably elsewhere -- heck even D) shows that tuples are incredibly useful. So useful that they deserve better syntax than Tuple!(...).Agree. They should be first class citizen as dynamic arrays or hashes.
Mar 31 2009
Andrei Alexandrescu, el 31 de marzo a las 17:57 me escribiste:Leandro Lucarella wrote:It's perfectly explained in this thread why, all I have to say will repeate something already said (the int[] vs. std::vector<int> mostly). Of course you don't seem to agree with those arguments... If they are not 1st citizens you just end up: 1) not using them 2) making your code look like boost, I mean *really* ugly ;) (when what you want to do it's even possible, of course) -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- Every year is getting shorter never seem to find the time. Plans that either come to nought or half a page of scribbled lines. Hanging on in quiet desparation is the English way. The time is gone, the song is over, thought I'd something more to say.Bill Baxter, el 1 de abril a las 05:22 me escribiste:Why? Not grokking it.Right. In my ideal world I could use tuples like this: (int,float) a; a = returns_tuple(); a[0] = 2; a[1] = 3.4; (int,float) z = returns_tuple(); (int x, float y) = returns_tuple(); auto tup = (2, 3.4); takes_int_and_float(unpack!(tup)); I think experience with tuples in Python and ML (and probably elsewhere -- heck even D) shows that tuples are incredibly useful. So useful that they deserve better syntax than Tuple!(...).Agree. They should be first class citizen as dynamic arrays or hashes.
Mar 31 2009
Leandro Lucarella wrote:Andrei Alexandrescu, el 31 de marzo a las 17:57 me escribiste:Well I don't agree, but maybe there's more arguments that could improve that.It's perfectly explained in this thread why, all I have to say will repeate something already said (the int[] vs. std::vector<int> mostly). Of course you don't seem to agree with those arguments...Agree. They should be first class citizen as dynamic arrays or hashes.Why? Not grokking it.If they are not 1st citizens you just end up: 1) not using them 2) making your code look like boost, I mean *really* ugly ;) (when what you want to do it's even possible, of course)Tuple is a 1st citizen language constituent (they have to). It just doesn't have a literal. Say we do invent a literal, e.g.: [: int, float :] mytuple; Does this improve the language over Tuple!(int, float)? I'm not convinced - at all, in fact. Right now Tuple is on equal footing with other templates and whatever introspection we have/will add works/will work on Tuple as it works with other templates. With the extra syntax, we'll then need to add special methods for introspecting a tuple. We'll find ourselves also reserving a keyword "tuple" and positing that [: ... :] is the same as tuple!(...) or some other similarly unpleasant solution. Plus, special syntax contributes to the disconnect between user-defined and built-in. This creates the self-perpetuating trend that if anything is interesting, it should have a literal allocated to it. Instead of that, let's think e.g. of methods to generally make parameterized types look better. Andrei
Mar 31 2009
Andrei Alexandrescu, el 31 de marzo a las 18:50 me escribiste:Leandro Lucarella wrote:Yes, even when that literal sucks =)Andrei Alexandrescu, el 31 de marzo a las 17:57 me escribiste:Well I don't agree, but maybe there's more arguments that could improve that.It's perfectly explained in this thread why, all I have to say will repeate something already said (the int[] vs. std::vector<int> mostly). Of course you don't seem to agree with those arguments...Agree. They should be first class citizen as dynamic arrays or hashes.Why? Not grokking it.If they are not 1st citizens you just end up: 1) not using them 2) making your code look like boost, I mean *really* ugly ;) (when what you want to do it's even possible, of course)Tuple is a 1st citizen language constituent (they have to). It just doesn't have a literal. Say we do invent a literal, e.g.: [: int, float :] mytuple; Does this improve the language over Tuple!(int, float)?I'm not convinced - at all, in fact. Right now Tuple is on equal footing with other templates and whatever introspection we have/will add works/will work on Tuple as it works with other templates. With the extra syntax, we'll then need to add special methods for introspecting a tuple. We'll find ourselves also reserving a keyword "tuple" and positing that [: ... :] is the same as tuple!(...) or some other similarly unpleasant solution. Plus, special syntax contributes to the disconnect between user-defined and built-in. This creates the self-perpetuating trend that if anything is interesting, it should have a literal allocated to it. Instead of that, let's think e.g. of methods to generally make parameterized types look better.This is all very nice theory, but in the practice, my 2 previos points stands. I'm sorry to keep quoting Python stuff, I agree pretty much with The Zen if Python (python -m this): Special cases aren't special enough to break the rules. Although practicality beats purity. =) -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- They love me like I was a brother They protect me, listen to me They dug me my very own garden Gave me sunshine, made me happy Nice dream, nice dream Nice dream
Apr 01 2009
On Wed, Apr 1, 2009 at 5:03 AM, Sergey Gromov <snake.scaly gmail.com> wrote= :Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:For me the distinction is that I would only consider writing a function that returns something like "Tuple!(int, float)" as a last resort when no other design would work. I would sooner use two out parameters. But in Python or ML, no question. I'd happily write a function that returns (2, 4.2) without giving it much thought. Now perhaps cogent arguments like "blech" and "belch" can convince me that I should embrace the Tuple!(int,float) and use it everywhere, just like I'd use tuples in Python and ML, but so far I'm not convinced. To me it seems to be in the same league as int[] vs std::vector<int>. int[] -- great I'll happily use that everywhere. std::vector<int> kind of a pain, use begrudgingly as needed. --bbJarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. =A0While typecons.Tuple is sorta OK for construction, things are still pretty ugly on the "decomposition" end.On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { =A0 =A0 =A0return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { =A0 =A0 =A0alias T Tuple; } Tuple!(int, float) foo() { =A0 =A0 =A0return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) =3D someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) =3D someFunction();Cute, but uh, I'd much rather see tuples just be returnable.
Mar 31 2009
Bill Baxter wrote:On Wed, Apr 1, 2009 at 5:03 AM, Sergey Gromov <snake.scaly gmail.com> wrote:Why? I use tuple returns all over.Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:For me the distinction is that I would only consider writing a function that returns something like "Tuple!(int, float)" as a last resort when no other design would work. I would sooner use two out parameters.Jarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. While typecons.Tuple is sorta OK for construction, things are still pretty ugly on the "decomposition" end.On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { alias T Tuple; } Tuple!(int, float) foo() { return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) = someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) = someFunction();Cute, but uh, I'd much rather see tuples just be returnable.But in Python or ML, no question. I'd happily write a function that returns (2, 4.2) without giving it much thought. Now perhaps cogent arguments like "blech" and "belch" can convince me that I should embrace the Tuple!(int,float) and use it everywhere, just like I'd use tuples in Python and ML, but so far I'm not convinced. To me it seems to be in the same league as int[] vs std::vector<int>. int[] -- great I'll happily use that everywhere. std::vector<int> kind of a pain, use begrudgingly as needed.Well I think a language can only have so many built-in types. We can't go on forever. Andrei
Mar 31 2009
Andrei Alexandrescu, el 31 de marzo a las 17:55 me escribiste:You don't have to. There are very few types that are extremely useful to build up things having a good syntax. I think Python got this right: tuples, lists, hashes. That's all you need as first class citizens (speaking of "containers"). I think D is only missing tuples (dynamic arrays works just fine as lists in D). -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- The Muppet show was banned from TV in Saudi Arabia Because one of its stars was a pigBut in Python or ML, no question. I'd happily write a function that returns (2, 4.2) without giving it much thought. Now perhaps cogent arguments like "blech" and "belch" can convince me that I should embrace the Tuple!(int,float) and use it everywhere, just like I'd use tuples in Python and ML, but so far I'm not convinced. To me it seems to be in the same league as int[] vs std::vector<int>. int[] -- great I'll happily use that everywhere. std::vector<int> kind of a pain, use begrudgingly as needed.Well I think a language can only have so many built-in types. We can't go on forever.
Mar 31 2009
Leandro Lucarella wrote:Andrei Alexandrescu, el 31 de marzo a las 17:55 me escribiste:So we must add lists too. AndreiYou don't have to. There are very few types that are extremely useful to build up things having a good syntax. I think Python got this right: tuples, lists, hashes. That's all you need as first class citizens (speaking of "containers"). I think D is only missing tuples (dynamic arrays works just fine as lists in D).But in Python or ML, no question. I'd happily write a function that returns (2, 4.2) without giving it much thought. Now perhaps cogent arguments like "blech" and "belch" can convince me that I should embrace the Tuple!(int,float) and use it everywhere, just like I'd use tuples in Python and ML, but so far I'm not convinced. To me it seems to be in the same league as int[] vs std::vector<int>. int[] -- great I'll happily use that everywhere. std::vector<int> kind of a pain, use begrudgingly as needed.Well I think a language can only have so many built-in types. We can't go on forever.
Mar 31 2009
Andrei Alexandrescu, el 31 de marzo a las 18:42 me escribiste:Leandro Lucarella wrote:^^^^^^^Andrei Alexandrescu, el 31 de marzo a las 17:55 me escribiste:You don't have to. There are very few types that are extremely useful to build up things having a good syntax. I think Python got this right: tuples, lists, hashes. That's all you need as first class citizens (speaking of "containers"). I think D is only missing tuples (dynamicBut in Python or ML, no question. I'd happily write a function that returns (2, 4.2) without giving it much thought. Now perhaps cogent arguments like "blech" and "belch" can convince me that I should embrace the Tuple!(int,float) and use it everywhere, just like I'd use tuples in Python and ML, but so far I'm not convinced. To me it seems to be in the same league as int[] vs std::vector<int>. int[] -- great I'll happily use that everywhere. std::vector<int> kind of a pain, use begrudgingly as needed.Well I think a language can only have so many built-in types. We can't go on forever.^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^arrays works just fine as lists in D).So we must add lists too.Are you ignoring what I'm writing on purpose? =) -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- He used to do surgery On girls in the eighties But gravity always wins
Mar 31 2009
Andrei Alexandrescu:So we must add lists too.Notice the the python "list" is an array dynamic on the right, it's not a linked list. Regarding tuple: I don't like the name "tuple" of typecons, because they aren't the tuples of D, they are structs. That's why I have named them Record/record in my dlibs. In my dlibs Tuple is: template Tuple(T...) { alias T Tuple; } Also, tuple of typecons misses some very important methods. ---------------------- Andrei Alexandrescu:Would the special set syntax look a ton better thanset(1, 2, 5, 6) set("ab", "c") ?< I agree, that's acceptable. That's how they are implemented in my d.sets.I guess I can't bring myself to dislike tuple(1, 2) in D.<"I don't agree": a built-in tuple allows you some of the other things I have shown you in Python. --------------- Bill Baxter:Walter read a paper by a numerical math guy stating that some things just can't be done correctly if complex types aren't part of the language.<Maybe you are talking about William Kahan, a person that knows more than the square of what you, me and Walter knows :-) See Complex Arithmetic Class here: http://www.eecs.berkeley.edu/~wkahan/JAVAhurt.pdfAnd I guess it seemed true at the time. But since then they have figured out a way to make the compiler clever enough to handle such cases correctly even without it being built-in.<Do you have references or links that can show me that what Kahan says there is not longer necessary/true? Bye, bearophile
Mar 31 2009
bearophile wrote:Andrei Alexandrescu:I know. My point was that I might want to add a reasonable data structure to the language, and it's hard to build an argument on what to leave out and what to put in.So we must add lists too.Notice the the python "list" is an array dynamic on the right, it's not a linked list.Regarding tuple: I don't like the name "tuple" of typecons, because they aren't the tuples of D, they are structs. That's why I have named them Record/record in my dlibs.D is at fault because it called typelists tuples. I told Walter not to, and he went ahead and did so anyway. Now we're living with the consequences.In my dlibs Tuple is: template Tuple(T...) { alias T Tuple; }That's a typelist.Also, tuple of typecons misses some very important methods.I added a few (soon to be released). Andrei
Mar 31 2009
Andrei Alexandrescu:D is at fault because it called typelists tuples. I told Walter not to, and he went ahead and did so anyway. Now we're living with the consequences.<I see, and you are right. Then why not rename tuples of D2 to a more correct name (typelists)? Being D2 in alpha still there's time to rename invariant as immutable, tuples as typelists... :-) Giving the right names to things is important.I added a few (soon to be released).<May I ask what ones? My Records (of D1) have: - attribute length - opCmp that uses a recursive structCmp() that works even with nested normal structs tpp :-) - opEquals - toHash (this too is recursive nested normal structs too) - opIn_r - toString - opCat, that attaches a Record to another Record/generic struct, creating a new Record. All that is useful. This allows them to work almost as Python tuples. But Record/record doesn't support a good unpacking syntax, of course. You may need compiler support for this. Bye, bearophile
Mar 31 2009
On Tue, 31 Mar 2009 23:07:46 -0700, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:bearophile wrote:Why is that a typelist when it can contain almost any entity in the language, not only types?Andrei Alexandrescu:I know. My point was that I might want to add a reasonable data structure to the language, and it's hard to build an argument on what to leave out and what to put in.So we must add lists too.Notice the the python "list" is an array dynamic on the right, it's not a linked list.Regarding tuple: I don't like the name "tuple" of typecons, because they aren't the tuples of D, they are structs. That's why I have named them Record/record in my dlibs.D is at fault because it called typelists tuples. I told Walter not to, and he went ahead and did so anyway. Now we're living with the consequences.In my dlibs Tuple is: template Tuple(T...) { alias T Tuple; }That's a typelist.Also, tuple of typecons misses some very important methods.I added a few (soon to be released). Andrei
Apr 01 2009
Andrei Alexandrescu:Well I think a language can only have so many built-in types. We can't go on forever.Too many built-ins become confusing (see Fortress), but D is quite far from that point (see Python, that has more than D and they are just fine and easy to use and remember. I'd also like to add a set literal to the D syntax, semantically implemented in the std library). On the other hand Scala language shows that a good language allows you to remove things from the language/syntax and implement them as libraries (Scala moves in the libs several things that are built-in in D). So it's a dynamic balance, things go, things come. But note that collection "literals" of Scala are worse than Python ones. --------------- Sergey Gromov:Comma expression is not ambiguous. It's a comma expression. Renaming it into a tuple constructor expression does not add any ambiguity. Parentheses here are only required to separate the comma expression from an assignment expression which otherwise would become a part of comma expression.<Python has tuples, but their syntax has some holes I have never fully loved. See: Empty tuple: () Tuple with 1 item: 1, Or (1,) Tuple with two items: 1, 2 Or: (1, 2) They also support smarter forms of unpacking (Python 2.6): def foo((x, y)): Now if you pass foo a pair (a 2-list, 2-tuple, 2-string, 2-lazy iterable, 2-array, 2-set, 2-dict, etc) you have available and assigned x and y inside foo. In the following syntax (Python 3.0+), c becomes assigned with all the items following the second one: a, b, *c = baz In the end I don't like the use of () to denote tuples (well, in Python most of the times it's the comma that denotes a tuple, only empty tuples needs () ). So better to use different ways to denote them. Bye, bearophile
Mar 31 2009
bearophile wrote:Andrei Alexandrescu:Would the special set syntax look a ton better than set(1, 2, 5, 6) set("ab", "c") ?Well I think a language can only have so many built-in types. We can't go on forever.Too many built-ins become confusing (see Fortress), but D is quite far from that point (see Python, that has more than D and they are just fine and easy to use and remember. I'd also like to add a set literal to the D syntax, semantically implemented in the std library).On the other hand Scala language shows that a good language allows you to remove things from the language/syntax and implement them as libraries (Scala moves in the libs several things that are built-in in D). So it's a dynamic balance, things go, things come. But note that collection "literals" of Scala are worse than Python ones. --------------- Sergey Gromov:I guess I can't bring myself to dislike tuple(1, 2) in D. AndreiComma expression is not ambiguous. It's a comma expression. Renaming it into a tuple constructor expression does not add any ambiguity. Parentheses here are only required to separate the comma expression from an assignment expression which otherwise would become a part of comma expression.<Python has tuples, but their syntax has some holes I have never fully loved. See: Empty tuple: () Tuple with 1 item: 1, Or (1,) Tuple with two items: 1, 2 Or: (1, 2) They also support smarter forms of unpacking (Python 2.6): def foo((x, y)): Now if you pass foo a pair (a 2-list, 2-tuple, 2-string, 2-lazy iterable, 2-array, 2-set, 2-dict, etc) you have available and assigned x and y inside foo. In the following syntax (Python 3.0+), c becomes assigned with all the items following the second one: a, b, *c = baz In the end I don't like the use of () to denote tuples (well, in Python most of the times it's the comma that denotes a tuple, only empty tuples needs () ). So better to use different ways to denote them. Bye, bearophile
Mar 31 2009
On Wed, Apr 1, 2009 at 10:53 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:I guess I can't bring myself to dislike tuple(1, 2) in D.I'd actually be a heck of a lot happier with that than Tuple!(1,2). Especially if using it didn't require any explicit import. --bb
Mar 31 2009
== Quote from Bill Baxter (wbaxter gmail.com)'s articleOn Wed, Apr 1, 2009 at 10:53 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Yeah, IMHO, some of the really basic library functions that would be builtins in other languages should be implicitly imported in Object. Yes, namespace pollution is generally a bad thing, but noone in their right mind would name some arbitrary function max(), map(), filter(), etc. anyhow because that's just really bad naming. Given that functions with these names have such standard, well-defined meanings, trying to use these names for arbitrary functions is only marginally smarter than trying to name your function after some keyword. The fact that D can support these features well as libraries and they don't need to be built in is a good thing, and they should remain as libraries. It's just that for such basic, commonly used functions, even the mental burden of having to remember to import them is too much, and this problem is trivial to fix.I guess I can't bring myself to dislike tuple(1, 2) in D.I'd actually be a heck of a lot happier with that than Tuple!(1,2). Especially if using it didn't require any explicit import. --bb
Mar 31 2009
Bill Baxter wrote:On Wed, Apr 1, 2009 at 10:53 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Tuple!(...) tuple(...) { ... } is already in std.typecons. AndreiI guess I can't bring myself to dislike tuple(1, 2) in D.I'd actually be a heck of a lot happier with that than Tuple!(1,2). Especially if using it didn't require any explicit import. --bb
Mar 31 2009
On Wed, Apr 1, 2009 at 1:12 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Bill Baxter wrote:Ok,didn't realize that. But with that tuple(int,float) doesn't compile, right? I thought you were proposing that you could get rid of Tuple!() entirely somehow and replace it with tuple(). That is what I meant I could go for. --bbOn Wed, Apr 1, 2009 at 10:53 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Tuple!(...) tuple(...) { ... } is already in std.typecons.I guess I can't bring myself to dislike tuple(1, 2) in D.I'd actually be a heck of a lot happier with that than Tuple!(1,2). Especially if using it didn't require any explicit import. --bb
Mar 31 2009
On Wed, Apr 1, 2009 at 9:55 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Bill Baxter wrote:,On Wed, Apr 1, 2009 at 5:03 AM, Sergey Gromov <snake.scaly gmail.com> wrote:Tue, 31 Mar 2009 12:18:21 -0700, Andrei Alexandrescu wrote:Jarrett Billingsley wrote:Unfair---std.typecons.Tuple is actually a struct! Well, basically struct is a run-time tuple, anyway. I think that all the buzz around "actual tuple support" boils down to requests for syntax sugar for construction and decomposition of anonymous structs. =A0While typecons.Tuple is sorta OK for construction=On Tue, Mar 31, 2009 at 1:32 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:import std.typecons; Tuple!(int, float) foo() { =A0 =A0 return tuple(2, 4.5); } The addition of the alias this feature and of constructor templates makes std.typecons.Tuple even better. AndreiJarrett Billingsley wrote:template Tuple(T...) { =A0 =A0 alias T Tuple; } Tuple!(int, float) foo() { =A0 =A0 return Tuple!(3, 4.5); } foo.d(10): Error: functions cannot return a tuple Unless you're using some prerelease compiler, they are not.2009/3/30 dsimcha <dsimcha yahoo.com>:They are.// How it works now: uint foo; string bar; unpack(foo, bar) =3D someFunction(); // vs. how I want it to work: unpack(auto foo, auto bar) =3D someFunction();Cute, but uh, I'd much rather see tuples just be returnable.It could just be paranoia, but I prefer to avoid dependency on a library type if it is possible. If I use a library type as a part of my code's public interface I'm saying that the functionality provided by that library is so important that I think all users of my library should use it also. But this is the one negative reaction to Tuple!() that I could probably be convinced to overcome. For instance if it becomes clear that everyone will be able to use Phobos and love and adore it, then I think that issue goes away for me. (But not the ugly syntax issue). But I'm not quite there yet believing that, because y'know Phobos hasn't historically been so good at getting everyone to adore it.Why? I use tuple returns all over.things are still pretty ugly on the "decomposition" end.For me the distinction is that I would only consider writing a function that returns something like "Tuple!(int, float)" as a last resort when no other design would work. =A0I would sooner use two out parameters.onBut in Python or ML, no question. I'd happily write a function that returns (2, 4.2) without giving it much thought. =A0Now perhaps cogent arguments like "blech" and "belch" can convince me that I should embrace the Tuple!(int,float) and use it everywhere, just like I'd use tuples in Python and ML, but so far I'm not convinced. To me it seems to be in the same league as int[] vs std::vector<int>. int[] -- great I'll happily use that everywhere. =A0std::vector<int> kind of a pain, use begrudgingly as needed.Well I think a language can only have so many built-in types. We can't go=forever.Ok, then we'll introduce balanced budget amendment for types to ensure this doesn't happen. For every new type added one must be removed. We're going to vote complex types off the island, right? Maybe we could get rid of associative arrays as a built-in too. --bb
Mar 31 2009
== Quote from Bill Baxter (wbaxter gmail.com)'s articleOk, then we'll introduce balanced budget amendment for types to ensure this doesn't happen. For every new type added one must be removed. We're going to vote complex types off the island, right? Maybe we could get rid of associative arrays as a built-in too. --bbAren't builtin complex types on the way out anyhow? (See http://digitalmars.com/d/2.0/phobos/std_complex.html). I always found them to be quite peculiar, as they really only are useful for a niche within a niche. Specifically, noone outside scientific computing (already a small subset of programmers) would use them, and even then, only a subset of scientific computing people need them. I personally do scientific computing (specifically bioinformatics, which for those of you who aren't familiar with the field is mostly stochastic models and data mining as applied to molecular biology), and I have never in my life used D's complex numbers. My guess is that Walter, having a mech e. degree, drastically overestimated early in D's design how many people actually use complex numbers. I know enough mechanical and electrical engineers and physicists to know that they simply love complex numbers.
Mar 31 2009
On Wed, Apr 1, 2009 at 11:15 AM, dsimcha <dsimcha yahoo.com> wrote:=3D=3D Quote from Bill Baxter (wbaxter gmail.com)'s articleRight. That's what I meant. But I feared my tuple for complex exchange would not be accepted because the demise of complex was already announced. So I threw in associative arrays too.We're going to vote complex types off the island, right? =A0 Maybe we could get rid of associative arrays as a built-in too.Aren't builtin complex types on the way out anyhow?=A0(See http://digitalmars.com/d/2.0/phobos/std_complex.html). =A0I always found =them to bequite peculiar, as they really only are useful for a niche within a niche=.Specifically, noone outside scientific computing (already a small subset =ofprogrammers) would use them, and even then, only a subset of scientific c=omputingpeople need them. =A0I personally do scientific computing (specifically bioinformatics, which for those of you who aren't familiar with the field=ismostly stochastic models and data mining as applied to molecular biology)=, and Ihave never in my life used D's complex numbers. My guess is that Walter, having a mech e. degree, drastically overestimat=ed earlyin D's design how many people actually use complex numbers. =A0I know eno=ughmechanical and electrical engineers and physicists to know that they simp=ly lovecomplex numbers.Walter read a paper by a numerical math guy stating that some things just can't be done correctly if complex types aren't part of the language. And I guess it seemed true at the time. But since then they have figured out a way to make the compiler clever enough to handle such cases correctly even without it being built-in. --bb
Mar 31 2009
Bill Baxter wrote:Ok, then we'll introduce balanced budget amendment for types to ensure this doesn't happen. For every new type added one must be removed. We're going to vote complex types off the island, right? Maybe we could get rid of associative arrays as a built-in too.Ironic as that might be, I wouldn't mind it. The syntax of associative array types is nice, but other than that they are terribly opaque to introspection. If I could, I'd say T[U] rewrites into Hash!(U, T) and then Hash is defined in object.d. Andrei
Mar 31 2009