Re: Random D geekout

2012-04-22 Thread Nick Sabalausky
"H. S. Teoh" wrote in message news:mailman.2061.1335131543.4860.digitalmar...@puremagic.com... > > It's my fault. I really should be using module globals for those > regexes, and a module ctor (static this) for initializing them. > In most cases, I've come to prefer lazy initalization (via a mod

Re: Random D geekout

2012-04-22 Thread H. S. Teoh
On Sun, Apr 22, 2012 at 12:31:16PM +0200, SomeDude wrote: > On Saturday, 21 April 2012 at 14:40:00 UTC, H. S. Teoh wrote: [...] > >Hmph. I should've checked dmd memory usage when I wrote that. :-( > > > >But anyway, even on my souped up AMD hexacore system, the ctRegex > >version takes significantl

Re: Random D geekout

2012-04-22 Thread SomeDude
On Saturday, 21 April 2012 at 14:40:00 UTC, H. S. Teoh wrote: On Sat, Apr 21, 2012 at 03:12:05PM +0400, Dmitry Olshansky wrote: On 21.04.2012 14:48, SomeDude wrote: >On Saturday, 21 April 2012 at 10:21:49 UTC, Dmitry Olshansky >wrote: >>Just stop using ctRegex for now... it's experimental. >>

Re: Random D geekout

2012-04-21 Thread H. S. Teoh
On Sat, Apr 21, 2012 at 06:17:58PM +0200, nhk wrote: > Please bear with my ignorance I'm new to D, but why is that any > better compared to a simple > > switch(key){ > default: throw Exception("Invalid attribute '%s'".format(key)); > case "name": d.name = value; >break; > ... > ...

Re: Random D geekout

2012-04-21 Thread Jakob Ovrum
On Saturday, 21 April 2012 at 14:40:00 UTC, H. S. Teoh wrote: I'm getting confused about the use of 'static' in this context. What I wanted was to make the regex module-global, but apparently 'static' has an overloaded meaning here, and also makes it compile-time evaluated? How do I make it mod

Re: Random D geekout

2012-04-21 Thread Dmitry Olshansky
On 21.04.2012 18:41, H. S. Teoh wrote: [snip] How do I make it module-global without being compile-time evaluated?? No idea ;) But as a workaround: Global blah; static this(){ blah = ...; } -- Dmitry Olshansky

Re: Random D geekout

2012-04-21 Thread nhk
Please bear with my ignorance I'm new to D, but why is that any better compared to a simple switch(key){ default: throw Exception("Invalid attribute '%s'".format(key)); case "name": d.name = value; break; ... ... } On Friday, 20 April 2012 at 04:05:43 UTC, H. S. Teoh wrote: I'm

Re: Random D geekout

2012-04-21 Thread Jacob Carlborg
On 2012-04-20 20:50, Arne wrote: auto dgs = [ "name": (string value) {d.name = value; }, "phone": (string value) => cast(void)(d.phone = value), "age": (string value) => cast(void)(d.age = value.to!int()), ]; This works... is there a better way, to avoid cast? You could try explicitly declare

Re: Random D geekout

2012-04-21 Thread H. S. Teoh
On Sat, Apr 21, 2012 at 03:12:05PM +0400, Dmitry Olshansky wrote: > On 21.04.2012 14:48, SomeDude wrote: > >On Saturday, 21 April 2012 at 10:21:49 UTC, Dmitry Olshansky wrote: > >>Just stop using ctRegex for now... it's experimental. > >> > >>Or more to the point the problem is this. I've seen this

Re: Random D geekout

2012-04-21 Thread Dmitry Olshansky
On 21.04.2012 14:48, SomeDude wrote: On Saturday, 21 April 2012 at 10:21:49 UTC, Dmitry Olshansky wrote: Just stop using ctRegex for now... it's experimental. Or more to the point the problem is this. I've seen this one on bugzilla: version(CtRgx) { enum Re = ctRegex!re;//auto is OK here BTW }

Re: Random D geekout

2012-04-21 Thread SomeDude
On Saturday, 21 April 2012 at 10:21:49 UTC, Dmitry Olshansky wrote: Just stop using ctRegex for now... it's experimental. Or more to the point the problem is this. I've seen this one on bugzilla: version(CtRgx) { enum Re = ctRegex!re;//auto is OK here BTW } else {//tha

Re: Random D geekout

2012-04-21 Thread Dmitry Olshansky
On 21.04.2012 11:46, SomeDude wrote: I can't compile it. I get "Out of memory". Is it the regex.d module again ?:( This one really needs to be fixed ASAP, as the older working Ah-ha-ha. OK, come on use it the source are out there in the open :) It didn't even handle * properly. regexp is dep

Re: Random D geekout

2012-04-21 Thread Arne
On Friday, 20 April 2012 at 19:00:29 UTC, Nick Sabalausky wrote: "Arne" wrote in message news:qmehxgyksrdxkabvc...@forum.dlang.org... auto dgs = [ "name": (string value) {d.name = value; }, "phone": (string value) => cast(void)(d.phone = value), "age": (string value) => cast(void)(d.a

Re: Random D geekout

2012-04-21 Thread SomeDude
I can't compile it. I get "Out of memory". Is it the regex.d module again ?:( This one really needs to be fixed ASAP, as the older working regexp is deprecated.

Re: Random D geekout

2012-04-20 Thread H. S. Teoh
On Fri, Apr 20, 2012 at 04:25:30PM +0200, ixid wrote: > As a D learner this thread is very interesting. It would be great to > maintain it with a polished and error catching version that > incorporates people's tweaks. What I posted was a pared-down simplified version of the actual code I was work

Re: Random D geekout

2012-04-20 Thread Nick Sabalausky
"Arne" wrote in message news:qmehxgyksrdxkabvc...@forum.dlang.org... > > auto dgs = > [ > "name": (string value) {d.name = value; }, > "phone": (string value) => cast(void)(d.phone = value), > "age": (string value) => cast(void)(d.age = value.to!int()), > ]; > > This works... is there

Re: Random D geekout

2012-04-20 Thread Ali Çehreli
On 04/20/2012 11:50 AM, Arne wrote: On Friday, 20 April 2012 at 11:23:49 UTC, Steven Schveighoffer wrote: On Fri, 20 Apr 2012 00:06:41 -0400, H. S. Teoh wrote: The only complaint is that I couldn't write auto[string] dgs and have the compiler auto-infer the delegate type. :-) Does this not

Re: Random D geekout

2012-04-20 Thread Arne
On Friday, 20 April 2012 at 11:23:49 UTC, Steven Schveighoffer wrote: On Fri, 20 Apr 2012 00:06:41 -0400, H. S. Teoh wrote: The only complaint is that I couldn't write auto[string] dgs and have the compiler auto-infer the delegate type. :-) Does this not work? auto dgs = ... Also, it do

Re: Random D geekout

2012-04-20 Thread ixid
As a D learner this thread is very interesting. It would be great to maintain it with a polished and error catching version that incorporates people's tweaks.

Re: Random D geekout

2012-04-20 Thread Steven Schveighoffer
On Fri, 20 Apr 2012 00:06:41 -0400, H. S. Teoh wrote: The only complaint is that I couldn't write auto[string] dgs and have the compiler auto-infer the delegate type. :-) Does this not work? auto dgs = ... Also, it doesn't look like that needs to be in the inner loop. Each time you sp

Re: Random D geekout

2012-04-20 Thread Jacob Carlborg
On 2012-04-20 06:06, H. S. Teoh wrote: I'm writing some code that does some very simplistic parsing, and I'm just totally geeking out on how awesome D is for writing such code: import std.conv; import std.regex; import std.stdio; struct Data { str

Re: Random D geekout

2012-04-19 Thread Dmitry Olshansky
On 20.04.2012 8:44, Denis Shelomovskij wrote: 20.04.2012 8:06, H. S. Teoh написал: I'm writing some code that does some very simplistic parsing, and I'm just totally geeking out on how awesome D is for writing such code: import std.conv; import std.regex; import std.stdio; struct Data { string

Re: Random D geekout

2012-04-19 Thread Dmitry Olshansky
On 20.04.2012 9:19, F i L wrote: Denis Shelomovskij wrote: A shorter variant: --- void delegate(string, string)[string] dgs = [ "name" : (key, value) { d.name = value; }, "phone": (key, value) { d.phone = value; }, "age" : (key, value) { d.age = to!int(value); }, ... // whole bunch of other stuf

Re: Random D geekout

2012-04-19 Thread Ary Manzana
On 4/20/12 1:09 PM, H. S. Teoh wrote: On Fri, Apr 20, 2012 at 08:44:06AM +0400, Denis Shelomovskij wrote: 20.04.2012 8:06, H. S. Teoh написал: I'm writing some code that does some very simplistic parsing, and I'm just totally geeking out on how awesome D is for writing such code: impor

Re: Random D geekout

2012-04-19 Thread F i L
Denis Shelomovskij wrote: A shorter variant: --- void delegate(string, string)[string] dgs = [ "name" : (key, value) { d.name = value; }, "phone": (key, value) { d.phone = value; }, "age" : (key, value) { d.age = to!int(value); }, ... // whole bunch of other s

Re: Random D geekout

2012-04-19 Thread F i L
Denis Shelomovskij wrote: A shorter variant: --- void delegate(string, string)[string] dgs = [ "name" : (key, value) { d.name = value; }, "phone": (key, value) { d.phone = value; }, "age" : (key, value) { d.age = to!int(value); }, ... // whole bunch of other s

Re: Random D geekout

2012-04-19 Thread Nick Sabalausky
"H. S. Teoh" wrote in message news:mailman.1957.1334898572.4860.digitalmar...@puremagic.com... > > Good idea, I really need to work on my delegate syntax. I must admit I > still have to look it up each time, 'cos I just can't remember the right > syntax with all its shorthands thereof. > Heh, I

Re: Random D geekout

2012-04-19 Thread H. S. Teoh
On Fri, Apr 20, 2012 at 08:44:06AM +0400, Denis Shelomovskij wrote: > 20.04.2012 8:06, H. S. Teoh написал: > >I'm writing some code that does some very simplistic parsing, and I'm > >just totally geeking out on how awesome D is for writing such code: > > > > import std.conv; > > import std.

Re: Random D geekout

2012-04-19 Thread Denis Shelomovskij
20.04.2012 8:06, H. S. Teoh написал: I'm writing some code that does some very simplistic parsing, and I'm just totally geeking out on how awesome D is for writing such code: import std.conv; import std.regex; import std.stdio; struct Data { strin

Re: Random D geekout

2012-04-19 Thread Nick Sabalausky
"H. S. Teoh" wrote in message news:mailman.1953.1334894800.4860.digitalmar...@puremagic.com... > I'm writing some code that does some very simplistic parsing, and I'm > just totally geeking out on how awesome D is for writing such code: > Heh, yup :) I grew up on C/C++ (well, after outgrowing B

Random D geekout

2012-04-19 Thread H. S. Teoh
I'm writing some code that does some very simplistic parsing, and I'm just totally geeking out on how awesome D is for writing such code: import std.conv; import std.regex; import std.stdio; struct Data { string name; string phone;