Re: typeof(string.front) should be char

2012-03-02 Thread Ali Çehreli
On 03/02/2012 06:30 PM, Piotr Szturmaj wrote: > Hello, > > For this code: > > auto c = "test"c; > auto w = "test"w; > auto d = "test"d; > pragma(msg, typeof(c.front)); > pragma(msg, typeof(w.front)); > pragma(msg, typeof(d.front)); > > compiler prints: > > dchar > dchar > immutable(dchar) > > IMO

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread H. S. Teoh
On Sat, Mar 03, 2012 at 03:33:46AM +0100, Adam D. Ruppe wrote: > On Saturday, 3 March 2012 at 02:19:55 UTC, Andrej Mitrovic wrote: > >Right, but what about template bloat? > > You don't have to use templates at all. The __FILE__ > and __LINE__ default params work in regular functions. > >

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread Andrej Mitrovic
Ah yeah, I forgot about those. int opIndex(int x, int line = __LINE__, string file = __FILE__) Tada. I overcomplicated.

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread Adam D. Ruppe
On Saturday, 3 March 2012 at 02:19:55 UTC, Andrej Mitrovic wrote: Right, but what about template bloat? You don't have to use templates at all. The __FILE__ and __LINE__ default params work in regular functions. // not a template, just regular parameters void awesome(string file =

typeof(string.front) should be char

2012-03-02 Thread Piotr Szturmaj
Hello, For this code: auto c = "test"c; auto w = "test"w; auto d = "test"d; pragma(msg, typeof(c.front)); pragma(msg, typeof(w.front)); pragma(msg, typeof(d.front)); compiler prints: dchar dchar immutable(dchar) IMO it should print this: immutable(char) immutable(wcha

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread Andrej Mitrovic
On 3/3/12, Adam D. Ruppe wrote: > Since some time last year, it works on all functions, just > use regular default parameters: Right, but what about template bloat? DMD doesn't seem to merge these templates. It can try to inline them, but it's very easy to break the inliner. E.g.: int myFunc(str

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread Adam D. Ruppe
On Saturday, 3 March 2012 at 01:46:05 UTC, Andrej Mitrovic wrote: Well, there is a way but it might wreak havoc on your object size since it will instantiate a lot of templates. Since some time last year, it works on all functions, just use regular default parameters: // test9.d import std.st

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread Andrej Mitrovic
Ok this works: http://paste.pocoo.org/show/560103/

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread Andrej Mitrovic
Err wait a minute, that debug/else thing doesn't quite work well.. I thought it would.

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread Andrej Mitrovic
On 3/3/12, Andrej Mitrovic wrote: > throw new Exception(format("%s: %s", file, line)); That format is unnecessary but anywho. :)

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread Andrej Mitrovic
Well, there is a way but it might wreak havoc on your object size since it will instantiate a lot of templates. Therefore it would be a good thing to only do it in debug mode: import std.string; class A { int opIndexDebug(int line = __LINE__, string file = __FILE__)(int x) { /* do

Re: Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread Adam D. Ruppe
On Saturday, 3 March 2012 at 01:36:51 UTC, H. S. Teoh wrote: int opIndex(int x) { Make that (int x, string file = __FILE__, int line = __LINE__) and use file/line in there. The exception consturctors do this, so you can throw new Exception("msg", file, line); and get it pass

Evaluating __FILE__ and __LINE__ of caller?

2012-03-02 Thread H. S. Teoh
Is it possible to get at the file and line number of where a function is being called from? For example: class A { int opIndex(int x) { /* do a bunch of checks */ if (checkFailed) throw new Rang

Re: Read csv data into a struct

2012-03-02 Thread Jesse Phillips
On Saturday, 3 March 2012 at 00:03:02 UTC, Yao Gomez wrote: On Friday, 2 March 2012 at 22:56:49 UTC, tjb wrote: Ali, Thanks. That helps me see how to use a structure. I just need to figure out the date and time conversion. Thanks! TJB I don't remember who did it or where is located, but

Re: Read csv data into a struct

2012-03-02 Thread Yao Gomez
On Friday, 2 March 2012 at 22:56:49 UTC, tjb wrote: Ali, Thanks. That helps me see how to use a structure. I just need to figure out the date and time conversion. Thanks! TJB I don't remember who did it or where is located, but there's actually a project/code that can be used for conver

Re: Read csv data into a struct

2012-03-02 Thread tjb
Ali, Thanks. That helps me see how to use a structure. I just need to figure out the date and time conversion. Thanks! TJB

Re: Read csv data into a struct

2012-03-02 Thread Ali Çehreli
On 03/02/2012 02:01 PM, Yao Gomez wrote: On Friday, 2 March 2012 at 21:50:12 UTC, tjb wrote: Woops. I have a mistake in the code. Should be: import std.stdio : writeln; import std.stream; void main() { auto fin = new File("temp.csv"); char[] line; int count; while(!fin.eof()) { line = fin.rea

Re: Read csv data into a struct

2012-03-02 Thread tjb
Yao, Thanks. That looks perfect. I'll play with it until I figure it out. Any suggestions for the date and time variables? Thanks again! TJB

Re: Read csv data into a struct

2012-03-02 Thread Yao Gomez
On Friday, 2 March 2012 at 21:50:12 UTC, tjb wrote: Woops. I have a mistake in the code. Should be: import std.stdio : writeln; import std.stream; void main() { auto fin = new File("temp.csv"); char[] line; int count; while(!fin.eof()) { line = fin.readLine(); writeln(line);

Re: Read csv data into a struct

2012-03-02 Thread tjb
Woops. I have a mistake in the code. Should be: import std.stdio : writeln; import std.stream; void main() { auto fin = new File("temp.csv"); char[] line; int count; while(!fin.eof()) { line = fin.readLine(); writeln(line); } } Thanks! TJB

Read csv data into a struct

2012-03-02 Thread tjb
Hello, I am trying to read some data from a csv file into a struct. I'm just learning to use D. This little bit of code reads the data and prints to standard output just fine: import std.stdio : writeln; import std.stream; void main() { auto fin = new File("temp.csv"); char[] line; in

Re: How to indicate that a memory block contains no GC pointers?

2012-03-02 Thread Alex Rønne Petersen
On 02-03-2012 21:54, Ali Çehreli wrote: On 03/02/2012 12:48 PM, Alex Rønne Petersen wrote: Hi, Is there any way I can tell the GC that a block of memory does not contain any possible pointers (in)to other GC-managed memory? Everything about the GC should be in the core.memory module. I think

Re: Define .empty property for hashes?

2012-03-02 Thread Ali Çehreli
On 03/02/2012 01:08 PM, Andrej Mitrovic wrote: > Is there a reason why there's no .empty property for hashes? std.array > defines it for arrays, and range types must have it defined. Yes, empty is a part of the InputRange interface. Slices are InputRange ranges but associative arrays are not. Un

Define .empty property for hashes?

2012-03-02 Thread Andrej Mitrovic
Is there a reason why there's no .empty property for hashes? std.array defines it for arrays, and range types must have it defined. But hashes are left out even though they define .length. This could be put in std.array: @property bool empty(T)(in T a) if (isAssociativeArray!T) { return !a

Re: How to indicate that a memory block contains no GC pointers?

2012-03-02 Thread Ali Çehreli
On 03/02/2012 12:48 PM, Alex Rønne Petersen wrote: Hi, Is there any way I can tell the GC that a block of memory does not contain any possible pointers (in)to other GC-managed memory? Everything about the GC should be in the core.memory module. I think what you need is removeRange(). Or you

How to indicate that a memory block contains no GC pointers?

2012-03-02 Thread Alex Rønne Petersen
Hi, Is there any way I can tell the GC that a block of memory does not contain any possible pointers (in)to other GC-managed memory? -- - Alex

Re: Dumb question about git

2012-03-02 Thread Graham Fawcett
On Fri, 02 Mar 2012 20:30:07 +0100, David Nadlinger wrote: > On Friday, 2 March 2012 at 18:10:56 UTC, Jonathan M Davis wrote: >> Both should work, and the man page is going to be for git-rebase. >> Pretty much >> all of the git commands can be used with or without a -. > > On my system, the dashe

QR code based twitter --slightly OT

2012-03-02 Thread bls
Twitter messages are pretty limited, so I think it could make sense to implement a QR code based twitter like information-service. D could be the tool of choice, But does this idea makes sense at all ? I Think so, but would like to hear your opinion. TIA Bjoern

Re: Dumb question about git

2012-03-02 Thread David Nadlinger
On Friday, 2 March 2012 at 18:10:56 UTC, Jonathan M Davis wrote: Both should work, and the man page is going to be for git-rebase. Pretty much all of the git commands can be used with or without a -. On my system, the dashed commands are not directly accessible, and the man page exclusively u

Re: Dumb question about git

2012-03-02 Thread Jonathan M Davis
On Friday, March 02, 2012 14:47:00 Graham Fawcett wrote: > On Thu, 01 Mar 2012 17:16:59 -0500, Jonathan M Davis wrote: > > If you make changes in a branch and want them on top of what's in > > master, then do > > > > git-rebase master > > While "git-rebase" may be available on your system, I thin

Re: Dumb question about git

2012-03-02 Thread Graham Fawcett
On Thu, 01 Mar 2012 17:16:59 -0500, Jonathan M Davis wrote: > > If you make changes in a branch and want them on top of what's in > master, then do > > git-rebase master While "git-rebase" may be available on your system, I think the typical spelling would be git rebase master Graham > in

Re: Char * character and string

2012-03-02 Thread Andrej Mitrovic
SDL_LoadBMP is declared as: SDL_Surface *SDL_LoadBMP(const char *file); http://www.libsdl.org/cgi/docwiki.cgi/SDL_LoadBMP So you don't need a mutable char*. I'd recommend using Derelict since it already has all these prototypes declared properly.

Re: Getting the mutable version of a type

2012-03-02 Thread Magnus Lie Hetland
On 2012-03-02 11:23:20 +, Ali Çehreli said: On 03/02/2012 02:18 AM, Magnus Lie Hetland wrote: I'm writing a template for generating data of some possibly immutable type -- e.g., a string. What I'm wondering is, is there some way of accessing the mutable version of an immutable type? Yes,

Re: Using lazily ?

2012-03-02 Thread Timon Gehr
On 03/02/2012 12:12 AM, bearophile wrote: Ali: Note that Timon's inner foreach is a compile-time foreach, which is the equivalent of the following three lines: I'd like it to be written: static foreach (...) {... In the meantime an annotation helps clarify the code for the person that will

Re: Getting the mutable version of a type

2012-03-02 Thread Ali Çehreli
On 03/02/2012 02:18 AM, Magnus Lie Hetland wrote: I'm writing a template for generating data of some possibly immutable type -- e.g., a string. What I'm wondering is, is there some way of accessing the mutable version of an immutable type? Yes, std.traits.Unqual: http://dlang.org/phobos/std_

Getting the mutable version of a type

2012-03-02 Thread Magnus Lie Hetland
I'm writing a template for generating data of some possibly immutable type -- e.g., a string. What I'm wondering is, is there some way of accessing the mutable version of an immutable type? I mean, I could do something like (for strings and related immutable arrays)... void func(T)(ref immutab

Re: Cocoa bindings?

2012-03-02 Thread Jacob Carlborg
On 2012-03-02 07:40, James Miller wrote: On 2 March 2012 18:52, Alex Rønne Petersen wrote: Hi, Are there any actively-maintained Cocoa bindings for D? -- - Alex Not as far as I know. You should make some! -- James Miller Bindings and bridge: http://www.dsource.org/projects/dstep The b

Re: Should uniform(-real.max, real.max) be inf?

2012-03-02 Thread Magnus Lie Hetland
On 2012-03-01 16:34:23 +, Ali Çehreli said: Since there are also sub-normal values between 0 and T.min_normal, it may make sense to use the range [T.min_normal, 1) and scale the result from there. But I haven't tested whether the distinct values in that range are equally distributed. I g

Re: Should uniform(-real.max, real.max) be inf?

2012-03-02 Thread Magnus Lie Hetland
On 2012-03-01 16:34:23 +, Ali Çehreli said: I recommend reading this page: http://dlang.org/d-floating-point.html Thanks. Especially the ASCII graph there is very interesting. The number of distinct values between T.min_normal and 1 are equal to the distinct values between 1 and T.