Re: let (x,y) = ...
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 ", t[1]); I really missed the ML syntax to write let (name, age) = 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) = 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 not desired there's let (x,y,z)[] = ... variant that uses just the available data and keeps the rest variables unchanged. That's pretty neat! May I turn this code into a d-idioms? Name and link will be kept of course.
Re: let (x,y) = ...
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) = ...
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) = ...
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) = ...
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 others have it as "let" keyword, so personally I'd prefer continuing that tradition.
Re: let (x,y) = ...
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) = ...
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 ", t[1]); I really missed the ML syntax to write let (name, age) = 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) = 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 not desired there's let (x,y,z)[] = ... variant that uses just the available data and keeps the rest variables unchanged. that's a great example to show d's strength. thank you.
Re: let (x,y) = ...
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) = ...
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? http://ideone.com/iBzuiG - how "let" works in javascript.
Re: let (x,y) = ...
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) = ...
Or even more obvious (VBA,TSQL): set (x,y,z) = [1,2,3];
Re: let (x,y) = ...
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) = ...
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) = ...
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) = ...
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
Re: quick-and-dirty minimalistic LISP engine
If you weren't deliberately making a joke, you might want to google "milf". And if you were... Hmm interesting sense of humor you have there. On Feb 18, 2015 11:40 PM, "via Digitalmars-d-announce" < digitalmars-d-announce@puremagic.com> wrote: > On Wednesday, 18 February 2015 at 22:37:34 UTC, ketmar wrote: > >> yet you're still alive, so at least it's not fatal >> > > I became one year older, but I feel invigorated after this Alice encounter! > > and again, so let's consider code cleanup as an exercise for the reader. >> > > That's quite ok. I enjoy just looking at D code by different authors to > get a picture of how the language is used in real code. So thanks for > sharing! > > i know that everybody loves textbooks where the most interesting part is >> left as an exercise. >> > > Yes, especially if you get that part on an exam later on... >
Re: let (x,y) = ...
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
Re: let (x,y) = ...
"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 >
Re: We are Beta (2.067.0-b2)
On Wednesday, 18 February 2015 at 14:13:25 UTC, Martin Nowak wrote: Find more information on the dmd-beta mailing list. http://forum.dlang.org/thread/54e41ca2.4060...@dawg.eu 'lib32mscoff' should be in there,what do you think? Frank
Re: quick-and-dirty minimalistic LISP engine
On Thursday, 19 February 2015 at 14:50:43 UTC, Bill Baxter wrote: If you weren't deliberately making a joke, you might want to google "milf". What do you mean? It was my birthday! I became one year older!
Re: quick-and-dirty minimalistic LISP engine
On Thu, 19 Feb 2015 06:50:29 -0800, Bill Baxter via Digitalmars-d-announce wrote: > If you weren't deliberately making a joke, you might want to google > "milf". no jokes, it's Serious Bussiness! do you think that our project architect will allow to build our own milf without googling? or our security team don't know that i want to share our milf? it's all Official. signature.asc Description: PGP signature
Re: let (x,y) = ...
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]);
Re: quick-and-dirty minimalistic LISP engine
On Thu, 19 Feb 2015 07:39:31 +, Ola Fosheim Grøstad wrote: > That's quite ok. I enjoy just looking at D code by different authors to > get a picture of how the language is used in real code. So thanks for > sharing! same for me. i have a habit of downloading various D libraries and poking through the source, even if i'll never need to use that library. it's interesting to see how people think, and sometimes i can steal a trick. signature.asc Description: PGP signature
Re: let (x,y) = ...
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;
Re: We are Beta (2.067.0-b2)
On Wednesday, 18 February 2015 at 14:13:25 UTC, Martin Nowak wrote: Find more information on the dmd-beta mailing list. http://forum.dlang.org/thread/54e41ca2.4060...@dawg.eu Many of the beta-2 files are missing from downloads.dlang.org, and all of them are missing from ftp.digitalmars.com. This makes testing the Debian packages or using DVM impossible.
Re: quick-and-dirty minimalistic LISP engine
On Thu, Feb 19, 2015 at 8:30 AM, ketmar via Digitalmars-d-announce < digitalmars-d-announce@puremagic.com> wrote: > On Thu, 19 Feb 2015 06:50:29 -0800, Bill Baxter via Digitalmars-d-announce > wrote: > > > If you weren't deliberately making a joke, you might want to google > > "milf". > > no jokes, it's Serious Bussiness! do you think that our project architect > will allow to build our own milf without googling? or our security team > don't know that i want to share our milf? it's all Official. Okie dokie then. :-) Just wanted to make sure you knew what you were doing. But seems it's all under control. Don't mind me. You can go about your business. --bb
Re: Coedit alpha 11 released
those useless options... the next version have an awesome option editor. about 100 settings just for the editor and the highlither http://imgur.com/RdmHyKJ
dfmt 0.1.0
dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Congrats, I found the reformatting a bit harsh from time to time, but it's a good opportunity to finally settle style discussions.
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Thanks, you should list some of the formatting changes it makes in the README.
Re: We are Beta (2.067.0-b2)
On 2/19/2015 2:06 PM, Brian Schott wrote: On Wednesday, 18 February 2015 at 14:13:25 UTC, Martin Nowak wrote: Find more information on the dmd-beta mailing list. http://forum.dlang.org/thread/54e41ca2.4060...@dawg.eu Many of the beta-2 files are missing from downloads.dlang.org, and all of them are missing from ftp.digitalmars.com. This makes testing the Debian packages or using DVM impossible. The files are up now on ftp.digitalmars.com
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 05:23:45 UTC, Joakim wrote: On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Thanks, you should list some of the formatting changes it makes in the README. It doesn't do formatting changes. It wipes out the formatting during lexing and builds it up from scratch. The only thing that gets preserved is that it will look at line numbers on comments and try to keep them in roughly the same place. (For example, "//" comments that are on the end of a line instead of on the next line)
Re: dfmt 0.1.0
On Friday, 20 February 2015 at 05:53:32 UTC, Brian Schott wrote: On Friday, 20 February 2015 at 05:23:45 UTC, Joakim wrote: On Friday, 20 February 2015 at 02:21:01 UTC, Brian Schott wrote: dfmt is a D source code formatting tool. https://github.com/Hackerpilot/dfmt/ https://github.com/Hackerpilot/dfmt/releases/tag/v0.1.0 Thanks, you should list some of the formatting changes it makes in the README. It doesn't do formatting changes. It wipes out the formatting during lexing and builds it up from scratch. The only thing that gets preserved is that it will look at line numbers on comments and try to keep them in roughly the same place. (For example, "//" comments that are on the end of a line instead of on the next line) Well, you should indicate what that new formatting is in the README, so potential users know what to expect without having to run it first.