Re: Choice ranges?

2014-03-28 Thread H. S. Teoh
On Sat, Mar 29, 2014 at 01:37:42AM +0100, Artur Skawina wrote: [...] > D is statically typed -- there is no way for one function to return > different types that are selected by a runtime condition. > The fact that the produced elements have the same type is irrelevant. > > You can wrap the range

Re: Choice ranges?

2014-03-28 Thread Artur Skawina
On 03/28/14 23:10, H. S. Teoh wrote: > On Fri, Mar 28, 2014 at 10:44:11PM +0100, Artur Skawina wrote: >> On 03/28/14 20:00, H. S. Teoh wrote: >>> Today I ran into an interesting situation where I have a function f >>> that needs to return ranges of different types (but identical >>> element types):

Re: Getting a class' name, but not fully qualified?

2014-03-28 Thread w0rp
On Friday, 28 March 2014 at 20:47:39 UTC, JR wrote: On Friday, 28 March 2014 at 13:42:43 UTC, w0rp wrote: size_t dotIndex = qualName.retro.countUntil('.'); if (dotIndex < 0) { size_t is unsigned. :3 (So ptrdiff_t -- or simply auto.) Oh yes, that is a bug. There's always at least one

Re: Choice ranges?

2014-03-28 Thread monarch_dodra
On Friday, 28 March 2014 at 22:12:02 UTC, H. S. Teoh wrote: On Fri, Mar 28, 2014 at 10:44:11PM +0100, Artur Skawina wrote: eg auto f(A...)(A args) { ... return cartesianProduct(x, y) .joiner .filter!(a=>somec

Re: Order of destruction of local variables

2014-03-28 Thread monarch_dodra
On Friday, 28 March 2014 at 19:03:22 UTC, Marc Schütz wrote: That is, destruction happens in reverse lexical order of declaration, and arrays are destroyed from back to front. Is this behaviour guaranteed? Yes. It's guaranteed by spec.

Re: Choice ranges?

2014-03-28 Thread H. S. Teoh
On Fri, Mar 28, 2014 at 10:44:11PM +0100, Artur Skawina wrote: > On 03/28/14 20:00, H. S. Teoh wrote: > > Today I ran into an interesting situation where I have a function f > > that needs to return ranges of different types (but identical > > element types): > > > > auto f(A...)(A args) { > >

Re: Choice ranges?

2014-03-28 Thread Artur Skawina
On 03/28/14 20:00, H. S. Teoh wrote: > Today I ran into an interesting situation where I have a function f that > needs to return ranges of different types (but identical element types): > > auto f(A...)(A args) { > ... > if (someCondition) >

Re: Function to print a diamond shape

2014-03-28 Thread bearophile
void main(){ import std.stdio,std.range,std.algorithm,std.conv; auto m=10.iota.map!(_=>readln.split.to!(int[])); m.map!sum.chain(m.transposed.map!sum).reduce!max.write; } It used to work, but with the latest changes I think I have broken it. Bye, bearophile

Re: Order of destruction of local variables

2014-03-28 Thread Ali Çehreli
On 03/28/2014 12:03 PM, "Marc Schütz" " wrote: > destruction happens in reverse lexical order of declaration, > and arrays are destroyed from back to front. > > Is this behaviour guaranteed? It must be that way because later objects can hold references to earlier objects. Ali

Re: Choice ranges?

2014-03-28 Thread Ali Çehreli
On 03/28/2014 01:46 PM, bearophile wrote: H. S. Teoh: So how would I implement something like this? One option is to wrap those ranges in classes. See std.range for the adapters. (I have not used them yet). Link: http://dlang.org/phobos/std_range.html#.inputRangeObject Short examples he

Re: Waiting for a Spawn'ed process

2014-03-28 Thread Ali Çehreli
On 03/28/2014 11:43 AM, Sharad Gupta wrote: > But this is another spawned process. How can I tell this second process > to wait on the first one. std.concurrency is based on message passing. Normally, the second process would send a message either to its owner or to another thread that was pre

Re: Getting a class' name, but not fully qualified?

2014-03-28 Thread JR
On Friday, 28 March 2014 at 13:42:43 UTC, w0rp wrote: size_t dotIndex = qualName.retro.countUntil('.'); if (dotIndex < 0) { size_t is unsigned. :3 (So ptrdiff_t -- or simply auto.)

Re: Choice ranges?

2014-03-28 Thread bearophile
H. S. Teoh: So how would I implement something like this? One option is to wrap those ranges in classes. See std.range for the adapters. (I have not used them yet). Bye, bearophile

Re: Choice ranges?

2014-03-28 Thread Meta
On Friday, 28 March 2014 at 19:02:48 UTC, H. S. Teoh wrote: Today I ran into an interesting situation where I have a function f that needs to return ranges of different types (but identical element types): auto f(A...)(A args) { ... if (someCondition)

Order of destruction of local variables

2014-03-28 Thread Marc Schütz
struct MyStruct { string name; ~this() { import std.stdio; writeln("destroying ", name); } } void main() { auto a = MyStruct("a"), b = MyStruct("b"); { auto e = MyStruct("scoped e"); } auto c = MyStruct("c"); MyStruct[3] f = [MyStruct("1"),

Choice ranges?

2014-03-28 Thread H. S. Teoh
Today I ran into an interesting situation where I have a function f that needs to return ranges of different types (but identical element types): auto f(A...)(A args) { ... if (someCondition) return cartesianProduct(x, y)

Re: Waiting for a Spawn'ed process

2014-03-28 Thread Sharad Gupta
If you start the worker with spawnLinked then you will receive a LinkTerminated message. import std.stdio; import std.concurrency; import core.thread; void main() { auto worker = spawnLinked(&workerFunc); // Wait for worker to terminate bool terminated = false; while (!termin

Re: Getting around the lack of foreach in CTFE

2014-03-28 Thread Colin Grogan
On Friday, 28 March 2014 at 15:39:48 UTC, monarch_dodra wrote: On Friday, 28 March 2014 at 14:42:54 UTC, Colin Grogan wrote: Im trying to parse command line args and then build a struct that will, at run-time, hold the data the user passed in via command line args. Very similar to Pythons docop

Re: What is the correct function or cast to compare an unprintable ASCII character value to a string slice

2014-03-28 Thread monarch_dodra
On Friday, 28 March 2014 at 15:33:32 UTC, Gary Miller wrote: If I need to examine a byte in string for a specific ASCII value like string MyString; MyString = "Hello World" and I want to check a position in the string for a certain unprintable ASCII value like the ASCII Block 219 what is the

Waiting for a Spawn'ed process

2014-03-28 Thread Sharad Gupta
I am trying to make a Utility which spwans=>pipeShell off multiple processes on user choice. On of the issues is that some process need to wait for other processes to finish. Now I could implement it using messages but that doesn't seem very nice solution. I could also wait for the pipeShell

Re: Getting around the lack of foreach in CTFE

2014-03-28 Thread monarch_dodra
On Friday, 28 March 2014 at 14:42:54 UTC, Colin Grogan wrote: Im trying to parse command line args and then build a struct that will, at run-time, hold the data the user passed in via command line args. Very similar to Pythons docopt utility -> https://github.com/docopt/docopt Up till now, I'

Re: Getting around the lack of foreach in CTFE

2014-03-28 Thread Colin Grogan
On Friday, 28 March 2014 at 13:49:59 UTC, Dicebot wrote: On Friday, 28 March 2014 at 11:59:47 UTC, Colin Grogan wrote: I'm interested to hear peoples methods for getting around the lack of foreach loops while using CTFE? Currently, I've been using a lot of recursive templates, but its beginni

Re: Getting a class' name, but not fully qualified?

2014-03-28 Thread Dicebot
On Friday, 28 March 2014 at 13:28:00 UTC, Matt wrote: I haven't tried with deeper derived trees, but this seems to suggest that the .stringof property provides the class name, WITHOUT the full qualification. Those can't be really compared. .stringof provides string representation of anything a

Re: Waiting for a Spawn'ed process

2014-03-28 Thread Ali Çehreli
On 03/28/2014 10:19 AM, Sharad Gupta wrote: On Friday, 28 March 2014 at 16:37:00 UTC, Vladimir Panteleev wrote: On Friday, 28 March 2014 at 15:52:17 UTC, Sharad Gupta wrote: I am trying to make a Utility which spwans=>pipeShell off multiple processes on user choice. On of the issues is that so

Re: Waiting for a Spawn'ed process

2014-03-28 Thread Sharad Gupta
On Friday, 28 March 2014 at 16:37:00 UTC, Vladimir Panteleev wrote: On Friday, 28 March 2014 at 15:52:17 UTC, Sharad Gupta wrote: I am trying to make a Utility which spwans=>pipeShell off multiple processes on user choice. On of the issues is that some process need to wait for other processes

Re: Getting around the lack of foreach in CTFE

2014-03-28 Thread Adam D. Ruppe
On Friday, 28 March 2014 at 11:59:47 UTC, Colin Grogan wrote: I'm interested to hear peoples methods for getting around the lack of foreach loops while using CTFE? What, exactly are you trying to do? foreach does work in CTFE, though it will need to be wrapped in helper function that returns

Re: Waiting for a Spawn'ed process

2014-03-28 Thread Vladimir Panteleev
On Friday, 28 March 2014 at 15:52:17 UTC, Sharad Gupta wrote: I am trying to make a Utility which spwans=>pipeShell off multiple processes on user choice. On of the issues is that some process need to wait for other processes to finish. Now I could implement it using messages but that doesn't

Re: What is the correct function or cast to compare an unprintable ASCII character value to a string slice

2014-03-28 Thread bearophile
Gary Miller: if (MyString[0..1])== ???(219)) writeln("ASCII Block found") enum char block = 219; ... if (myString[i] == block) "ASCII Block found".writeln; Note that variable/function names in D start with a lower case. Bye, bearophile

What is the correct function or cast to compare an unprintable ASCII character value to a string slice

2014-03-28 Thread Gary Miller
If I need to examine a byte in string for a specific ASCII value like string MyString; MyString = "Hello World" and I want to check a position in the string for a certain unprintable ASCII value like the ASCII Block 219 what is the recommended method for doing so if (MyString[0..1])== ???(

Re: Iterate over an array while mutating it?

2014-03-28 Thread Regan Heath
On Thu, 27 Mar 2014 22:23:40 -, Anh Nhan wrote: Hey guys, I want to iterate over an array, while adding new entries, and have those in the iteration loop. See here: https://gist.github.com/AnhNhan/9820226 The problem is that the foreach loop seemingly only iterates over the original

Re: Getting a class' name, but not fully qualified?

2014-03-28 Thread w0rp
You could do the following. class Klass { static class SubKlass { } } string baseName(ClassInfo classinfo) { import std.array; import std.algorithm : countUntil; import std.range : retro; string qualName = classinfo.name; size_t dotIndex = qualName.retro.countUntil(

Re: Getting around the lack of foreach in CTFE

2014-03-28 Thread Dicebot
On Friday, 28 March 2014 at 11:59:47 UTC, Colin Grogan wrote: I'm interested to hear peoples methods for getting around the lack of foreach loops while using CTFE? Currently, I've been using a lot of recursive templates, but its beginning to give me a headache and I'd like to see if there's b

Re: Getting a class' name, but not fully qualified?

2014-03-28 Thread Matt
On Friday, 28 March 2014 at 11:28:09 UTC, JR wrote: On Thursday, 27 March 2014 at 17:41:14 UTC, Jeremy DeHaan wrote: typeof(this) gives its fully qualified name though. I was looking for a way to get just the name of the class alone. I guess I'm confused about what 'fully qualified name' entai

Re: Getting around the lack of foreach in CTFE

2014-03-28 Thread bearophile
Colin Grogan: Currently, I've been using a lot of recursive templates, but its beginning to give me a headache and I'd like to see if there's better ways around it. That's a good strategy. In some cases you can use Iota: https://d.puremagic.com/issues/show_bug.cgi?id=4085 On a related note

Re: Regarding the -vgc switch

2014-03-28 Thread bearophile
Kagamin: The phobos code is precompiled, so the compiler doesn't diagnose it. Right. So only allocations of templaes of Phobos can be detected. Bye, bearophile

Re: D project structure

2014-03-28 Thread Dejan Lekic
On Wednesday, 26 March 2014 at 16:13:15 UTC, Russel Winder wrote: Is it the case that the Dub recommended project structure is in fact the canonical D project structure? The Dub recommended structure doesn't mention test code as opposed to application/library source code, is it the case that t

Re: Regarding the -vgc switch

2014-03-28 Thread Kagamin
The phobos code is precompiled, so the compiler doesn't diagnose it.

Getting around the lack of foreach in CTFE

2014-03-28 Thread Colin Grogan
I'm interested to hear peoples methods for getting around the lack of foreach loops while using CTFE? Currently, I've been using a lot of recursive templates, but its beginning to give me a headache and I'd like to see if there's better ways around it. On a related note, is there plans to ad

Re: Why are compile-time constraints checked with an (inout int = 0) lambda in Phobos?

2014-03-28 Thread Andrej Mitrovic
On 3/27/14, Atila Neves wrote: > Why the (inout int = 0) instead of an empty parameter list? Try removing it and compile std.range with -unittest. Here's what happens: std\range.d(546): Error: static assert (isInputRange!(inout(int)[])) is false The reason it's false is because the code wouldn

Re: Getting a class' name, but not fully qualified?

2014-03-28 Thread JR
On Thursday, 27 March 2014 at 17:41:14 UTC, Jeremy DeHaan wrote: typeof(this) gives its fully qualified name though. I was looking for a way to get just the name of the class alone. I guess I'm confused about what 'fully qualified name' entails. For a class Foo, is "Foo" not just the name of t

Re: Why are compile-time constraints checked with an (inout int = 0) lambda in Phobos?

2014-03-28 Thread Dicebot
On Friday, 28 March 2014 at 11:17:10 UTC, Atila Neves wrote: Seriously, nobody? I'd've thought this was quite important. On Thursday, 27 March 2014 at 05:27:50 UTC, Atila Neves wrote: Why the (inout int = 0) instead of an empty parameter list? I checkout how isInputRange was implemented and I c

Re: Why are compile-time constraints checked with an (inout int = 0) lambda in Phobos?

2014-03-28 Thread Atila Neves
Seriously, nobody? I'd've thought this was quite important. On Thursday, 27 March 2014 at 05:27:50 UTC, Atila Neves wrote: Why the (inout int = 0) instead of an empty parameter list? I checkout how isInputRange was implemented and I copied the idiom, but I'd like to know why it's like that inst

Re: Iterate over an array while mutating it?

2014-03-28 Thread bearophile
Anh Nhan: Ah, that the foreach caches the entries would make sense. What does it mean "foreach caches the entries" for you? Foreach does very little. It is light syntax sugar over a normal for loop. Bye, bearophile

Re: Iterate over an array while mutating it?

2014-03-28 Thread Marc Schütz
On Thursday, 27 March 2014 at 22:23:41 UTC, Anh Nhan wrote: Hey guys, I want to iterate over an array, while adding new entries, and have those in the iteration loop. See here: https://gist.github.com/AnhNhan/9820226 The problem is that the foreach loop seemingly only iterates over the orig