Re: unit-threaded v0.8.0
On Wednesday, 30 January 2019 at 14:27:25 UTC, Atila Neves wrote: New release of unit-threaded, the advanced test framework for D: https://code.dlang.org/packages/unit-threaded Besides bug fixes, the main difference is now cartesian product of types works as it did for values when it comes to parameterized tests: -- @Types!(ubyte, byte) @Types!(int, uint, float) @UnitTest void fun(T0, T1)() { static assert(T0.sizeof == 1); static assert(T1.sizeof == 4); } -- This now generates 6 tests, one for each combination of types, similarly to what already worked with the @Values UDA. Thanks for this library. One of the more useful on code.dlang.org!
Re: Process Pipes
On Tuesday, 9 October 2018 at 09:15:09 UTC, Gorker wrote: Hi all, I'm on macOS 10.11.6 with dmd 2.081.2 and I've a problem with std.process. --- gork ():foo gorker$ gcc -c -Iinclude -o foo.cpp.o src/foo.cpp In file included from src/foo.cpp:2: include/foo/foo.hpp:22:10: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions] enum class foo_event_type_t ^ 56 warnings and 9 errors generated. --- No output, (zero bytes) in stdout. If I use standard process to collect both stream with: --- auto processPipes = pipeProcess(args, Redirect.all, null, Config.none, workDir); foreach (c; pipes.stdout.byChunk(100)) writeln(cast(string) c); // <<< it halts here: stdout file is empty, but not EOF foreach (c; pipes.stderr.byChunk(100)) writeln(cast(string) c); --- Everything is fine if I don't redirect the stderr to a pipe. Suggestions? If you want to use asynch io - you'll have to fork and use NONBLOCK output on the file descriptor. I wrote this years ago (not sure if it still compiles tbh, but it should) https://github.com/grogancolin/dexpect Specifically this block should help you: https://github.com/grogancolin/dexpect/blob/master/source/dexpect.d#L343-L352
Re: Source changes should include date of change
On Saturday, 8 September 2018 at 06:59:28 UTC, Josphe Brigmo wrote: Having source code that doesn't show changes with dates is pretty useless for diagnostics. I realize that git has the changes but the source code should. If some code is added or changed it is very simple to add the date of change in a comment. // Date: Date1, Date2, Date3, Anything below a was changed at those dates. Why not also add a link to the git hub patch or bugzilla or whatever? Git is the tool that's used to manage changes, including viewing the changes. A lot of dev time has gone into it and it works really well. Some ad hoc comment system in source code to point out changes will never be as good. Just Use Git!
Re: Auto keyword and when to use it
On Monday, 20 August 2018 at 17:52:17 UTC, QueenSvetlana wrote: Great! So I can't declare class level variables with auto, correct? only local method variables? You can use auto if you're setting the class level variable to a default. class X { auto i = 42; // i will be an int }
Re: Making sense of recursion
On Monday, 25 June 2018 at 17:45:01 UTC, zbr wrote: Hi, this question is not specifically D related but I'll just ask anyway. Consider the following snippet: [...] Your mistake is in your visualization :-) But... more like: 0 < 4 ? true : mergeSort(0,2) && mergeSort(3, 4) And so on. I.e, the it's not either or to run the second mergeSort, they both happen.
Re: #include C headers in D code
On Monday, 9 April 2018 at 11:03:48 UTC, Atila Neves wrote: Here's my blog post about my project that allows directly #including C headers in D* https://atilanevesoncode.wordpress.com/2018/04/09/include-c-headers-in-d-code/ The summary is that, modulo bugs, things like this work: #include void main() { printf("Hello world\n".ptr); } So far it's successfully compiled whilst #including pthread, libcurl, openssl and others. The blog and the github README have more information, and feel free to reply to this with questions. dub: http://code.dlang.org/packages/dpp reddit: https://www.reddit.com/r/programming/comments/8axj53/include_c_headers_in_d_code/ hacker news: It's in there somewhere, search around. Atila * Technically, "D + #include directives + C macros" This is very cool. Gonna try it against gl.h tonight!
Re: Unable to run D program on mac system when using dependency.
On Wednesday, 10 January 2018 at 12:44:01 UTC, Harbeer Kadian wrote: I am pretty new to D language. I am working on existing code developed by others. Previous developers were using linux environment to build and run the D Application. I am trying to do the same in MAC as it is my local environment. [...] What version of DMD are you using?
Re: Error: variable foo conflicts with struct foo
On Thursday, 4 January 2018 at 17:45:35 UTC, Stijn wrote: Why is it not allowed for a variable name to match a type name? The following example fails with "Error: variable foo conflicts with struct foo" struct foo {} foo foo; How can the compiler know which symbol is which symbol if everything has the same name? Standard practice is to capitalise type names and camelCase variable names.
Re: static if and early exit from function doesn't seem to work?
On Sunday, 31 December 2017 at 13:32:03 UTC, aliak wrote: Alo! I'm making a recursive concat function that is similar to chain. The following code works: [...] I suspect it's because you've no 'else static if'.
Re: Embedded Containers
On Tuesday, 5 December 2017 at 19:13:10 UTC, A Guy With a Question wrote: On Tuesday, 5 December 2017 at 19:09:50 UTC, Adam D. Ruppe wrote: [...] Ok, so that worked. I still have the problem with importing though: mypackage: Item seems to generate the error: "Error: undefined identifier 'Item'" Which is weird, because I'm able to bring in Array through std.container.array: Array; Is Item public in your package?
code.dlang.org is down
Just in case whomever runs this doesn't know.
Re: ZipException: no end record when attempting dub fetch vibelog
On Friday, 8 September 2017 at 13:33:42 UTC, Kevin McTaggart wrote: Once again, I'm taking a serious look at D after a break of 3 years. I'm trying to download packages using dub from DMD 2.076 as follows: dub fetch vibelog The following error is produced: ZipException: no end record Any suggestions? Looks like the file isn't being downloaded correctly? I'd try deleting the .dub/packages/ directory. (not sure the equivalent location on windows).
Re: dub projects generate docs and host on code.dlang.org?
On Tuesday, 5 September 2017 at 22:30:24 UTC, user1234 wrote: On Tuesday, 5 September 2017 at 02:08:08 UTC, Manu wrote: On 4 September 2017 at 21:45, user1234 via Digitalmars-d < digitalmars-d@puremagic.com> wrote: On Monday, 4 September 2017 at 10:47:47 UTC, Manu wrote: Thoughts? - Manu It has existed in the past, see http://forum.dlang.org/thread/ weuxppabkrreaxbqq...@forum.dlang.org?page=1 Seems to be gone. Yes of course it's gone. That's a fact. I wanted to bring this fact in the discussion. That has existed already. I think nobody cared about the initiative. I think it was nice. It just wasn't particularly well integrated and it's look and feel was... off. This thread proves theres interest in this, so it would certainly be worth some time. Maybe reviving kiith-sa's work or starting a new?
Re: Tilix 1.5.8 released
On Tuesday, 23 May 2017 at 23:35:22 UTC, Gerald wrote: Tilix 1.5.8 is now available with a number of new features and bug fixes. For those unfamiliar with Tilix, it is a tiling terminal emulator for Linux written in D using GTK3. It attempts to follow the Gnome Human Interface Guidelines as closely as possible. More information about Tilix is available here: https://gnunn1.github.io/tilix-web One word of caution, this version of Tilix has been upgraded to using PCRE2 for regular expressions when the VTE version indicates it is supported. Unfortunately Ubuntu 17.10 removed this functionality from VTE and hence Tilix is broken on 17.10 until Ubuntu patches Tilix in their distribution. See issue [#916](https://github.com/gnunn1/tilix/issues/916) for more information. Other notable changes for this release include: * Can detach sessions by dragging them off the sidebar to the desktop. Can re-attach sessions by dragging them from the sidebar to another tilix window * Can re-order sessions via drag and drop in sidebar or by using ctrl-pgup or ctrl-pagedn * If ctrl-c is assigned to the copy shortcut, tilix is smart enough to only copy when text is selected otherwise normal interrupt is passed * Window state is now restored on new launch, i.e. if window is maximized and closed it will be maximized when new instance is launched * Added new variable for titles at session scope for active terminal title * Added support for GTK active CSS style to enable better styling of terminal titlebars * Added support for pending VTE hyperlink functionality (#904) As always, any D developers interested in contributing to Tilix are more then welcome to do so. Feel free to contact me if interested. How difficult would it be to get osx support? I haven't looked at the source code at all so forgive the potentially stupid question. Also, looking at the screens - it looks very like tmux - is there any integration there?
Re: 'real' not able to store it's largest value
D'oh! Thanks Adam and Ali :)
'real' not able to store it's largest value
Am I doing something wrong here? real.max evaluates to: 1.18973e+4932 So, I'd expect to be able to store any value up to that... however ``` void main() { writeln("Real max: ", real.max); foreach(i; 0..10){ writefln!("1024 ^^ %s = %s")(i, real(1024 ^^ i)); } } ``` Output: ``` Real max: 1.18973e+4932 1024 ^^ 0 = 1 1024 ^^ 1 = 1024 1024 ^^ 2 = 1.04858e+06 1024 ^^ 3 = 1.07374e+09 1024 ^^ 4 = 0 1024 ^^ 5 = 0 1024 ^^ 6 = 0 1024 ^^ 7 = 0 1024 ^^ 8 = 0 1024 ^^ 9 = 0 ```
rdmd with a file with no extension
When running a small D program through rdmd, it seems the file needs a .d extension to work. ``` $ ./testscript2 Error: module testscript2 is in file './testscript2.d' which cannot be read $ cat testscript2 #!/usr/bin/env rdmd void main(string[] args){ import std.stdio; writeln(args); } ``` Trying the above on OSX if that makes a difference. Any way to get these to work short of renaming it testscript2.d?
Re: Moving forward with work on the D language and foundation
On Thursday, 27 August 2015 at 16:01:54 UTC, BBasile wrote: On Monday, 24 August 2015 at 18:43:01 UTC, Andrei Alexandrescu wrote: [...] That's courageous, particularly past 50 yo. It's a different culture, past 50 yo in Europe people choose security, but in USA, past 50 yo some people still take the risk to try something new. Awesome. Andrei is past 50? Doesn't look it!
Re: Moving forward with work on the D language and foundation
On Thursday, 27 August 2015 at 18:42:41 UTC, BBasile wrote: On Thursday, 27 August 2015 at 18:03:37 UTC, Colin wrote: On Thursday, 27 August 2015 at 16:01:54 UTC, BBasile wrote: On Monday, 24 August 2015 at 18:43:01 UTC, Andrei Alexandrescu wrote: [...] That's courageous, particularly past 50 yo. It's a different culture, past 50 yo in Europe people choose security, but in USA, past 50 yo some people still take the risk to try something new. Awesome. Andrei is past 50? Doesn't look it! And Walter who was involved in the 80's in the team who made MS DOS... do you think he's 20 yo ? We were talkin' bout Andrei yo, not Walter!
Re: DDT 0.13.0 released - DUB configurations support.
On Tuesday, 11 August 2015 at 17:03:35 UTC, Bruno Medeiros wrote: A new DDT release (nicknamed Candy Kingdom ) is out, please read the changelog: https://github.com/bruno-medeiros/DDT/releases/tag/Release_0.13.0 This is Release Candidate quality, there might be a few undiscovered bugs with the recently introduced functionality. Great work! Thanks. Is the next one going to be Ice Kingdom?
Re: line numbers for linux exception traces
On Wednesday, 5 August 2015 at 15:57:46 UTC, Adam D. Ruppe wrote: If you just download this little file: http://arsdnet.net/dcode/linetrace.d [...] This is v nice - thanks! I wonder how difficult implementing this in the compiler would be? Obviously cant use external tools...
Re: Wait, what? What is AliasSeq?
On Wednesday, 15 July 2015 at 18:21:10 UTC, Andrei Alexandrescu wrote: On 7/15/15 11:54 AM, Deadalnix wrote: That how I ended up with seq in the first place. I went to talk to everybody and sequence was what came up the most while not having people as opposed to it as list. Now I'm sorry I even started. I'd be happy to return to AliasSeq. -- Andrei Luckily we have 2 people that can just decide. I reckon at this stage yourself and Walter should just pick the name ye prefer best and go with it. The democratic approach, I feel anyway, hasn't worked in this case... (Doesn't mean it wont in future!!)
DMD Copyright string
I notice when you run dmd with no args, it will print: DMD64 D Compiler v2.067.0 Copyright (c) 1999-2014 by Digital Mars written by Walter Bright Surely that's meant to be 2015? Walter should prob fix that. Someone could steal D!
Re: How to make a Currency class from std.BigInt?
On Saturday, 31 January 2015 at 14:26:45 UTC, RuZzz wrote: The next version, which does not work: https://bpaste.net/show/b9c85de68d07 I really dont understand what your trying to achieve here. Maybe you can articulate it in one post what this class is trying to achieve?
Re: How to make a Currency class from std.BigInt?
On Saturday, 31 January 2015 at 12:07:23 UTC, RuZzz wrote: How to get amount of digit after point in a double for to get integer from a double? assert(amountAfterPoint(1.456) == 3); assert(amountAfterPoint(0.6) == 5); How about a loop like import std.stdio; void main(){ writefln(%s, 1.45.numDigits);// prints 2 writefln(%s, 1.452343.numDigits);// prints 6 writefln(%s, 1.0.numDigits);// prints 0 } long numDigits(double num){ long i=0; double n=num; while(true){ if(n - (cast(long)n) == 0){ return i; } i++; n *= 10; } }
Re: Eliminate comparison.html?
On Saturday, 17 January 2015 at 17:32:43 UTC, Andrei Alexandrescu wrote: In https://github.com/D-Programming-Language/dlang.org/pull/778 I'm proposing replacing http://dlang.org/comparison.html with http://erdani.com/d/comparison.html The silly one-column comparison was a vestige of a multi-column comparison that did more harm than good. I replaced it with a simple hierarchical list. However I wonder if we should eliminate the page altogether, or redo it completely. Thoughts? Andrei When viewing the http://dlang.org/comparison.html page, the nav tree on the left now looks like: D 2.066.1 Download Overview Features Features With the second features link pointing at comparison.html, and the second containing a list of D2 features. (features2.html) Im guessing it's still a WIP but said I'd let you know just in case...
Re: building a simple json tree
On Thursday, 15 January 2015 at 12:50:59 UTC, Rikki Cattermole wrote: On 16/01/2015 1:37 a.m., anonymous wrote: On Thursday, 15 January 2015 at 12:10:09 UTC, Rikki Cattermole wrote: On 16/01/2015 12:16 a.m., anonymous wrote: what's the right syntax for building a JSON tree ? I try to do like in an AA but the program throw because the Key doesn't exist: --- import std.stdio, std.json; void main(string[] args) { struct Foo{ string a, b; void writeToJson(ref JSONValue target) { target[a] = JSONValue(a); target[b] = JSONValue(b); } } JSONValue root = parseJSON({}); root[items] = JSONValue([]); Foo*[] foos; foos ~= new Foo(a1,b1); foos ~= new Foo(a2,b2); foreach(foo; foos) { root[items].array.length += 1; root[items].array[$-1] = parseJSON({}); foo.writeToJson(root[items].array[$-1]); } } --- import std.stdio, std.json; void main(string[] args) { struct Foo{ string a, b; void writeToJson(ref JSONValue target) { target[a] = JSONValue(a); target[b] = JSONValue(b); } } JSONValue root = [items: cast(string[])[]]; Foo[] foos; foos ~= Foo(a1,b1); foos ~= Foo(a2,b2); foreach(foo; foos) { root[items].array ~= JSONValue(foo.a); root[items].array ~= JSONValue(foo.b); } writeln(root.toString()); } I would recommend keeping away from std.json. Its an old piece of code, that needs to be replaced. Vibe.d has a much nicer implementation that is really decent. I would recommend that, if you are up to using the build manager dub. Thx, but actually I initially liked to get an array of object with each identifier: currently it produces: {items:[a1,b1,a2,b2]} while it'd be more desirable to have {items:[{a:a1,b:b1}, {a:a2,b:b2}]} because the reader will test the presence of each the key a and b in each element of items. Would it be a complete non-sense to assign an element with opIndexAssign(), just like I wrote initially ? I know this is wrong but the syntax seemed natural and logic. Reading from std.json is straightforward but writing looks a bit messy. It makes sense to do it. But like I said std.json is rubbish. Just so you can see why I'm saying vibe.d's json implementation is better[0]. [0] https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/data/json.d#L1670 Also, look at the new std.json candidate: http://code.dlang.org/packages/std_data_json
Re: Accessing class with module name as Java's
Have the following directory structure? ~/testModule$ find . -print . ./net ./net/http_.d# ** ./net/http ./net/http/Mod1.d ./net/http/Mod2.d ./main.d ** I put the _ here to make it seperate from the net/http directory. Probably, a better solution exists, this was hacked together quickly :) In http_.d have: module net.http_; // again, a better solution surely exists public import net.http.Mod1; public import net.http.Mod2; Then in your main have import net.http_; You can then use whatever's in Mod1 and Mod2 modules. In your case, Mod1/Mod2 will be like HTTPConnectionRequest/HTTPConnectionResponse and will only contain a single class. This works for me. You can also go a little further and have renamed imports. Something like: public import Renamed = net.http.Mod2; Then in main.d call it with: Renamed.Mod2 mod2 = new renamed.Mod2; Feels just like Java :)
Re: Accessing class with module name as Java's
On Tuesday, 13 January 2015 at 09:22:04 UTC, Colin wrote: Have the following directory structure? ~/testModule$ find . -print . ./net ./net/http_.d# ** ./net/http ./net/http/Mod1.d ./net/http/Mod2.d ./main.d ** I put the _ here to make it seperate from the net/http directory. Probably, a better solution exists, this was hacked together quickly :) In http_.d have: module net.http_; // again, a better solution surely exists public import net.http.Mod1; public import net.http.Mod2; Then in your main have import net.http_; You can then use whatever's in Mod1 and Mod2 modules. In your case, Mod1/Mod2 will be like HTTPConnectionRequest/HTTPConnectionResponse and will only contain a single class. This works for me. You can also go a little further and have renamed imports. Something like: public import Renamed = net.http.Mod2; Then in main.d call it with: Renamed.Mod2 mod2 = new renamed.Mod2; Feels just like Java :) Ah, I just re-read your OP. Your already at this point :)
Re: We need a DConf 2015 logo
On Friday, 9 January 2015 at 07:25:54 UTC, Jacob Carlborg wrote: On 2015-01-08 23:40, ponce wrote: There: http://ovh.to/GAYPaom - same vector logo but with text and gray background - a render in 500x150 (I've used Firefox) - instructions on how to render again Let me know if you need any change. Shouldn't the logo look at least somewhat similar to the one on dlang.org? It shouldn't just be similar, it should be the same one I feel. The new logo is pretty snazzy though!
Re: Even better navigation - thanks Nick Treleaven!
On Wednesday, 7 January 2015 at 23:18:03 UTC, Andrei Alexandrescu wrote: We just deployed Nick's work at https://github.com/D-Programming-Language/dlang.org/pull/726, which enables jump-to navigation for structures. For example, from http://dlang.org/phobos/std_array.html#.Appender one can jump easily to its methods. Thanks, Nick! Andrei Nice! std.datetime is a little* nicer to navigate now. (Your not guessing which toISOExtString your clicking on for example). * I do mean a LITTLE. That module is still an enigma wrapped up in a mystery all shrouded in a veil of deceit.
Re: Compile for other OS's on Windows?
On Monday, 5 January 2015 at 15:00:05 UTC, Bauss wrote: On Monday, 5 January 2015 at 12:54:00 UTC, Gary Willoughby wrote: On Monday, 5 January 2015 at 11:49:32 UTC, Bauss wrote: Is it possible to compile for other OS's on Windows using dmd? This is what's known as cross compiling and is not currently supported by DMD at this time. Any alternatives? Fire up a VM of the target machine (easy with any of the *nix systems) and compile on that?
Re: std.file.readText() extra Line Feed character
On Thursday, 18 December 2014 at 22:29:30 UTC, Ali Çehreli wrote: On 12/18/2014 02:51 AM, Colin wrote: vi, and it does indeed have a '\n' at the end of file. Ah, I see. That's a little annoying. It looks like there are ways of dealing with it: http://stackoverflow.com/questions/1050640/vim-disable-automatic-newline-at-end-of-file Ali happy with Emacs :p Does emacs do this aswell? :) Anyway, I'm making a tool which will be in use by a range of people, so making the tool accept inputs with \n or not would be the better choice than getting everyone to ensure they dont have \n at the end of every file.
std.file.readText() extra Line Feed character
Why does std.file.readText() append a Line Feed char onto the end of the string? I have a file with the following contents in it: Name = Int Other=Float One More = String(Random;) I then have the code: void main(string[] args){ const text = Name = Int Other=Float One More = String(Random;); string input = readText(args[1]); writefln(Raw data); writefln(D)%s, cast(ubyte[])text[$-5..$]); writefln(File) %s, cast(ubyte[])input[$-5..$]); } This produces: Raw data D)[100, 111, 109, 59, 41] File) [111, 109, 59, 41, 10] Any Idea why the reading from the File adds on that extra '10' character? I don't think it's my editor adding chars to the end of the file, as I'm using vi.
Re: std.file.readText() extra Line Feed character
On Thursday, 18 December 2014 at 09:25:47 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 18 Dec 2014 09:18:35 + Colin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Why does std.file.readText() append a Line Feed char onto the end of the string? I have a file with the following contents in it: Name = Int Other=Float One More = String(Random;) I then have the code: void main(string[] args){ const text = Name = Int Other=Float One More = String(Random;); string input = readText(args[1]); writefln(Raw data); writefln(D)%s, cast(ubyte[])text[$-5..$]); writefln(File) %s, cast(ubyte[])input[$-5..$]); } This produces: Raw data D)[100, 111, 109, 59, 41] File) [111, 109, 59, 41, 10] Any Idea why the reading from the File adds on that extra '10' character? I don't think it's my editor adding chars to the end of the file, as I'm using vi. you *definetely* has the last line ended with '\n'. I dont see how, I copy and pasted from the string definition in D, directly after the first and directly before the last . If I look at the file in vim with line numbers turned on, the file is like this. So I really dont think I have a new line in the file... 1 Name = Int 2 Other=Float 3 One More = String(Random;)
Re: std.file.readText() extra Line Feed character
On Thursday, 18 December 2014 at 10:43:32 UTC, yazd wrote: On Thursday, 18 December 2014 at 10:16:38 UTC, Colin wrote: On Thursday, 18 December 2014 at 09:25:47 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 18 Dec 2014 09:18:35 + Colin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Why does std.file.readText() append a Line Feed char onto the end of the string? I have a file with the following contents in it: Name = Int Other=Float One More = String(Random;) I then have the code: void main(string[] args){ const text = Name = Int Other=Float One More = String(Random;); string input = readText(args[1]); writefln(Raw data); writefln(D)%s, cast(ubyte[])text[$-5..$]); writefln(File) %s, cast(ubyte[])input[$-5..$]); } This produces: Raw data D)[100, 111, 109, 59, 41] File) [111, 109, 59, 41, 10] Any Idea why the reading from the File adds on that extra '10' character? I don't think it's my editor adding chars to the end of the file, as I'm using vi. you *definetely* has the last line ended with '\n'. I dont see how, I copy and pasted from the string definition in D, directly after the first and directly before the last . If I look at the file in vim with line numbers turned on, the file is like this. So I really dont think I have a new line in the file... 1 Name = Int 2 Other=Float 3 One More = String(Random;) You can make sure using `hexdump -C file`. I tested locally creating a file using vi, and it does indeed have a '\n' at the end of file. Ah, I see. That's a little annoying. Thanks folks!
Re: Parsing a date string into a std.datetime.datetime
On Thursday, 23 October 2014 at 21:17:23 UTC, Jonathan M Davis wrote: On Thursday, 23 October 2014 at 11:13:26 UTC, Colin wrote: Hi, I'm looking for an easy way to parse a dates into a datetime object. Most of my dates will be of the form: mmm dd, HH:MM AM|PM So like: May 30, 2014 12:12 PM I can easily write a regex or whatever to pull these out of that one format, but it's not guaranteed they'll all be in the one format and I may have to deal with others. Is there a helper function that I'm missing that can parse these dates? Maybe something similar to pythons dateutil.parser [1] ? If not maybe adding this function to std.datetime would be a good project to undertake for myself... [1] - https://labix.org/python-dateutil std.datetime supports the ISO formats but, it does not currently support generating or parsing custom strings for dates or times. It's on my todo list (probably after splitting std.datetime into a package), but I don't know exactly when I'm going to get to it. The first step will be figuring out what the format strings will look like, since what languages like C do is a complete mess. I had a proposal on it that was discussed a while ago, but it was too complicated. It'll probably end up being something closer to this http://pr.stewartsplace.org.uk/d/sutil/datetime_format.html though I'm afraid that that approach as it's presented might not be flexible enough. I'll probably need to do something like add a templated function that returns a custom struct with the values that you want so that you can get them effeiently to build the string yourself in the cases where you need to do something wacky enough that the normal custom string formatting functions aren't flexible enough. Then leaving the normal custom string format generating and parsing functions simpler works better. In any case, I intend to get to it, but I've been dreadfully slow about it. It's the number one thing missing from std.datetime. I'd prefer to do it myself, but there's certainly no reason why someone else can't do it if they really want to. - Jonathan M Davis Ok, thanks for the informative reply Jonathan. For now I'll go with parsing the few types of dates I may need, and maybe port over in the future when you get to it. Cheers!
Parsing a date string into a std.datetime.datetime
Hi, I'm looking for an easy way to parse a dates into a datetime object. Most of my dates will be of the form: mmm dd, HH:MM AM|PM So like: May 30, 2014 12:12 PM I can easily write a regex or whatever to pull these out of that one format, but it's not guaranteed they'll all be in the one format and I may have to deal with others. Is there a helper function that I'm missing that can parse these dates? Maybe something similar to pythons dateutil.parser [1] ? If not maybe adding this function to std.datetime would be a good project to undertake for myself... [1] - https://labix.org/python-dateutil
std.algorithm.reduce on an array of structs
I have this test code: struct Thing { uint x; } void main(){ uint[] ar1 = [1, 2, 3, 4, 5]; auto min1 = ar1.reduce!((a,b) = a b); writefln(%s, min1); // prints 1 as expected Thing[] ar2 = [Thing(1), Thing(2), Thing(4)]; auto min2 = ar2.reduce!((a,b) = a.x b.x); // - Wont Compile writefln(%s, min2); } The line with Wont Compile on it has this error message: /usr/include/dmd/phobos/std/algorithm.d(770): Error: cannot implicitly convert expression (__lambda2(result, front(_param_1))) of type bool to Thing /usr/include/dmd/phobos/std/algorithm.d(791): Error: template instance t.main.reduce!((a, b) = a.x b.x).reduce!(Thing, Thing[]) error instantiating t.d(16):instantiated from here: reduce!(Thing[]) Any idea what I'm doing wrong here? To me, the operation on ar2 should be pretty much identical to ar1, except for the use of the struct.
Re: std.algorithm.reduce on an array of structs
On Thursday, 11 September 2014 at 13:27:39 UTC, Daniel Kozak wrote: On Thursday, 11 September 2014 at 13:06:05 UTC, Colin wrote: I have this test code: struct Thing { uint x; } void main(){ uint[] ar1 = [1, 2, 3, 4, 5]; auto min1 = ar1.reduce!((a,b) = a b); writefln(%s, min1); // prints 1 as expected Thing[] ar2 = [Thing(1), Thing(2), Thing(4)]; auto min2 = ar2.reduce!((a,b) = a.x b.x); // - Wont Compile writefln(%s, min2); } The line with Wont Compile on it has this error message: /usr/include/dmd/phobos/std/algorithm.d(770): Error: cannot implicitly convert expression (__lambda2(result, front(_param_1))) of type bool to Thing /usr/include/dmd/phobos/std/algorithm.d(791): Error: template instance t.main.reduce!((a, b) = a.x b.x).reduce!(Thing, Thing[]) error instantiating t.d(16):instantiated from here: reduce!(Thing[]) Any idea what I'm doing wrong here? To me, the operation on ar2 should be pretty much identical to ar1, except for the use of the struct. You are try to put uint to Thing. This is corect version: import std.stdio; import std.algorithm; struct Thing { uint x; } void main(){ uint[] ar1 = [1, 2, 3, 4, 5]; auto min1 = ar1.reduce!((a,b) = a b); writefln(%s, min1); // prints 1 as expected Thing[] ar2 = [Thing(1), Thing(2), Thing(4)]; auto min2 = ar2.reduce!((a,b) = a.x b.x ? a : b); // - Wont Compile writefln(%s, min2); } Ah ok. I get it. Thanks daniel!
Re: std.algorithm.reduce on an array of structs
On Thursday, 11 September 2014 at 14:49:03 UTC, bearophile wrote: Daniel Kozak: You can just use min: import std.stdio, std.algorithm; struct Thing { uint x; alias x this; } alias minimum = reduce!min; void main() { immutable ar1 = [10, 20, 30, 40, 50]; ar1.minimum.writeln; immutable ar2 = [Thing(10), Thing(20), Thing(40)]; ar2.minimum.writeln; } Bye, bearophile Using the alias x this solution would work, but my actual struct is not a simple struct, so the comparison isn't exactly (a.x b.x).
Re: String to binary conversion
On Wednesday, 3 September 2014 at 12:33:49 UTC, clearion wrote: I would like to write binary data to a file for an ancillary hash table operation and then read it back using stream.rawRead(). How would I go about converting a string to binary in D. I would prefer not to use any third party libraries if I can. Thank You I think this: void main(){ string str = Test string; auto file = File(output.txt, w); auto bin = cast(ubyte[])str; foreach(b; bin){ file.writef(%b, b); } file.close(); } will do it? This is untested though
Re: Brighton [was Using D]
On Thursday, 21 August 2014 at 10:06:25 UTC, Iain Buclaw via Digitalmars-d wrote: On 12 Jul 2014 16:03, Iain Buclaw ibuc...@gdcproject.org wrote: On 12 July 2014 15:53, Russel Winder via Digitalmars-d digitalmars-d@puremagic.com wrote: On Sat, 2014-07-12 at 15:37 +0100, Iain Buclaw via Digitalmars-d wrote: […] I live literally 400 yards away from the burnt down west pier. Its a beautiful sight in the morning, come sun, rain, or fog. I hear they are building a 100 metre high elevator-to-nowhere in its place. Sad times... We lived for a while in Little Western Street. Even then the West Pier was crumbling and was closed a short while after we wandered up and down it one afternoon in glorious (very un-English) sun. […] I can give you my details, and can see where things go from there. Is evening meetings in London something you might be up for? Depending on who is involved and what constitutes the centre of mass, there is always the option of meeting in a pub in Clapham Junction – saves the extra haul across Central London. That sounds like at least the beginnings of a plan to me. My only way of getting around would be train due to lack of a car, or license. Hey Russel, Have you got anywhere with planning this? I'd be happy to help out with anything. Iain. Is this the beginnings of a London based DConf? (Note: That'd be great!)
Re: Learning D
On Monday, 25 August 2014 at 17:57:54 UTC, Ryan wrote: Anyone know MonoDevelop? Why is the Edit References context menu item missing. I have it at the top (Project-Edit References...) but when I click it nothing happens. Grrr. I couldnt figure it out either tbh (creating dub projects using MonoD) I just fire up a command line, go to my workspace folder, and do dub init project name here Then, in monoD, File - Open - C:\Path\To\Project\dub.json Then your good to go regarding MonoD.
Re: Can you explain this?
On Wednesday, 20 August 2014 at 20:18:15 UTC, Dicebot wrote: On Wednesday, 20 August 2014 at 20:01:05 UTC, Colin wrote: I see 3 distinct parts playing a role in my confusion: A) The 'is' keyword. What does it do when you have is(expression); http://dlang.org/expression.html#IsExpression It is a tool for type checking. It has many options but plain `is(T)` checks if `T` is a valid type and returns `true` if it is. `void` is considered a valid type. B) typeof( expression ); whats this doing? Particularly when the expression its acting on is a closure that returns nothing? (at least as far as I can see) typeof(() {}) evaluates to void: static assert(is(typeof(() {}) == void)); However, if any compilation errors happen inside the delegate, it evaluates to special invalid type which yield `false` when supplied to `is` expression. Thus `is(typeof(expr))` is a way to express a concept if `expr` compiles. Delegate is necessary to test statements because `typeof` only accepts expressions. C) The closure expression: (inout int = 0) { // Check to see if I can do InputRangy stuff... } Why is there a need for that inout int = 0 clause at the start of it? Now this is a really weird one. This is necessary for input ranges with `inout` functions to fit the trait because `inout` variables can be declared only inside `inout` functions. See this bug report for details : https://issues.dlang.org/show_bug.cgi?id=7824 It is one of surprising feature inter-operation cases you don't expect when designing features :) Thanks all, that explains it. It is weird looking code alright, but I guess it has its uses. I think I prefer the __traits(compiles,...) construct, as it is a bit more obvious as to what I'm checking. So will use that I suspect. Cheers!
Can you explain this?
Hi, I'm implementing some template checks on some types I'm using in a project, and went to phobos for some indications on how to use them. In std.range, I see this construct quite a bit: template isInputRange(R) { enum bool isInputRange = is(typeof( (inout int = 0) { R r = R.init; // can define a range object if (r.empty) {} // can test for empty r.popFront(); // can invoke popFront() auto h = r.front; // can get the front of the range })); } Can anyone explain the: is(typeof( (inout int = 0) {} ); section to me? It looks veryhacky. I see 3 distinct parts playing a role in my confusion: A) The 'is' keyword. What does it do when you have is(expression); B) typeof( expression ); whats this doing? Particularly when the expression its acting on is a closure that returns nothing? (at least as far as I can see) C) The closure expression: (inout int = 0) { // Check to see if I can do InputRangy stuff... } Why is there a need for that inout int = 0 clause at the start of it? Sorry for the long question! Thanks, Colin
Re: monodevelop mono-d versions
On Friday, 1 August 2014 at 09:12:49 UTC, sclytrack wrote: I can't seem to install mono-d. It always seems to want a newer version of MonoDevelop. I'm on Ubuntu 14.04 LTS and it has version 4.0.12 of MonoDevelop. Has anybody else got this to work with this version? I have this file called MonoDevelop.D-1.9.6.mpack Tools-Add In Manager-Install From File Select the MonoDevelop.D-1.9.6.mpack file. Press Open Dialog Window: The Following Packages will be Installed. D Language Binding v2.1.14 (In User Directory) Follow the info here: http://wiki.dlang.org/Mono-D Mono-d requires a MonoDevelop 5.0, which at the moment you have to build yourself on Ubuntu 14.04. You can find a precompiled version of it here: http://simendsjo.me/files/abothe (Which is also linked to in the wiki above) Hope that helps!
Re: monodevelop mono-d versions
On Friday, 1 August 2014 at 13:15:25 UTC, Dicebot wrote: On Friday, 1 August 2014 at 09:12:49 UTC, sclytrack wrote: I can't seem to install mono-d. It always seems to want a newer version of MonoDevelop. I'm on Ubuntu 14.04 LTS and it has version 4.0.12 of MonoDevelop. Has anybody else got this to work with this version? I have this file called MonoDevelop.D-1.9.6.mpack Tools-Add In Manager-Install From File Select the MonoDevelop.D-1.9.6.mpack file. Press Open Dialog Window: The Following Packages will be Installed. D Language Binding v2.1.14 (In User Directory) MonoDevelop has a terrible plugin API compatibility policy which makes Mono-D author only stick to latest released API version unless he wants to maintain dozen of different Mono-D builds :( In practice that means that you pretty much will never be able to use MonoDevelop version from repositories in Ubuntu - need to either build recent version on your own or use /opt/ bundle by simendsjo Which is a pity, as it's otherwise a pretty nice IDE. Still, vim with NERDTree + dub on the command line. What more do you need?
Re: [OT] Re: Redesign of dlang.org
On Tuesday, 29 July 2014 at 08:51:43 UTC, w0rp wrote: On Tuesday, 29 July 2014 at 08:27:40 UTC, Sönke Ludwig wrote: Am 29.07.2014 00:54, schrieb w0rp: On Monday, 28 July 2014 at 22:38:10 UTC, Sönke Ludwig wrote: I'll look at playing with the style of the documentation pages some more another evening. I've had a few ideas for improvements, and I obviously still need to include syntax highlighting. Is this the library which is being used on the live site now for that? https://code.google.com/p/google-code-prettify/ That plus some modifications to add D support. But my plan was to use server side highlighting using Brian Schott's lexer in the future. That's probably a good call. Were you thinking of discovering code blocks in pages and running the lexer on them to produce the formatted output? The other way around. DDOX and the Markdown processor would directly call the syntax highlighter on code sections they encounter. The result would then directly be written to the output range. Sounds good to me. This is starting to remind me of Inception. A D website running on vibe.d which invokes a D compiler to produce D documentation which produces syntax highlighting for D code blocks using a D lexer. Confusing sentence. Deception at it's finest. /sorry
Re: D port of docopt
On Sunday, 15 June 2014 at 17:35:59 UTC, Bob Tolbert wrote: In order to learn D, I've worked up a port of the docopt commandline parser (original in Python http://docopt.org). https://github.com/rwtolbert/docopt.d Since this is my first code in D, I apologize in advance for the mix if Python and C++ idioms. Since this is ported from Python, with the intention of staying compatible with future Python versions, some of that is expected, but I look for this as an chance to learn more about D. It is also a pretty useful way to write commandline interfaces. The included example that mimics the git CLI is pretty impressive. This is also my first submission as a dub project, so hopefully I got that right as well. Still needs more tests ported from Python, but it does pass the entire functional test suite for the current Python version. Regards, Bob Good going bob, I've actually been attempting to write this for the past while too :) Looks good, and should be very useful to the community!
Re: DConf 2014 Day 1 Talk 4: Inside the Regular Expressions in D by Dmitry Olshansky
On Thursday, 12 June 2014 at 09:17:45 UTC, Dmitry Olshansky wrote: 12-Jun-2014 03:29, Adam D. Ruppe пишет: On Wednesday, 11 June 2014 at 18:03:06 UTC, Atila Neves wrote: I wish I'd taken the mic at the end, and 2 days later Adam D. Ruppe said what I was thinking of saying: unit test and debug the CTFE function at runtime and then use it at compile-time when it's ready for production. Aye. It wasn't long ago that this wasn't really possible because of how incomplete and buggy CTFE was, you kinda had to do it with special code, but now so much of the language works, there's a good chance if it works at runtime it will work at compile time too. I was really surprised with CTFE a few months ago when I tried to use my dom.d with it... and it actually worked. That's amazing to me. But anyway, in general, the ctfe mixin stuff could be replaced with an external code generator, so yeah that's the way I write them now - as a code generator standalone thing then go back and enum it to actually use. (BTW I also like to generate fairly pretty code, e.g. indentend properly, just because it makes it easier to read.) And these couple of minutes are more like 30 minutes at a times. Worse yet unlike proper build system it doesn't keep track of actual changes (same regex patterns get recompiled over and over), at this point seamless integration into the language starts felling like a joke. Maybe a change to the compiler to write any mixin'd string out to a temporary file (along with some identifier information and the line of code that generated it) and at the next compilation time try reading it back from that file iff the line of code that generated it hasnt changed? Then, there'd be no heavy work for the compiler to do, apart from read that file in to a string.
Re: DConf 2014 Day 1 Talk 4: Inside the Regular Expressions in D by Dmitry Olshansky
On Thursday, 12 June 2014 at 12:31:09 UTC, Dicebot wrote: On Thursday, 12 June 2014 at 10:40:56 UTC, Colin wrote: Maybe a change to the compiler to write any mixin'd string out to a temporary file (along with some identifier information and the line of code that generated it) and at the next compilation time try reading it back from that file iff the line of code that generated it hasnt changed? Then, there'd be no heavy work for the compiler to do, apart from read that file in to a string. Compiler can cache return value of function that get called from inside mixin statement (for a given argument set). As CTFE is implicitly pure (no global state at compile-time) later generated code can be simply re-used for same argument set. Re-using it between compiler invocations is more tricky because it is only legal if generator function and all stuff they indirectly use have not changed too. Ignoring this requirement can result in nasty build issues that are only fixed by clean build. Too harmful in my opinion. Yeah, it quite dangerous I agree. I was only thinking of a solution to the problem above where a ctRegex is compiled every time, whether it was changed or not. I'm sure theres some way of keeping track of all dependent D modules filename, and if any of them have been changed in the chain, recalculate the string mixin. Only trouble with that is, there'd be a good chunk of checking for every mixin, and would slow the compiler down in normal use cases.
Re: Basics of calling C from D
On Wednesday, 11 June 2014 at 14:28:49 UTC, belkin wrote: On Wednesday, 11 June 2014 at 14:02:08 UTC, John Colvin wrote: On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Example: I have this C function that is compiled into a library //File: factorial.h int factorial(int n); //File: factorial.c #include factorial.h int factorial(int n) { if(n!=1) return n*factorial(n-1); } Question: How do I use it from D? //File: blah.d extern(C) int factorial(int n); //coincidentally identical to the C declaration. void main() { assert(factorial(3) == 6); } $ gcc -c factorial.c -ofactorial.o $ dmd blah.d factorial.o $ ./blah or $ gcc -c factorial.c -ofactorial.o $ ar rcs libfactorial.a factorial.o $ dmd blah.d -L-lfactorial $ ./blah Basically, you just translate the header files from C to D, then link to the C implementation. See http://code.dlang.org/packages/dstep for automatic translation of headers. This is great. How practical (reliable ) is it to translate a large and complex header file like oci.h ( the interface for Oracle's database API ) to D? You can do a lot of it by simply doing a find and replace in the file. For example, all C definitions of: unsigned char x become: ubyte x So a find an replace will do that for you quite easily. Other things like structs and typedefs are a bit more difficult to do with a find replace. All the info you need is here anyway: wiki.dlang.org/Bind_D_to_C
Re: Basics of calling C from D
On Wednesday, 11 June 2014 at 15:14:19 UTC, Colin wrote: On Wednesday, 11 June 2014 at 14:28:49 UTC, belkin wrote: On Wednesday, 11 June 2014 at 14:02:08 UTC, John Colvin wrote: On Wednesday, 11 June 2014 at 13:52:09 UTC, belkin wrote: Example: I have this C function that is compiled into a library //File: factorial.h int factorial(int n); //File: factorial.c #include factorial.h int factorial(int n) { if(n!=1) return n*factorial(n-1); } Question: How do I use it from D? //File: blah.d extern(C) int factorial(int n); //coincidentally identical to the C declaration. void main() { assert(factorial(3) == 6); } $ gcc -c factorial.c -ofactorial.o $ dmd blah.d factorial.o $ ./blah or $ gcc -c factorial.c -ofactorial.o $ ar rcs libfactorial.a factorial.o $ dmd blah.d -L-lfactorial $ ./blah Basically, you just translate the header files from C to D, then link to the C implementation. See http://code.dlang.org/packages/dstep for automatic translation of headers. This is great. How practical (reliable ) is it to translate a large and complex header file like oci.h ( the interface for Oracle's database API ) to D? You can do a lot of it by simply doing a find and replace in the file. For example, all C definitions of: unsigned char x become: ubyte x So a find an replace will do that for you quite easily. Other things like structs and typedefs are a bit more difficult to do with a find replace. All the info you need is here anyway: wiki.dlang.org/Bind_D_to_C And here: http://dlang.org/interfaceToC.html