Re: mixin template question

2015-04-11 Thread Paul D Anderson via Digitalmars-d-learn
On Sunday, 12 April 2015 at 04:04:43 UTC, lobo wrote: On Sunday, 12 April 2015 at 03:51:03 UTC, Paul D Anderson wrote: I don't understand why the following code compiles and runs without an error: import std.stdio; mixin template ABC(){ int abc() { return 3; } } mixin ABC; int abc() { retu

Re: stdout redirect

2015-04-11 Thread Philip Stuckey via Digitalmars-d-learn
On Thursday, 12 April 2012 at 08:11:58 UTC, Andrea Fontana wrote: On Wednesday, 11 April 2012 at 15:25:56 UTC, Stefan wrote: On Wednesday, 11 April 2012 at 13:00:45 UTC, Andrea Fontana wrote: On Wednesday, 11 April 2012 at 12:46:30 UTC, Andrea Fontana wrote: How can I redirect stdout / stderr t

Re: vibed - best approach to manage central state (cached records)

2015-04-11 Thread Laeeth Isharc via Digitalmars-d-learn
On Sunday, 12 April 2015 at 02:54:27 UTC, Rikki Cattermole wrote: On 12/04/2015 7:24 a.m., Laeeth Isharc wrote: Hi. Two questions: 1. On startup I load various indexes from file storage into memory in the shared static this segment, and I would like to access these from threads serving web r

Re: mixin template question

2015-04-11 Thread lobo via Digitalmars-d-learn
On Sunday, 12 April 2015 at 03:51:03 UTC, Paul D Anderson wrote: I don't understand why the following code compiles and runs without an error: import std.stdio; mixin template ABC(){ int abc() { return 3; } } mixin ABC; int abc() { return 4; } void main() { writefln("abc() = %s", abc())

mixin template question

2015-04-11 Thread Paul D Anderson via Digitalmars-d-learn
I don't understand why the following code compiles and runs without an error: import std.stdio; mixin template ABC(){ int abc() { return 3; } } mixin ABC; int abc() { return 4; } void main() { writefln("abc() = %s", abc()); } Doesn't the mixin ABC create a function with the same signatu

Re: D1: Out of memory problems

2015-04-11 Thread jicman via Digitalmars-d-learn
On Saturday, 11 April 2015 at 20:45:25 UTC, Kagamin wrote: Parsers unique duplicated strings via a name table: string udup(string s, ref string[string] nameTable) { if(s in nameTable)return nameTable[s]; string s1=s.dup; nameTable[s1]=s1; return s1; } This way you avoid extra duplicates.

Re: vibed - best approach to manage central state (cached records)

2015-04-11 Thread Rikki Cattermole via Digitalmars-d-learn
On 12/04/2015 7:24 a.m., Laeeth Isharc wrote: Hi. Two questions: 1. On startup I load various indexes from file storage into memory in the shared static this segment, and I would like to access these from threads serving web requests. The data can be considered immutable once loaded. What is

Re: seeking D wisdom

2015-04-11 Thread Rikki Cattermole via Digitalmars-d-learn
On 12/04/2015 2:22 a.m., John S wrote: On Saturday, 11 April 2015 at 03:27:32 UTC, Rikki Cattermole wrote: I'm currently writing a web server[0]. I do have a web service framework waiting for it. It is based upon my previous one (Cmsed). If you want to help with the web server, please let me kn

Re: Formatted output ranges

2015-04-11 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 11 April 2015 at 22:45:39 UTC, Dennis Ritchie wrote: I also want to know whether it is possible to D somehow set the maximum width of the print string in characters? I got to do this: - import std.stdio, std.range, std.conv, std.array; void formatWidthIotaToStr(ref string for

Re: D1: Out of memory problems

2015-04-11 Thread jicman via Digitalmars-d-learn
On Saturday, 11 April 2015 at 20:45:25 UTC, Kagamin wrote: Parsers unique duplicated strings via a name table: string udup(string s, ref string[string] nameTable) { if(s in nameTable)return nameTable[s]; string s1=s.dup; nameTable[s1]=s1; return s1; } This way you avoid extra duplicates.

Re: IMAP library

2015-04-11 Thread Laeeth Isharc via Digitalmars-d-learn
Need to have some way of manipulating email in D though. I agree. This would especially be cool, if you can do it from a small device like a microcontroller! Yes - nice to know it can do that also. For me I need to have a way of managing large amounts of email (I have about 2mm messages)

Re: Formatted output ranges

2015-04-11 Thread Dennis Ritchie via Digitalmars-d-learn
I also want to know whether it is possible to D somehow set the maximum width of the print string in characters? - void main() { import std.stdio, std.range; writefln(";; %(%s, %)).", iota(10, 1101)); } - For example, here's the code to Common Lisp which is given by the

Re: D1: Out of memory problems

2015-04-11 Thread Kagamin via Digitalmars-d-learn
Parsers unique duplicated strings via a name table: string udup(string s, ref string[string] nameTable) { if(s in nameTable)return nameTable[s]; string s1=s.dup; nameTable[s1]=s1; return s1; } This way you avoid extra duplicates. You can also try to free file content manually when it's p

Re: Formatted output ranges

2015-04-11 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 11 April 2015 at 20:37:17 UTC, anonymous wrote: On Saturday, 11 April 2015 at 20:10:49 UTC, Dennis Ritchie wrote: writefln("%(;; %(%s, %),\n%).", [ a[0 .. 15], a[15 .. 30], a[30 .. 45], a[45 .. 60],

Re: Formatted output ranges

2015-04-11 Thread anonymous via Digitalmars-d-learn
On Saturday, 11 April 2015 at 20:10:49 UTC, Dennis Ritchie wrote: writefln("%(;; %(%s, %),\n%).", [ a[0 .. 15], a[15 .. 30], a[30 .. 45], a[45 .. 60], a[60 .. 75], a[75 .. 90],

Re: Function name from function pointer

2015-04-11 Thread Paul D Anderson via Digitalmars-d-learn
On Saturday, 11 April 2015 at 19:08:50 UTC, Marco Leise wrote: Am Sat, 11 Apr 2015 18:28:35 + schrieb "Paul D Anderson" : Is there a way to return the name of a function (a string) from a pointer to that function? Function pointer example from D Reference: --- int function() fp; void tes

Formatted output ranges

2015-04-11 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Is it possible to write somehow shorter using formatted output and other library functions? - import std.stdio, std.range; void main() { auto a = iota(100, 201); writefln("%(;; %(%s, %),\n%).", [ a[0 .. 15], a[15 .. 30],

vibed - best approach to manage central state (cached records)

2015-04-11 Thread Laeeth Isharc via Digitalmars-d-learn
Hi. Two questions: 1. On startup I load various indexes from file storage into memory in the shared static this segment, and I would like to access these from threads serving web requests. The data can be considered immutable once loaded. What is the best way to make this data accessible?

Re: Function name from function pointer

2015-04-11 Thread bearophile via Digitalmars-d-learn
Paul D Anderson: Is there a way to return the name of a function (a string) from a pointer to that function? Perhaps creating a string[void*] AA and initializing with all the function pointers you care about. Bye, bearophile

Re: Function name from function pointer

2015-04-11 Thread Marco Leise via Digitalmars-d-learn
Am Sat, 11 Apr 2015 18:28:35 + schrieb "Paul D Anderson" : > Is there a way to return the name of a function (a string) from a > pointer to that function? > > Function pointer example from D Reference: > --- > int function() fp; > > void test() > { > static int a = 7; > static int

Function name from function pointer

2015-04-11 Thread Paul D Anderson via Digitalmars-d-learn
Is there a way to return the name of a function (a string) from a pointer to that function? Function pointer example from D Reference: --- int function() fp; void test() { static int a = 7; static int foo() { return a + 3; } fp = &foo; } void bar() { test(); int i = fp();

Re: D1: Out of memory problems

2015-04-11 Thread jicman via Digitalmars-d-learn
On Friday, 10 April 2015 at 13:47:52 UTC, Kagamin wrote: On Tuesday, 7 April 2015 at 15:28:21 UTC, jicman wrote: H... Will you be able to give me an example of what is bad and then fix that bad to a good? This may be my problem... maybe aTUs = AddToTrackerRepeat(aTUs, source.dup, fn, 1, t

Re: seeking D wisdom

2015-04-11 Thread John S via Digitalmars-d-learn
On Saturday, 11 April 2015 at 03:27:32 UTC, Rikki Cattermole wrote: I'm currently writing a web server[0]. I do have a web service framework waiting for it. It is based upon my previous one (Cmsed). If you want to help with the web server, please let me know. The configuration system still is

Re: Why is indexed foreach restricted to build in array ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
On Saturday, 11 April 2015 at 14:01:07 UTC, John Colvin wrote: What OS are you on? Ubuntu 14.10.

Re: Why is indexed foreach restricted to build in array ?

2015-04-11 Thread John Colvin via Digitalmars-d-learn
On Saturday, 11 April 2015 at 12:04:06 UTC, matovitch wrote: On Saturday, 11 April 2015 at 11:24:32 UTC, John Colvin wrote: On Saturday, 11 April 2015 at 11:03:28 UTC, matovitch wrote: On Saturday, 11 April 2015 at 10:53:46 UTC, Jakob Ovrum wrote: On Saturday, 11 April 2015 at 10:50:17 UTC, ma

Re: Make a type tuple from an array

2015-04-11 Thread Artur Skawina via Digitalmars-d-learn
On 04/10/15 17:36, John Colvin via Digitalmars-d-learn wrote: > On Friday, 10 April 2015 at 15:13:54 UTC, Marc Schütz wrote: >> Is there a way to turn an array (known at compile time) into a TypeTuple? > For input ranges in general: > > import std.range : isInputRange; > > template TypeTupleOf(

Re: Why is indexed foreach restricted to build in array ?

2015-04-11 Thread Jakob Ovrum via Digitalmars-d-learn
On Saturday, 11 April 2015 at 12:04:06 UTC, matovitch wrote: well ldc doesn't compile : kmeans.d(40): Error: no property 'enumerate' for type 'Range' With -O -release -inline I get around 2s with foreach and 0.5s with a simple for. LDC does not yet support the 2.067 front-end version in whi

Re: Why is indexed foreach restricted to build in array ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
On Saturday, 11 April 2015 at 11:24:32 UTC, John Colvin wrote: On Saturday, 11 April 2015 at 11:03:28 UTC, matovitch wrote: On Saturday, 11 April 2015 at 10:53:46 UTC, Jakob Ovrum wrote: On Saturday, 11 April 2015 at 10:50:17 UTC, matovitch wrote: Hello, The question is in the title. It shoul

Re: Why is indexed foreach restricted to build in array ?

2015-04-11 Thread John Colvin via Digitalmars-d-learn
On Saturday, 11 April 2015 at 11:03:28 UTC, matovitch wrote: On Saturday, 11 April 2015 at 10:53:46 UTC, Jakob Ovrum wrote: On Saturday, 11 April 2015 at 10:50:17 UTC, matovitch wrote: Hello, The question is in the title. It should be possible for a finite random access ranges to perform an i

Re: Why is indexed foreach restricted to build in array ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
On Saturday, 11 April 2015 at 10:53:46 UTC, Jakob Ovrum wrote: On Saturday, 11 April 2015 at 10:50:17 UTC, matovitch wrote: Hello, The question is in the title. It should be possible for a finite random access ranges to perform an indexed foreach no ? I mean like : foreach(size_t i = 0, aut

Why is indexed foreach restricted to build in array ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
Hello, The question is in the title. It should be possible for a finite random access ranges to perform an indexed foreach no ? I mean like : foreach(size_t i = 0, auto ref x; R) { /*...*/ } Why are other foreach statements overloadable but this one ? Thanks in advance.

Re: Why is indexed foreach restricted to build in array ?

2015-04-11 Thread Jakob Ovrum via Digitalmars-d-learn
On Saturday, 11 April 2015 at 10:50:17 UTC, matovitch wrote: Hello, The question is in the title. It should be possible for a finite random access ranges to perform an indexed foreach no ? I mean like : foreach(size_t i = 0, auto ref x; R) { /*...*/ } Why are other foreach statements ov

Re: Auto ref function : How is this possible ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
In fact I am now thinking it's great...I tried with string instead of float and got a clear error message. I should have read the spec more thoroughly.

Re: Auto ref function : How is this possible ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
Ok this explain it : http://dlang.org/function.html#auto-functions. It should return a float.

Re: Make a type tuple from an array

2015-04-11 Thread John Colvin via Digitalmars-d-learn
On Saturday, 11 April 2015 at 09:23:11 UTC, Dicebot wrote: On Saturday, 11 April 2015 at 09:05:19 UTC, Nordlöw wrote: On Saturday, 11 April 2015 at 07:18:26 UTC, John Colvin wrote: Why not use isStaticArray instead of isInputRange here? Because that would be completely different. Static array

Re: Auto ref function : How is this possible ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
(you can remove the ref stuff)

Auto ref function : How is this possible ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
Hi, I just learn about auto ref functions and tried this : import std.stdio; auto ref foo(int i, ref float f) { if (i < f) { return i; } else { return f; } } void main() { int i = 1; float f1 = 1.

Re: Make a type tuple from an array

2015-04-11 Thread Dicebot via Digitalmars-d-learn
On Saturday, 11 April 2015 at 09:05:19 UTC, Nordlöw wrote: On Saturday, 11 April 2015 at 07:18:26 UTC, John Colvin wrote: Why not use isStaticArray instead of isInputRange here? Because that would be completely different. Static arrays aren't even input ranges... Ahh, my mistake. Could som

Re: Make a type tuple from an array

2015-04-11 Thread Nordlöw
On Saturday, 11 April 2015 at 07:18:26 UTC, John Colvin wrote: Why not use isStaticArray instead of isInputRange here? Because that would be completely different. Static arrays aren't even input ranges... Ahh, my mistake. Could somebody explain when this feature is needed?

Re: Make a type tuple from an array

2015-04-11 Thread John Colvin via Digitalmars-d-learn
On Friday, 10 April 2015 at 22:55:23 UTC, Nordlöw wrote: On Friday, 10 April 2015 at 15:36:42 UTC, John Colvin wrote: if (TL.length == 1 && isInputRange!(typeof(TL[0]))) Why not use isStaticArray instead of isInputRange here? Because that would be completely different. Static arrays aren'