Re: Cocoa bindings?
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
Re: Char * character and string
Ok, got it all sorted. Thank you for the guidance.
Re: Char * character and string
On Friday, March 02, 2012 06:22:41 Chris Pons wrote: > Thank you for the reply. However, I've run into another problem. > > I changed: > > --- > > char * file; > > this() > { > this.filename = "test.bmp"; > } > > --- > > To: > > > > char * file > > this() > { > this.filename = toStringz("test.bmp"); > } > > --- > > I am getting this error: > > Error 1 Error: cannot implicitly convert expression > (toStringz("test.bmp")) of type immutable(char)* to > char* D:\Documents\Projects\Test\Test\DPBall.d10 > > Instead I tried toUTFz, which I used like this: > > -- > > char * filename; > > this() > { > this.filename = toUTFz("test.bmp"); > } > > -- > > I get these errors: > > Error 1 Error: template std.utf.toUTFz(P,S) if (isSomeString!(S) > && isPointer!(P) && isSomeChar!(typeof(*P.init)) && > is(Unqual!(typeof(*P.init)) == Unqual!(ElementEncodingType!(S))) > && is(immutable(Unqual!(ElementEncodingType!(S))) == > ElementEncodingType!(S))) does not match any function template > declaration D:\Documents\Projects\Test\Test\DPBall.d11 > > Error 2 Error: template std.utf.toUTFz(P,S) if (isSomeString!(S) > && isPointer!(P) && isSomeChar!(typeof(*P.init)) && > is(Unqual!(typeof(*P.init)) == Unqual!(ElementEncodingType!(S))) > && is(immutable(Unqual!(ElementEncodingType!(S))) == > ElementEncodingType!(S))) cannot deduce template function from > argument types > !()(string) D:\Documents\Projects\Test\Test\DPBall.d11 > > > Am I using these functions incorrectly? toStringz returns an immutable(char)*, so you can assign it to a const(char)* or an immutable(char)* but not a char*. If you want to assign to a char*, then you need to use toUTFz, which you are most definitely using incorrectly. The documentation gives several examples on how to use it correctly, but if what you want is a char*, then you'd do this.filename = toUTFz!(char*)("test.bmp"); toUTFZ is a templated function which requires that you give it the type that you want to convert to. You were trying to call it without giving the type. - Jonathan M Davis
Cocoa bindings?
Hi, Are there any actively-maintained Cocoa bindings for D? -- - Alex
Re: Char * character and string
Thank you for the reply. However, I've run into another problem. I changed: --- char * file; this() { this.filename = "test.bmp"; } --- To: char * file this() { this.filename = toStringz("test.bmp"); } --- I am getting this error: Error 1 Error: cannot implicitly convert expression (toStringz("test.bmp")) of type immutable(char)* to char* D:\Documents\Projects\Test\Test\DPBall.d 10 Instead I tried toUTFz, which I used like this: -- char * filename; this() { this.filename = toUTFz("test.bmp"); } -- I get these errors: Error 1 Error: template std.utf.toUTFz(P,S) if (isSomeString!(S) && isPointer!(P) && isSomeChar!(typeof(*P.init)) && is(Unqual!(typeof(*P.init)) == Unqual!(ElementEncodingType!(S))) && is(immutable(Unqual!(ElementEncodingType!(S))) == ElementEncodingType!(S))) does not match any function template declaration D:\Documents\Projects\Test\Test\DPBall.d 11 Error 2 Error: template std.utf.toUTFz(P,S) if (isSomeString!(S) && isPointer!(P) && isSomeChar!(typeof(*P.init)) && is(Unqual!(typeof(*P.init)) == Unqual!(ElementEncodingType!(S))) && is(immutable(Unqual!(ElementEncodingType!(S))) == ElementEncodingType!(S))) cannot deduce template function from argument types !()(string) D:\Documents\Projects\Test\Test\DPBall.d 11 Am I using these functions incorrectly?
Re: Char * character and string
On Friday, March 02, 2012 05:51:14 Chris Pons wrote: > Hello, > I am trying to work with SDL and one of their functions takes a > char * file as a function a parameter. However, i'm running into > trouble how to actually set this variable in my constructor. > > I am getting a problem where if I use a pointer to a char and set > it as "test.bmp" I get an error stating "cannot implicitly > convert expression (file) of type string to char*. After that I > decided to try to set file to 'test.bmp' instead, and in that > case I get: "Unterminated character constant" . Although I am > familiar with what this error is referring to, I do not know how > to add a terminator in D. > > This is the function that I intend to use the filename in: > **Note the function LoadBMP is the one that REQUIRES a pointer to > a char > -- > SDL_Surface * Load(char * file) > { > SDL_Surface * Temp = null; > > if((Temp = SDL_LoadBMP(file)) == null) > return null; > > Surface = SDLDisplayFormat(Temp); > > SDL_FreeSurface(Temp); > > return Surface; > } > > > This is the constructor that is giving me the error: > -- > char * file; > > this() > { > this.filename = "test.bmp"; > } > - Use std.string.toStringz (or std.utf.toUTFz if immutable(char)* doesn't cut it). Regardless, be careful of passing char* to C code. Even if the C code keeps the pointer, it won't stop the GC from collecting it. The D code needs to have reference to it of some kind (though a pointer in your struct as you appeart to be doing should be plenty as long as an instance of the struct remains in the D code - as opposed to passing it to the C code and then not having it in the D code anymore, which would be no better than just passing the char* to the C code without keeping a reference to it). - Jonathan M Davis
Char * character and string
Hello, I am trying to work with SDL and one of their functions takes a char * file as a function a parameter. However, i'm running into trouble how to actually set this variable in my constructor. I am getting a problem where if I use a pointer to a char and set it as "test.bmp" I get an error stating "cannot implicitly convert expression (file) of type string to char*. After that I decided to try to set file to 'test.bmp' instead, and in that case I get: "Unterminated character constant" . Although I am familiar with what this error is referring to, I do not know how to add a terminator in D. This is the function that I intend to use the filename in: **Note the function LoadBMP is the one that REQUIRES a pointer to a char -- SDL_Surface * Load(char * file) { SDL_Surface * Temp = null; if((Temp = SDL_LoadBMP(file)) == null) return null; Surface = SDLDisplayFormat(Temp); SDL_FreeSurface(Temp); return Surface; } This is the constructor that is giving me the error: -- char * file; this() { this.filename = "test.bmp"; } -
Re: Dumb question about git
Unless you have an expectation that other people are already using the old version of your branch, just use 'git push blah -f' to overwrite the old version. It's not a big deal for patches and pull requests, but it would be a disaster if anyone did this to the master branch. "H. S. Teoh" wrote in message news:mailman.271.1330614611.24984.digitalmars-d-le...@puremagic.com... > OK, so I'm new to git, and I ran into this problem: > > - I forked druntime on github and made some changes in a branch > - Pushed the changes to the fork > - Pulled upstream commits to master > - Merged master with branch > - Ran git rebase master, so that my changes appear on top of the latest > upstream master. > - Tried to push branch to my fork, but now it complains that I have > non-fast-forward changes and rejects the push. > > What's the right thing to do here? Looks like I screwed up my branch > history. How do I fix it? > > Thanks! > > > T > > -- > Real Programmers use "cat > a.out".
Re: SysTime in a Struct
On Thursday, March 01, 2012 16:00:09 Ali Çehreli wrote: > On 03/01/2012 03:46 PM, albatroz wrote: > > Hi Ali, just tring to define a type that holds this information. It was > > just an attempt to create a type DateTime with the values from the known > > strings, I thought it was possible to create the definition directly in > > the Struct, with no need for an external function. > > edate and etime are strings that I will read in to the struct, but for > > operations with time and dates I need to create/define a DateTime type. > > From that description, it looks like you can hold edate etc. as members > and produce SysTime as needed. The following demonstrates how to convert > preEv to SysTime by opCast implicitly and by sys_time explicitly: > > import std.stdio; > import std.conv; > import std.datetime; > > struct preEv > { > string edate; //010112 > string etime; //00:00:00 > string etext; // > > SysTime opCast(T : SysTime)() const > { > return SysTime(DateTime( > Clock.currTime.year, > to!int(this.edate[2..4]), > to!int(this.edate[0..2]), > to!int(etime[0..2]), > to!int(etime[3..5]), > to!int(etime[6..8]))); > } > > SysTime sys_time() const @property > { > return to!SysTime(this); > } > } > > void main() > { > auto pe = preEv("010312", "15:53:00", "The event"); > > // Explicit conversion > auto st0 = to!SysTime(pe); > writeln(st0); > > // Casting > auto st1 = cast(SysTime)(pe); > writeln(st1); > > // As a property > auto st2 = pe.sys_time; > writeln(st2); > } > > If you think that you need to cache SysTime in the object itself, you > can do that for example in opCast. > > On the other hand, if all you need to store is SysTime and etext, then > you need to create SysTime in the constructor: > > import std.stdio; > import std.conv; > import std.datetime; > > struct preEv > { > SysTime time; > string etext; > > this (string edate, string etime, string etext) > { > this.time = SysTime(DateTime( > Clock.currTime.year, > to!int(edate[2..4]), > to!int(edate[0..2]), > to!int(etime[0..2]), > to!int(etime[3..5]), > to!int(etime[6..8]))); > this.etext = etext; > } > } > > void main() > { > auto pe = preEv("010312", "15:53:00", "The event"); > > writeln(pe.time); > } You know, you can create a TimeOfDay from "15:53:00" with TimeOfDay.fromISOExtString. That won't work with the date, since it's not in either the ISO or ISO Extended format, but it would work for the time. I'd also point out that currTime isn't a property (since it takes an optional TimeZone argument), so you really should be using parens when you call it. Otherwise, once property enforcement is enabled, your code won't compile. Also, you should use std.conv.to, not a cast, when converting, since std.conv.to now supports calling user-defined opCasts, and there's less risk of screwing up the cast if you use std.conv.to. So, defining an opCast is fine, but it should probably be used with std.conv.to rather than directly. - Jonathan M Davis
Re: SysTime in a Struct
On 03/01/2012 03:46 PM, albatroz wrote: > Hi Ali, just tring to define a type that holds this information. It was > just an attempt to create a type DateTime with the values from the known > strings, I thought it was possible to create the definition directly in > the Struct, with no need for an external function. > edate and etime are strings that I will read in to the struct, but for > operations with time and dates I need to create/define a DateTime type. From that description, it looks like you can hold edate etc. as members and produce SysTime as needed. The following demonstrates how to convert preEv to SysTime by opCast implicitly and by sys_time explicitly: import std.stdio; import std.conv; import std.datetime; struct preEv { string edate; //010112 string etime; //00:00:00 string etext; // SysTime opCast(T : SysTime)() const { return SysTime(DateTime( Clock.currTime.year, to!int(this.edate[2..4]), to!int(this.edate[0..2]), to!int(etime[0..2]), to!int(etime[3..5]), to!int(etime[6..8]))); } SysTime sys_time() const @property { return to!SysTime(this); } } void main() { auto pe = preEv("010312", "15:53:00", "The event"); // Explicit conversion auto st0 = to!SysTime(pe); writeln(st0); // Casting auto st1 = cast(SysTime)(pe); writeln(st1); // As a property auto st2 = pe.sys_time; writeln(st2); } If you think that you need to cache SysTime in the object itself, you can do that for example in opCast. On the other hand, if all you need to store is SysTime and etext, then you need to create SysTime in the constructor: import std.stdio; import std.conv; import std.datetime; struct preEv { SysTime time; string etext; this (string edate, string etime, string etext) { this.time = SysTime(DateTime( Clock.currTime.year, to!int(edate[2..4]), to!int(edate[0..2]), to!int(etime[0..2]), to!int(etime[3..5]), to!int(etime[6..8]))); this.etext = etext; } } void main() { auto pe = preEv("010312", "15:53:00", "The event"); writeln(pe.time); } Ali
Re: SysTime in a Struct
Are you trying to record the time when a prevEv is copied from another one? If not, I suggest not defining this(this). It is the postblit, to make things right for rare structs and only when the compiler generated copying is wrong for a that type. Or, are you just trying to define a type that contains time information? Hi Ali, just tring to define a type that holds this information. It was just an attempt to create a type DateTime with the values from the known strings, I thought it was possible to create the definition directly in the Struct, with no need for an external function. edate and etime are strings that I will read in to the struct, but for operations with time and dates I need to create/define a DateTime type. Thanks
Re: Using lazily ?
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 read the code: /*static*/ foreach (...) {... Bye, bearophile
Re: Regarding std.array.Appender
Am 01.03.2012 03:40, schrieb Jonathan M Davis: On Wednesday, February 29, 2012 21:23:54 bearophile wrote: Jonathan M Davis: put is a function on output ranges, and Appender is an output range. Also, given that it doesn't define ~ (and it wouldn't really make sense for it to), it would be very weird IMHO to define ~=. I don't understand why that's weird. In Java you can't overload an append operator, so using a method is right. But for me it's weird that Appender doesn't use the D operator to _append_. I sometimes use "add" instead of "put" by mistake, forgetting the right method name, because I find it quite unnatural. If Appender needs a put, then I suggest to give it both "put" method and "~=" operator. Would you define += without defining +? Or *= without defining *? It strikes me as a misuse of operator overloading if you have an opOpAssign without its corresponding opBinary. - Jonathan M Davis Consider matrix * vector and matrix *= vector for an opposite example.
Re: Using lazily ?
On 03/01/2012 02:25 PM, bioinfornatics wrote: > Le jeudi 01 mars 2012 à 23:10 +0100, Timon Gehr a écrit : >> S s; >> size_t tokenLength = "member1".length; >> void main(){ >> foreach(char[] line; stdin.byLine()) >> foreach(m;__traits(allMembers,S)){ >> if(line[0..tokenLength] == m) mixin("s."~m) = >> line[tokenLength >> .. $].idup; >> } >> } > > awesome :) > > can use hasMember instead allMembers ? No, because both of those are compile-time features. Even if you used hasMember, the answer will always be true: if (__traits(hasMember, S, "member1")) Yes, S has member1. Note that Timon's inner foreach is a compile-time foreach, which is the equivalent of the following three lines: if(line[0..tokenLength] == "member1") s.member1 = line[tokenLength .. $].idup; if(line[0..tokenLength] == "member2") s.member2 = line[tokenLength .. $].idup; if(line[0..tokenLength] == "member3") s.member3 = line[tokenLength .. $].idup; There is no inner foreach looop that is executed at runtime. Ali
Re: Using lazily ?
Le jeudi 01 mars 2012 à 23:10 +0100, Timon Gehr a écrit : > S s; > size_t tokenLength = "member1".length; > void main(){ > foreach(char[] line; stdin.byLine()) > foreach(m;__traits(allMembers,S)){ > if(line[0..tokenLength] == m) mixin("s."~m) = > line[tokenLength > .. $].idup; > } > } awesome :) can use hasMember instead allMembers ?
Re: SysTime in a Struct
On Thursday, March 01, 2012 15:15:00 albatroz wrote: > Hi, > > I have defined this struct > struct preEv { > string edate; //010112 > string etime; //00:00:00 > string etext; // > SysTime esystime; > this (this) { > SysTime esystime = SysTime(DateTime( > Clock.currTime.year, > to!int(this.edate[2..4]), > to!int(this.edate[0..2]), > to!int(etime[0..2]), > to!int(etime[3..5]), > to!int(etime[6..8]))); > } > } > > If I write to the sctruct and then print it I'm able to see the > SysTime variable with a value. > writeln(preEv) //previousEvents("140212", "05:13:26", "9 140212 > 05:13:26 d", "2012-Feb-14 05:13:26") > > but if trying to get the value from the SysTime variable I get a > Segmentation fault. Trying to read any other variable inside this > struct will not be a problem. > > writeln (preEv.esystime.day) // will compile but segfaults > > On DMD32 D Compiler v2.058 > > Any correct way to do this? A default-initialized SysTime is useless. It hasn't been properly initialized. SysTime contains a time zone object, which is a class and must be initialized at runtime (so directly initializing it won't work), and that object is null in SysTime.init (and it can't be anything else, because you can't construct a class at compile and have it persist to runtime). You need to actually initialize a SysTime before using it. So, using the init value of struct which has a SysTime as a member probably isn't a great idea. - Jonathan M Davis
Re: Dumb question about git
On Thursday, March 01, 2012 09:17:18 H. S. Teoh wrote: > On Thu, Mar 01, 2012 at 10:22:33AM -0500, Kevin Cox wrote: > > When people say git encourages rewriting history. Don't listen. Once > > you have pushed your changes to the world they are immutable. This is > > because git uses cryptography internally and changing the history > > messes everything up. If you haven't pushed you can change all of > > your history and it will all be fine. But if someone else (github) > > has the old hisory bad things happen. If you are sure nobody has > > pulled from github you can use --force when pushing (I think). It > > will work no matter what but you will piss off people if they have > > pulled from you. Please note that this kind of history modifying is > > considered bad practice. > > [...] > > OK, so what's the right way to do it then? I have some changes in a > branch, but master has been updated since, so I want to merge in the > latest updates so that the branch changes are compatible with the latest > code. If I just pull from master, then my changes get buried underneath > the newest changes. > > I guess I still don't quite understand how things are supposed to work > in situations like this. If you make changes in a branch and want them on top of what's in master, then do git-rebase master in _the branch_ and then merge the branch into master. And if you're using github to do pull requests and the like, then don't merge into master all. Simply create the pull request from the branch. That way, master only ever gets updated when the main repository gets updated, and you always have a clean version which matches the main repository. - Jonathan M Davis
Re: Using lazily ?
On 03/01/2012 10:50 PM, bioinfornatics wrote: dear, Noob question for know if D provide a shorter way i explain we have a struct S: struct S{ string member1; string member2; string member3; } we parse a file: File f = File("a path", "r"); S s; sise_t tokenLength = "member1".length; foreach( char[] line; f.byLine() ) mixin("s." ~ line[0 .. tokenLength] ~ " = " ~ line[tokenLength .. $]" ); // do not work because lien is not kno at compile time I know this do not works i.e comment but it will save some line by checking if is member1 2 or 3 They are a shorter way to do this use lazy ? struct S{ string member1; string member2; string member3; } S s; size_t tokenLength = "member1".length; void main(){ foreach(char[] line; stdin.byLine()) foreach(m;__traits(allMembers,S)){ if(line[0..tokenLength] == m) mixin("s."~m) = line[tokenLength .. $].idup; } }
Using lazily ?
dear, Noob question for know if D provide a shorter way i explain we have a struct S: struct S{ string member1; string member2; string member3; } we parse a file: File f = File("a path", "r"); S s; sise_t tokenLength = "member1".length; foreach( char[] line; f.byLine() ) mixin("s." ~ line[0 .. tokenLength] ~ " = " ~ line[tokenLength .. $]" ); // do not work because lien is not kno at compile time I know this do not works i.e comment but it will save some line by checking if is member1 2 or 3 They are a shorter way to do this use lazy ?
Re: Dumb question about git
OK, so what's the right way to do it then? I have some changes in a branch, but master has been updated since, so I want to merge in the latest updates so that the branch changes are compatible with the latest code. I use a quite crappy way to rebase my feature branch: git stash && git checkout master && git pull -v --rebase && git rebase master myworkingbranch There's probably some redundancy or whatever here, but at least it works ^^
Re: SysTime in a Struct
On 03/01/2012 09:14 AM, albatroz wrote: > Have fixed the segfault by using DateTime instead of SysTime. >> >> That is a separate local variable within this(this). Also, this(this) >> is the postblit (similar to a copy constructor). Is that what you want >> to define? > > No, but not using this(this) will fail to build with: > static variable _initialized cannot be read at compile time So you are trying to initialize the member with a default initializer, like this: struct prevEv { // ... DateTime edatetime = DateTime(/* ... */); } For that to work, the initial value must be a compile-time value. I am not sure that you want that. Also, this(this) is needed in very rare cases. Are you trying to create objects of prevEv? Then you should use this(). Unfortunately, structs cannot have default constructors. A solution might be to use a function that makes and returns a prevEv: prevEv make_prevEv() { return prevEv(/* ... */, DateTime(/* ... */)); } > Making the struct similar to what you suggest will work. > struct prevEv { > string edate; > string etime; > string etext; > DateTime edatetime; > this (this) > { > edatetime = DateTime( > Clock.currTime.year, > to!int(this.edate[2..4]), > to!int(this.edate[0..2]), > to!int(etime[0..2]), > to!int(etime[3..5]), > to!int(etime[6..8])); > } > } > > Just not has expected, do you have any suggestion how to do it properly? Are you trying to record the time when a prevEv is copied from another one? If not, I suggest not defining this(this). It is the postblit, to make things right for rare structs and only when the compiler generated copying is wrong for a that type. Or, are you just trying to define a type that contains time information? > > writeln ( prevEv.edatetime ); //0001-Jan-01 00:00:00 > writeln ( prevEv ); // preEv("140212", "05:13:26", "9 140212 05:13:26 > d", 2012-Feb-14 05:13:26) > >> >> >> Ali > Thanks > Ali
Re: Dumb question about git
On Mar 1, 2012 12:15 PM, "H. S. Teoh" wrote: > > On Thu, Mar 01, 2012 at 10:22:33AM -0500, Kevin Cox wrote: > > When people say git encourages rewriting history. Don't listen. Once > > you have pushed your changes to the world they are immutable. This is > > because git uses cryptography internally and changing the history > > messes everything up. If you haven't pushed you can change all of > > your history and it will all be fine. But if someone else (github) > > has the old hisory bad things happen. If you are sure nobody has > > pulled from github you can use --force when pushing (I think). It > > will work no matter what but you will piss off people if they have > > pulled from you. Please note that this kind of history modifying is > > considered bad practice. > [...] > > OK, so what's the right way to do it then? I have some changes in a > branch, but master has been updated since, so I want to merge in the > latest updates so that the branch changes are compatible with the latest > code. If I just pull from master, then my changes get buried underneath > the newest changes. > > I guess I still don't quite understand how things are supposed to work > in situations like this. > > > T > > -- > Music critic: "That's an imitation fugue!" This time I would just --force. In the future the idea is to only push changes once you are happy with them. What I would do next time is: - work - commit - work - commit - pull - rebase (make what you have done look pretty) - push
Re: Dumb question about git
On Thu, Mar 01, 2012 at 10:22:33AM -0500, Kevin Cox wrote: > When people say git encourages rewriting history. Don't listen. Once > you have pushed your changes to the world they are immutable. This is > because git uses cryptography internally and changing the history > messes everything up. If you haven't pushed you can change all of > your history and it will all be fine. But if someone else (github) > has the old hisory bad things happen. If you are sure nobody has > pulled from github you can use --force when pushing (I think). It > will work no matter what but you will piss off people if they have > pulled from you. Please note that this kind of history modifying is > considered bad practice. [...] OK, so what's the right way to do it then? I have some changes in a branch, but master has been updated since, so I want to merge in the latest updates so that the branch changes are compatible with the latest code. If I just pull from master, then my changes get buried underneath the newest changes. I guess I still don't quite understand how things are supposed to work in situations like this. T -- Music critic: "That's an imitation fugue!"
Re: SysTime in a Struct
Have fixed the segfault by using DateTime instead of SysTime. That is a separate local variable within this(this). Also, this(this) is the postblit (similar to a copy constructor). Is that what you want to define? No, but not using this(this) will fail to build with: static variable _initialized cannot be read at compile time Making the struct similar to what you suggest will work. struct prevEv { string edate; string etime; string etext; DateTime edatetime; this (this) { edatetime = DateTime( Clock.currTime.year, to!int(this.edate[2..4]), to!int(this.edate[0..2]), to!int(etime[0..2]), to!int(etime[3..5]), to!int(etime[6..8])); } } Just not has expected, do you have any suggestion how to do it properly? writeln ( prevEv.edatetime ); //0001-Jan-01 00:00:00 writeln ( prevEv ); // preEv("140212", "05:13:26", "9 140212 05:13:26 d", 2012-Feb-14 05:13:26) Ali Thanks
Re: Dumb question about git
On 01.03.2012 19:11, H. S. Teoh wrote: OK, so I'm new to git, and I ran into this problem: - I forked druntime on github and made some changes in a branch - Pushed the changes to the fork I use the magic pull --rebase master instead of these 3 if I have changes but want to sync with upstream. - Pulled upstream commits to master - Merged master with branch - Ran git rebase master, so that my changes appear on top of the latest upstream master. That's pretty much all. - Tried to push branch to my fork, but now it complains that I have non-fast-forward changes and rejects the push. I think push --force should do the trick What's the right thing to do here? Looks like I screwed up my branch history. How do I fix it? Thanks! T -- Dmitry Olshansky
Re: Regarding std.array.Appender
On 03/01/2012 03:40 AM, Jonathan M Davis wrote: On Wednesday, February 29, 2012 21:23:54 bearophile wrote: Jonathan M Davis: put is a function on output ranges, and Appender is an output range. Also, given that it doesn't define ~ (and it wouldn't really make sense for it to), it would be very weird IMHO to define ~=. I don't understand why that's weird. In Java you can't overload an append operator, so using a method is right. But for me it's weird that Appender doesn't use the D operator to _append_. I sometimes use "add" instead of "put" by mistake, forgetting the right method name, because I find it quite unnatural. If Appender needs a put, then I suggest to give it both "put" method and "~=" operator. Would you define += without defining +? Or *= without defining *? It strikes me as a misuse of operator overloading if you have an opOpAssign without its corresponding opBinary. - Jonathan M Davis It is not the same thing. a=a~b has different semantics from a~=b;
Re: Should uniform(-real.max, real.max) be inf?
On 03/01/2012 02:52 AM, Magnus Lie Hetland wrote: > What's the preferred way of generating a random floating-point number in > the range of a given floating-point type? We have uniform!T() for > integral types, but nothing similar for floats? And uniform(-real.max, > real.max) (possibly tweaking the limits) seems to only return inf, which > isn't terribly helpful. > > What's the standard thing to do here? I could just use > > uniform(cast(T) -1, cast(T) 1)*T.max > > I guess (for some floating-point type T). Seems to work fine, at least. > > Am I missing the obvious way to do it? > I recommend reading this page: http://dlang.org/d-floating-point.html 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.max. 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. Ali
Re: SysTime in a Struct
On 03/01/2012 06:15 AM, albatroz wrote: > Hi, > > I have defined this struct > struct preEv { > string edate; //010112 > string etime; //00:00:00 > string etext; // > SysTime esystime; That is a member of this type. > this (this) { > SysTime esystime = SysTime(DateTime( That is a separate local variable within this(this). Also, this(this) is the postblit (similar to a copy constructor). Is that what you want to define? I think you want to simply do this anyway: esystime = or this: this.esystime = > Clock.currTime.year, > to!int(this.edate[2..4]), > to!int(this.edate[0..2]), > to!int(etime[0..2]), > to!int(etime[3..5]), > to!int(etime[6..8]))); > } > } > > If I write to the sctruct and then print it I'm able to see the > SysTime variable with a value. > writeln(preEv) //previousEvents("140212", "05:13:26", "9 140212 > 05:13:26 d", "2012-Feb-14 05:13:26") > > but if trying to get the value from the SysTime variable I get a > Segmentation fault. Probably because esystime member is no initialized. > Trying to read any other variable inside this > struct will not be a problem. > > writeln (preEv.esystime.day) // will compile but segfaults > > On DMD32 D Compiler v2.058 > > Any correct way to do this? > > Thank you. Ali
Re: Dumb question about git
When people say git encourages rewriting history. Don't listen. Once you have pushed your changes to the world they are immutable. This is because git uses cryptography internally and changing the history messes everything up. If you haven't pushed you can change all of your history and it will all be fine. But if someone else (github) has the old hisory bad things happen. If you are sure nobody has pulled from github you can use --force when pushing (I think). It will work no matter what but you will piss off people if they have pulled from you. Please note that this kind of history modifying is considered bad practice. On Mar 1, 2012 10:10 AM, "H. S. Teoh" wrote: > OK, so I'm new to git, and I ran into this problem: > > - I forked druntime on github and made some changes in a branch > - Pushed the changes to the fork > - Pulled upstream commits to master > - Merged master with branch > - Ran git rebase master, so that my changes appear on top of the latest > upstream master. > - Tried to push branch to my fork, but now it complains that I have > non-fast-forward changes and rejects the push. > > What's the right thing to do here? Looks like I screwed up my branch > history. How do I fix it? > > Thanks! > > > T > > -- > Real Programmers use "cat > a.out". >
Dumb question about git
OK, so I'm new to git, and I ran into this problem: - I forked druntime on github and made some changes in a branch - Pushed the changes to the fork - Pulled upstream commits to master - Merged master with branch - Ran git rebase master, so that my changes appear on top of the latest upstream master. - Tried to push branch to my fork, but now it complains that I have non-fast-forward changes and rejects the push. What's the right thing to do here? Looks like I screwed up my branch history. How do I fix it? Thanks! T -- Real Programmers use "cat > a.out".
SysTime in a Struct
Hi, I have defined this struct struct preEv { string edate; //010112 string etime; //00:00:00 string etext; // SysTime esystime; this (this) { SysTime esystime = SysTime(DateTime( Clock.currTime.year, to!int(this.edate[2..4]), to!int(this.edate[0..2]), to!int(etime[0..2]), to!int(etime[3..5]), to!int(etime[6..8]))); } } If I write to the sctruct and then print it I'm able to see the SysTime variable with a value. writeln(preEv) //previousEvents("140212", "05:13:26", "9 140212 05:13:26 d", "2012-Feb-14 05:13:26") but if trying to get the value from the SysTime variable I get a Segmentation fault. Trying to read any other variable inside this struct will not be a problem. writeln (preEv.esystime.day) // will compile but segfaults On DMD32 D Compiler v2.058 Any correct way to do this? Thank you.
Re: Should uniform(-real.max, real.max) be inf?
On 2012-03-01 10:52:49 +, Magnus Lie Hetland said: I could just use uniform(cast(T) -1, cast(T) 1)*T.max I guess (for some floating-point type T). Seems to work fine, at least. Aaactually, not so much. The output here seems to get about the same exponent as T.max. Which isn't all that surprising, I guess. (Then again, most floating-point numbers *are* pretty large ;-) So ... any suggestions? -- Magnus Lie Hetland http://hetland.org
Should uniform(-real.max, real.max) be inf?
What's the preferred way of generating a random floating-point number in the range of a given floating-point type? We have uniform!T() for integral types, but nothing similar for floats? And uniform(-real.max, real.max) (possibly tweaking the limits) seems to only return inf, which isn't terribly helpful. What's the standard thing to do here? I could just use uniform(cast(T) -1, cast(T) 1)*T.max I guess (for some floating-point type T). Seems to work fine, at least. Am I missing the obvious way to do it? -- Magnus Lie Hetland http://hetland.org
Re: about std.csv and derived format
On Thursday, 1 March 2012 at 10:09:55 UTC, bioinfornatics wrote: and how convert bedInstances input array to BedData11[] ? std.array.array()
Re: about std.csv and derived format
Le jeudi 01 mars 2012 à 04:36 +0100, Jesse Phillips a écrit : > On Thursday, 1 March 2012 at 02:07:44 UTC, bioinfornatics wrote: > > > It is ok i have found a way maybe is not an efficient way but > > it works: > > https://gist.github.com/1946669 > > > > a minor bug exist for parse track line will be fixed tomorrow. > > time to > > bed > > > > > > Big thanks to all > > You can edit a gist instead of creating a new. > > This seems like a very fragile implementation, and hard to > follow. My quick untested code: > > auto str = readText(filePath); > > // Ignoring first three lines. > str = array(str.util(newline).until(newline).until(newline)); > > auto bedInstances = > csvReader!(BedData11,Malformed.ignore)(str,'\t'); > > But if you must keep the separate structs, I don't have any > better suggestions. and how convert bedInstances input array to BedData11[] ? Add a constructo to BedData11 and use std.algorithm.map? map!"BedData11(a.filed1, a.filed2...)"(bedInstances);