Re: D: How do I pipe (|) through three programs using std.process?
On Saturday, 11 November 2023 at 17:29:14 UTC, BoQsc wrote: https://dlang.org/library/std/process.html How do I pipe (|) through three programs using std.process? https://dev.to/jessekphillips/piping-process-output-1cai Your issue with [Find, "Hello"] might be [Find, "\"Hello\""] But I'm not testing the theory...
Re: How do I install a package globally?
On Saturday, 11 November 2023 at 23:28:18 UTC, Trevor wrote: Thanks for the detailed reply. I guess what I'd like to do is not create a DUB package for every little project I work on. It seems like most modern languages require a package/dependency manager though. Being able to install libraries globally would avoid this but I can how that can cause it's own set of issues. It doesn't seem efficient in terms of bandwidth and hard disk space to have a new copy of a library for each project that uses it? Dub has a local cache, so multiple projects don't download and take up additional space. There is also the --system option if you want to share cache with other users on the machine.
Re: Define a new custom operator in D Language.
On Monday, 2 October 2023 at 18:34:13 UTC, BoQsc wrote: --- **This might lead to less gaps between math formulas and the implementation.** Or at the very least would allow to define a formula in the source code for further implementation and introduce some consistency. You could write a parser with pegged https://code.dlang.org/packages/pegged Could probably support unicode math symbols.
Re: Straight Forward Arrays
On Wednesday, 4 October 2023 at 10:51:46 UTC, dhs wrote: D and Go slices have advantages but can be confusing. I don't have a solution, but if anyone is interested, the relevant discussions about slice confusion in the Go community apply to D slices as well. I don't believe slice confusion in D is the same as God. https://he-the-great.livejournal.com/48672.html D manages to avoid stomping, while Go provides no clear ownership when slices are at play. And here is the slices explained https://dlang.org/articles/d-array-article.html
Re: Can we ease WASM in D ?
On Wednesday, 16 November 2022 at 22:51:31 UTC, bioinfornatics wrote: Dear community, I look some day ago to the D wasm page: -> https://wiki.dlang.org/Generating_WebAssembly_with_LDC And since then I ask myself can we at compile time convert a D code to an extern C code for wasm ? Thanks for your ideas Not exactly related, but this effort seemed to have gotten pretty far. But is old now https://code.dlang.org/packages/spasm
Re: to delete the '\0' characters
On Friday, 23 September 2022 at 08:50:42 UTC, Salih Dincer wrote: On Thursday, 22 September 2022 at 21:49:36 UTC, Ali Çehreli wrote: On 9/22/22 14:31, Salih Dincer wrote: If you have multiple '\0' chars that you will continue looking for, how about the following? It can be preferred in terms of working at ranges. But it isn't useful in terms of having more than one character and moving away from strings. For example: ```d auto data = [ "hello", "and", "goodbye", "world" ]; auto hasZeros = data.joiner("\0\0").text; // ("hello\0\0", "and\0\0", "goodbye\0\0", "world\0\0") assert(hasZeros.count('\0') == 7); assert(hasZeros.splitz.walkLength == data.length * 2 - 1); auto range = hasZeros.splitz; // ("hello", "", "and", "", "goodbye", "", "world") ``` SDB@79 You should be explicit with requirements. It was hard to tell if you original code was correct. ```d auto splitz(string s) { return s.splitter('\0') .filter!(x => !x.empty); } ```
Re: int | missing | absent
On Wednesday, 22 June 2022 at 01:09:22 UTC, Steven Schveighoffer wrote: There are 3 situations: 1. field in json and struct. Obvious result. 2. field in json but not in struct. 3. field in struct but not in json. I do a lot of reading JSON data in C#, and I heavily lean on optional over required. The reason optional is so beneficial is because I'm looking to pull out specific data points from the JSON, I have no use nor care about any other field. If I had to specify every field being provided, every time something changes, the JSON parser would be completely unusable for me. I do like the @extra assuming it allows reserializing the entire JSON object. But many times that data just isn't needed and I'd like my type to trim it.
Re: Basic SQLite Application
On Wednesday, 1 June 2022 at 15:40:43 UTC, harakim wrote: It's been a long time since I did any C development, and I have never done any on windows, but I thought I could statically link to the .lib at compile time and then I wouldn't need a dll. I'm fine with using a dll, but I don't know how to get the corresponding .bin. I'm guessing there is just a c header file. Is this a case where I would need to make bindings? In this case this lib is the dynamic bindings to the dll.
Re: How to get element type of a slice?
On Thursday, 19 August 2021 at 04:03:31 UTC, jfondren wrote: On Thursday, 19 August 2021 at 03:32:47 UTC, Jesse Phillips wrote: On Tuesday, 17 August 2021 at 12:33:03 UTC, Ferhat Kurtulmuş wrote: Hey, thank you again but, I don't want an instance of Point[] I need: alias T = Point[]; alias ElementOfPointSlice = // element type of T so, what's the problem? This passes tests: ```d import std.range : ElementType; struct Point { int x, y; } alias T = Point[]; alias ElementOfPointSlice = ElementType!(T); unittest { assert(is(ElementOfPointSlice == Point)); } ``` No issue just trying to give Ferhat a final answer to his question.
Re: std.stdio.File is throwing with the message of: "Access Violation"
On Thursday, 19 August 2021 at 13:47:56 UTC, Ruby The Roobster wrote: On Thursday, 19 August 2021 at 03:25:31 UTC, Jesse Phillips wrote: tell me what went wrong. I am using DMD 2.097.2 : ```d case WM_CREATE: //Executed on creation of the window... try { import core.stdc.stdio; FILE* file; file = fopen("file","r"); //NOTE: Replace 'file' with any file on the system... fclose(file); } catch(Throwable e) { MessageBoxA(null,cast(const(char)*)e.msg,"ERROR",MB_OK | MB_ICONERROR); } ``` This works, no Message Box should be displayed(Note: use 2.097.2, this is the version I am using, and I don't know about if this same bug happens on earlier versions). Now do this: ```d case WM_CREATE: try { import std.stdio; File file = File("file","r"); //NOTE: Again, replace 'file' with any file on the system... file.close(); } catch(Throwable e) { MessageBoxA(null, cast(const(char)*)e.msg, "ERROR", MB_OK | MB_ICONERROR); } ``` For me, this code generates the Message Box. Does this happen for you? I don't have a good means to run with this, but it does not look like what I suggested.
Re: How to get element type of a slice?
On Thursday, 19 August 2021 at 03:29:03 UTC, Jesse Phillips wrote: On Tuesday, 17 August 2021 at 12:33:03 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 17 August 2021 at 12:26:36 UTC, jfondren wrote: On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş wrote: [...] This one's not in std.traits: ```d import std.range : ElementType; struct Point { int x, y; } unittest { Point[] points; assert(is(ElementType!(typeof(points)) == Point)); } ``` Hey, thank you again but, I don't want an instance of Point[] I need: alias T = Point[]; alias ElementOfPointSlice = // element type of T Sorry last post was not complete. Not tested. ``` alias T = Point[]; alias ElementOfPointSlice = ElementType!(T); unittest { assert(is(ElementOfPointSlice == Point)); } ```
Re: How to get element type of a slice?
On Tuesday, 17 August 2021 at 12:33:03 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 17 August 2021 at 12:26:36 UTC, jfondren wrote: On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş wrote: [...] This one's not in std.traits: ```d import std.range : ElementType; struct Point { int x, y; } unittest { Point[] points; assert(is(ElementType!(typeof(points)) == Point)); } ``` Hey, thank you again but, I don't want an instance of Point[] I need: alias T = Point[]; alias ElementOfPointSlice = // element type of T ``` alias T = Point[]; unittest { Point[] points; assert(is(ElementType!(typeof(points)) == Point)); }
Re: std.stdio.File is throwing with the message of: "Access Violation"
On Wednesday, 18 August 2021 at 17:42:53 UTC, Ruby The Roobster wrote: All I did was try to access a file with a self-made library. It didn't work. I tried again directly from the main file. This is the code: ```d File file = File("E:\\Users\\User\\Desktop\\dutils\\test.spr","r"); //This file exists on my system, so it should work... file.close(); ``` Output(Given to me by a message box that display's Throwable.msg in it's body): Access Violation Is this a bug, or me being stupid? If it's the latter, than tell me what went wrong. I am using DMD 2.097.2 This is an error message you'll get from Windows if the file is locked (open by another application).
Re: General rule when not to write ;
On Tuesday, 18 May 2021 at 16:27:13 UTC, Alain De Vos wrote: After each } i write a ; And let the compiler tell me it is an empty instruction. What are the general rules where ; is not needed after a } This is a good question, I'm not sure I can provide a concise answer. In general you don't need a ; after } The ; is used to end a statement, but I don't know how to define that and distinguish it from an expression. The {} create a block of code, usually they will contain statements, so it would be common to see ; inside. The only real time I would expect a }; is when you're defining a lambda/delegate and assigning to a variable. auto Foo = X; If X is something that ends with } we will still expect a ; to end the statement.
Re: How to get output of piped process?
On Saturday, 6 March 2021 at 21:20:30 UTC, kdevel wrote: ```pipechain.d import std.stdio; import std.process; import std.conv; import std.array; import std.range; import std.algorithm; int main (string [] args) { auto p = pipe (); auto proc1 = spawnProcess (["cat"], stdin, p.writeEnd); auto q = pipe (); auto proc2 = spawnProcess (["cat"], p.readEnd, q.writeEnd); auto os = appender!string; q.readEnd.byChunk (4096).copy (os); auto res2 = wait (proc2); auto res1 = wait (proc1); stderr.writeln ("res1 = ", res1, ", res2 = ", res2); write (os[]); stderr.writeln ("fin"); return 0; } ``` AFAICS this is immune to SIGPIPE. Do I miss anything? I probably missed that from the documentation and was trying to make it work with pipeProcess.
Re: Is there any generic iteration function that stops at first match?
On Friday, 5 March 2021 at 02:13:39 UTC, Jack wrote: something like filter[1] but that stops at first match? are there any native functions for this in D or I have to write one? just making sure to not reinvent the wheel [1]: https://devdocs.io/d/std_algorithm_iteration#filter std.algorithm.searching.find To summarize. * filter.front * find.front * until * find The first two provide you data at the first match, `until` produces a range exclusive of the first match. If you just use find it will produce a range that starts at the first match, unlike filter the range includes everything and not just the matching data.
Re: How to get output of piped process?
On Wednesday, 17 February 2021 at 06:58:55 UTC, Jedi wrote: I an using pipeShell, I have redirected stdout, stderr, and stdin. I am trying to read from the output and display it in my app. I have followed this code almost exactly except I use try wait and flush because the app is continuously updating the output. (it outputs a progress text on the same line and I'm trying to poll it to report to the user) I think this post is going to answer your need. https://dev.to/jessekphillips/piping-process-output-1cai I haven't read all the replies, so maybe you have it working and this will benefit someone else.
Re: How can I use UFCS for a loop
On Tuesday, 26 January 2021 at 02:19:10 UTC, Tim wrote: On Tuesday, 26 January 2021 at 01:38:45 UTC, Q. Schroll wrote: On Tuesday, 26 January 2021 at 00:47:09 UTC, Tim wrote: Hi all, How can I change the following to a more D-like approach by using UFCS? double[3] result; Unless you have a good reason, use a slice and not a static array: double[] result; The result of std.array.array will be a slice anyway. Why would I need to use a slice instead of a static array? I'm using a static array in this instance because I have and underlying 3d vector with double[3] as its base type In that case, maybe this untested code double[3] result; res.readJson[].map!(to!double).copy(result[]);
Re: Reading files using delimiters/terminators
On Sunday, 27 December 2020 at 13:21:44 UTC, Rekel wrote: On Sunday, 27 December 2020 at 02:41:12 UTC, Jesse Phillips wrote: Unfortunately std.csv is character based and not string. https://dlang.org/phobos/std_csv.html#.csvReader But your use case sounds like splitter is more aligned with your needs. https://dlang.org/phobos/std_algorithm_iteration.html#.splitter But I'm not using csv right? Additionally, shouldnt byLine also work with "\r\n"? Right, you weren't using csv. I'm not familiar with the file terminater to known why it didn't work. byline would allow \r\n as well as \n
Re: Reading files using delimiters/terminators
On Sunday, 27 December 2020 at 00:13:30 UTC, Rekel wrote: I'm trying to read a file with entries seperated by '\n\n' (empty line), with entries containing '\n'. I thought the File.readLine(KeepTerminator, Terminator) might work, as it seems to accept strings as terminators, since there seems to have been a thread regarding '\r\n' seperators. I don't know if there's some underlying reason, but when I try to use "\n\n" as a terminator, I end up getting the entire file into 1 char[], so it's not delimited. Should this work or is there a reason one cannot use byLine like this? For context, I'm trying this with the puzzle input of day 6 of this year's advent of code. (https://adventofcode.com/) Unfortunately std.csv is character based and not string. https://dlang.org/phobos/std_csv.html#.csvReader But your use case sounds like splitter is more aligned with your needs. https://dlang.org/phobos/std_algorithm_iteration.html#.splitter
Re: question as to when a new command gets executed
On Wednesday, 11 November 2020 at 22:29:00 UTC, SealabJaster wrote: On Wednesday, 11 November 2020 at 22:10:38 UTC, WhatMeWorry wrote: Thanks. Would you or anyone reading this know if this is unique to D or does C++ also behave like this? Also, where is the memory, that new allocates? Is it in the heap (thought heap was available only at runtime) or some other place? (Certainly not the stack, right?) I'm pretty sure this is the way it works in C# as well. C# isn't compile time, it is more a pre-constructor generated by the compiler.
Re: Return values from auto function
On Saturday, 7 November 2020 at 15:49:13 UTC, James Blachly wrote: ``` return i > 0 ? cast(Result) Success!int(i) : cast(Result) Failure("Sorry"); ``` I don't know about the SumType but I would expect you could use a construction instead of cast. import std; alias Result = Algebraic!(int, string) ; void main() { auto x = true? Result("fish") : Result(6); }
Re: Return values from auto function
On Friday, 6 November 2020 at 15:06:18 UTC, Andrey Zherikov wrote: On Friday, 6 November 2020 at 14:58:40 UTC, Jesse Phillips wrote: On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov wrote: This issue seems hit the inability to implicitly convert custom types. May be it makes more sense to ask in a separate thread. The return type must be the same for all execution paths. Result!void is a different type from Result!int. You aren't passing a 'Result' because that doesn't exist as a type. To clarify my statement: Yes, Result!void and Result!int are different types but I couldn't find a way to implicitly convert one to another. Putting aside D not providing implicit conversion to custom types. I'm curious what your semantics would be. # Result!void => Result!int How does the type know it can convert to int, or string, or Foo? What does it mean for a void to be an int? # Result!int => Result!void If you have something, what does it mean to go to not having that something. Would you really want to implicitly lose that something?
Re: Return values from auto function
On Friday, 6 November 2020 at 20:05:36 UTC, Ferhat Kurtulmuş wrote: On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote: I have auto function 'f' that might return either an error (with some text) or a result (with some value). The problem is that the type of the error is not the same as the type of result so compilation fails. [...] Sounds like Andrei's "Expected". Here is an implementation for d. https://github.com/tchaloupka/expected Hmmm, I wonder how that is different from the idea of 'option'
Re: Return values from auto function
On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov wrote: On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote: You can't. Both return values have to have the same type, which means the failure function has to be able to return more than one type, which means it has to be a template. This issue seems hit the inability to implicitly convert custom types. May be it makes more sense to ask in a separate thread. The return type must be the same for all execution paths. Result!void is a different type from Result!int. You aren't passing a 'Result' because that doesn't exist as a type. Hopefully one of these captures a misunderstanding.
Re: Why is vibe.d json serializer/deserializer so complex?
On Saturday, 31 October 2020 at 22:42:20 UTC, James Blachly wrote: So I've been meaning to ask this as I have been learning Rust off-and-on recently for web development, and was impressed by the traits functionality. In particular, with traits and some agreed upon API, many packages are interchangeable in terms of various functionalities, including JSON serialization/deserialization. What would be the nearest analog facility in D -- supposing we could agree on a standard API -- to facilitate pluggable serializers? I am a big fan of asdf (and Steve, haven't tried iopipejson yet, but will do). It would be nice to not rewrite code to try a different serializer, and Rust is really neat in this regard. Well I was putting this together, but didn't want to attempt submission until I felt I would be able to put in the time for the review process https://github.com/JesseKPhillips/DIPs/blob/serialize/attribute/DIPs/1NNN-jkp.md
Re: I think Associative Array should throw Exception
On Thursday, 3 September 2020 at 15:12:14 UTC, Steven Schveighoffer wrote: int[int] aa; aa[4] = 5; auto b = aa[4]; How is this code broken? It's valid, will never throw, and there's no reason that we should break it by adding an exception into the mix. int foo() nothrow { return "1".to!int; } The following code is valid, will never throw, why does the compiler prevent it?
Re: I think Associative Array should throw Exception
On Tuesday, 1 September 2020 at 18:55:20 UTC, Steven Schveighoffer wrote: On 9/1/20 2:20 PM, Jesse Phillips wrote: Using RangeError is nice as it allows code to use array index inside `nothrow.` This is the big sticking point -- code that is nothrow would no longer be able to use AAs. It makes the idea, unfortunately, a non-starter. What is wrong with using `in`? I use this mostly: if(auto v = key in aa) { /* use v */ } I think that actually might be my point. If you need nothrow then this is what you need to do. For breaking nothrow code using the [] syntax, I'd say it is already broken because the behavior is to throw and the above is how you would check that it won't. The issue is, associative arrays throw an "uncatchable" error. Meaning code is written to catch the error (because it works). And correctly written `nothrow` code needs to use `in` to be properly nothrow.
I think Associative Array should throw Exception
This is going to be a hard one for me to argue but I'm going to give it a try. Today if you attempt to access a key from an associative array (AA) that does not exist inside the array, a RangeError is thrown. This is similar to when an array is accessed outside the bounds. ``` string[string] dict; dict["Hello"] // RangeError string[] arr; arr[6] // RangeError ``` There are many things written[1][2] on the difference between Exception and Error. * Errors are for programming bugs and Exceptions are environmental * Exceptions can be caught, Errors shouldn't be (stack may not unwind) * Exceptions are recoverable, Errors aren't recoverable * Errors can live in nothrow, Exceptions can't * Always verify input I don't have an issue with the normal array RangeError, there is a clear means for claiming your access is a programming bug. However associative arrays tend to have both the key and value as "input." Trying to create a contract for any given method to validate the AA as input becomes cumbersome. I would say it is analogous to `find` throwing an error if it didn't find the value requested. Using RangeError is nice as it allows code to use array index inside `nothrow.` But again, can we really review code and say this will be the case? We'd have to enforce all access to associative arrays to be done using `in` and checked for null. Then what use is the [] syntax? Is it recoverable? I would say yes. We aren't actually trying to access memory outside the application ownership, we haven't put the system state into a critical situation (out of memory). And a higher portion of the code could easily decide to take a different path due to the failure of its call. "if exceptions are thrown for errors instead, the programmer has to deliberately add code if he wishes to ignore the error." 1. https://stackoverflow.com/questions/5813614/what-is-difference-between-errors-and-exceptions 2. https://forum.dlang.org/thread/m8tkfm$ret$1...@digitalmars.com
Re: Installing D on Fresh Windows 10 machine is a pain
On Friday, 28 August 2020 at 14:36:57 UTC, rikki cattermole wrote: On 28/08/2020 3:59 AM, Jesse Phillips wrote: DMD installer still is unable to find "VS installed" One of the reasons for this is that the environment variables have not been updated. You need to restart to do this. This might have been the issue, I don't recall it requesting a restart and I don't know if I restarted when I had gotten it fixed (I don't think I did). I unistalled everything (VS and C++ redistributables) then restarted. Installed the C++ development environment with VS and restarted. Seems that it builds now.
Re: Installing D on Fresh Windows 10 machine is a pain
On Thursday, 27 August 2020 at 15:59:51 UTC, Jesse Phillips wrote: Upon compiling a 64bit hello world I get helloworld> dmd -m64 .\hello.d LINK : fatal error LNK1104: cannot open file 'libucrt.lib' Error: linker exited with status 1104 I solved this by either installing c++ development tools from Community or by switching my path to the 64bit DMD.
Installing D on Fresh Windows 10 machine is a pain
Installing D isn't new to me but I haven't really had to do a fresh install for awhile and come from a time when I was installing VS from 2010 and up. VS 2019 Professional is installed on the system. I have installed the C++ desktop development for VS. DMD installer still is unable to find "VS installed" I've also installed the C++ 2010 redistributables to try and use the MinGW install path. I've also utilized the developer command prompt --- Upon compiling a 64bit hello world I get helloworld> dmd -m64 .\hello.d LINK : fatal error LNK1104: cannot open file 'libucrt.lib' Error: linker exited with status 1104 This appears to have been a library moved around VS 2015 release, and I don't want to do the copying around solution the internet suggests. I understand that as a compiler it is important to support systems of an older nature and so updating to the latest C++ runtimes might hinder usage of D. It is just sad that at one point the install really did just take care of things and now it can't find things.
Re: Send empty assoc array to function
On Thursday, 9 July 2020 at 20:08:47 UTC, Anonymouse wrote: On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote: void foo(int[int] bar) { // ... } Is it possible to send an empty array literal? foo( [ 0 : 2 ] ) works foo( [] ) doesn't int[int] empty; foo(empty); works but it's two lines I always did foo((int[int]).init); Isn't that just 'null'. I want to make note that you cannot pass null, modify the aa, and expect the parent stack to see those changes. Since you aren't using a variable that is null you are fine.
Re: Why is there no std.stream anymore?
On Thursday, 18 June 2020 at 14:53:58 UTC, aberba wrote: On Tuesday, 12 December 2017 at 20:51:30 UTC, Steven Schveighoffer wrote: On 12/11/17 6:33 PM, Seb wrote: [...] Since iopipe was mentioned several times, I will say a couple things: [...] I should really try iopipe this time round. I think I avoided toying with it because the making conventions put me off. Don't remember about the docs and available examples though. I too was trying to utilize iopipe and asked questions earlier this year[1] and I made a file writer util[2]. I haven't really taken advantage of the power yet, though it does appear that be a really nice abstraction. 1. https://forum.dlang.org/thread/faawejguebluwodfl...@forum.dlang.org 2. https://gitlab.com/jessephillips/devarticlator/-/blob/master/source/util/file.d
Re: Why is there no range iteration with index by the language?
On Tuesday, 9 June 2020 at 23:53:16 UTC, Q. Schroll wrote: Is there any particular reason why std.range : enumerate is a thing Someone already mentioned dictionary. Consider that most ranges don't actually have an index. In this case you aren't actually asking to add indexes, but a count of iteration. For those ranges which do have indexing, what if the range is iterating from a location in the middle. Now you have an iteration count but not the true index. `enumerate` allows for specifying a starting number but this still isn't sufficient since a filter could easily jump to any index. Now none of this may come as a surprise to you, but having an iteration counter and an array index using the same api does open the door for confusion.
Re: Alpine support for D
On Wednesday, 10 June 2020 at 01:06:30 UTC, aberba wrote: On Tuesday, 9 June 2020 at 14:23:34 UTC, Jesse Phillips wrote: I notice that in the new release for Alpine Linux it mentions support for D. I was curious what was meant by this and thought someone here would know. Just high level, like druntime was ported or packages added to the repo? Tradionally you'd run D on something like Ubuntu, etc but Alpine is lightweight which is a good thing when building docker containers. Alpine uses a different C runtime musl?? among other things whilst D uses use libc. So I believe we now have bindings musl too to get D to work on Alpine. Thank you. So it sounds like there are D compiler packages, and you can use alpine to execute programs written in D.
Alpine support for D
I notice that in the new release for Alpine Linux it mentions support for D. I was curious what was meant by this and thought someone here would know. Just high level, like druntime was ported or packages added to the repo?
Re: Array fill performance differences between for, foreach, slice
On Wednesday, 1 April 2020 at 12:22:48 UTC, Adam D. Ruppe wrote: On Wednesday, 1 April 2020 at 06:48:09 UTC, Jacob Carlborg wrote: You have not enabled optimizations. You should compile with `-O -release -inline` to enable all optimizations. -release should *never* be used. You're trading memory safety and security holes for a few microseconds of execution time. Not worth the risk. It is nice that bounds checks remain in place when using release and the code is @safe.
Re: Converting Lua source to D
On Saturday, 7 March 2020 at 01:14:14 UTC, Jesse Phillips wrote: Now I should look at getting the CI up and Test failure fixed. Test failures were my local system and related to the stack overflow tests. I have the build pipeline up and running but hit a couple of snags. https://github.com/JesseKPhillips/lua/runs/493866555?check_suite_focus=true * Couldn't use dpp in the build because I couldn't install libclang-dev on the runner (ubuntu repository issue) * The compiler couldn't locate libphobos I think I'll be able to make use of dpp locally though.
Re: How to use sets in D?
On Friday, 7 February 2020 at 19:37:08 UTC, mark wrote: I am porting code from other languages to D as part of learning D, and I find I've used sets quite a lot. AFAIK D doesn't have a built-in set type or one in the std. lib. However, I've been perfectly successfully using int[E] where E is my ElementType, and adding with set[element] = 0. I mostly only need add, remove, iteration, and in, with uniqueness what I care most about. I know I could use bool[E] and set[element] = false, or I suppose container.rbtree. Would either of these--or something else built-in or in the std. lib.--be better? I think I've usually used the associative arrays, but I also think I tend to avoid using this approach but couldn't quite remember what I do instead. I believe I have started just using an array. arr ~= addMyData; arr.sort.uniq Then I make use of the algorithms here. https://dlang.org/phobos/std_algorithm_setops.html
Re: Converting Lua source to D
On Thursday, 5 March 2020 at 16:54:35 UTC, AB wrote: I am only guessing, but I think the problem is line 87. Arrays and slices in D contain a length field and thus do not need to be null terminated. The foreach at line 96 iterates on all valid indices and thus in the last iteration you call luaL_requiref(L, null, null, 1). Try changing static const luaL_Reg[] loadedlibs = [ ... {LUA_DBLIBNAME, &luaopen_debug}, {null, null} ]; to static const luaL_Reg[] loadedlibs = [ ... {LUA_DBLIBNAME, &luaopen_debug} ]; I knew I was blind, thank you. Segfault is gone. Now I should look at getting the CI up and Test failure fixed.
Converting Lua source to D
I am making an attempt convert Lua to D. This is less about the conversion and more about exploring the tooling to make it happen. I have chosen to do this file by file and attempting to start with linint. I wanted to make use of dpp, however I hit a segmentation fault and reduced dependency. https://github.com/JesseKPhillips/lua/blob/dpp/init/linit.d I wasn't able to get a core dump for debugging. Anyone willing to give some advice or solution? I have gone through a number of compilers and better. I have implemented a build pipeline but didn't incorporate the D portion at this time.
Re: iopipe: Writing output to std.io File
On Tuesday, 28 January 2020 at 16:09:55 UTC, Steven Schveighoffer wrote: Everything is pulled with iopipe, even output, so it's just a matter of who is pulling and when. Pushing is a matter of telling the other end to pull. -Steve That statement I think will be very helpful to me. The push would control the buffer, creating that value concept, where the buffer is flush which creates a pull, specified in the delegate. Pusher(buffer) <- put(content) An output range wrapper would provide a push interface which would fill in the buffer of the Pusher. When the buffer fills the range wrapper would ask to release which Pusher does by calling the delegate. Hopefully I'm following this correctly.
Re: iopipe: Writing output to std.io File
On Monday, 27 January 2020 at 18:12:40 UTC, Steven Schveighoffer wrote: Before I show you what to do, let me explain what the above actually does. 1. You constructed a buffer of characters. Good, this is the first step. 2. You used encodeText to convert the data to ubyte. Note that for char buffer, this basically is just a cast. Other encodings might do byteswapping. But you have done this step a bit early. At this point now, the window type is ubyte[]. You want to put data into the buffer as char[]. 3. You appended an outputPipe, which is a pass through while writing the data to a file (which is fed a stream of uninitialized data I think, so you probably got a file with garbage in it). Writing to this pipe's buffer is kind of pointless because the writing has already happened (pretty much all effects and actions performed on the buffer happen in the .extend function). What you need is to access the buffer for writing BEFORE encoding and streaming to the file. For this, you need the push [1] mechanism, which wraps up everything you want to happen to data you have written to the buffer into a lambda template: auto outputBuffered = bufd!char .push!(p => p .encodeText .outputPipe(output())); [1] http://schveiguy.github.io/iopipe/iopipe/valve/push.html I really feel like this is all very well thought out and clean, I don't appear to have a previous model to help visualize this output approach. Right now something like tee is coming to mind. Thank you for explaining with the answer.
Re: iopipe: Writing output to std.io File
On Monday, 27 January 2020 at 01:50:00 UTC, Jesse Phillips wrote: Just as I'm hitting send the part I'm missing clicked: I needed to add the text encoding because my buffer is `char` but File writes `ubyte` ```dlang auto output() { return std.io.File("somefile.txt", mode!"w").refCounted; } auto outputBuffered = bufd!char .encodeText // Missing This part .outputPipe(output()); } ``` Unfortunately this did not write a text file as I expected.
Re: iopipe: Writing output to std.io File
Just as I'm hitting send the part I'm missing clicked: I needed to add the text encoding because my buffer is `char` but File writes `ubyte` ```dlang /+ dub.sdl: name "iobuftofile" dependency "iopipe" version="~>0.1.7" dependency "io" version="~>0.2.4" +/ void main() { import iopipe.valve; import iopipe.textpipe; import iopipe.bufpipe; import iopipe.buffer; import std.io; import std.typecons; auto output() { return std.io.File("somefile.txt", mode!"w").refCounted; } auto outputBuffered = bufd!char .encodeText // Missing This part .outputPipe(output()); } ```
iopipe: Writing output to std.io File
I'd like to start utilizing IOPipe[1] more. Right now I have an interest in utilizing it for buffering output (actually I don't have a need for buffering, I just want to utilize iopipe) Looking through some different examples[2][3] I thought I would have something with this: ```dlang /+ dub.sdl: name "iobuftofile" dependency "iopipe" version="~>0.1.7" dependency "io" version="~>0.2.4" +/ void main() { import iopipe.valve; import iopipe.textpipe; import iopipe.bufpipe; import iopipe.buffer; import std.io; import std.typecons; auto output() { return std.io.File("somefile.txt", mode!"w").refCounted; } auto outputBuffered = bufd!char .outputPipe(output()); } ``` 1. https://code.dlang.org/packages/iopipe 2. https://github.com/schveiguy/iopipe/blob/master/examples/convert/convert.d#L13 3. https://youtu.be/9fzttyj4JCs?t=1210
Re: CTFE, string mixins & code generation
On Friday, 24 January 2020 at 16:21:48 UTC, Jan Hönig wrote: I am looking for a detailed explanation or showcase regarding CTFE and string mixins. I want to play with D a little bit regarding code generation. I would like to have a pseudo-AST, consisting of a few classes, to represent some calculation. Think of a loop, some statements, and expressions. To do that, I want to be certain that this AST can be computed and generated during compile-time, with CTFE and string mixins. Are there limitations regarding CTFE (GC, global variables, static variables, templates, )? Are there any limitations regarding string mixins (which are not already included int the CTFE limitations)? Back in the day I had written CTFE unittests for Protobuf generation. https://github.com/JesseKPhillips/ProtocolBuffer/blob/master/source/dprotobuf/generator/dlang.d#L740 IIRC the mixin was because it needed to compile in a D1 compiler. I don't recall why I needed these. https://github.com/JesseKPhillips/ProtocolBuffer/blob/master/source/dprotobuf/generator/dlang.d#L20
Re: Reading a file of words line by line
On Wednesday, 15 January 2020 at 19:50:31 UTC, mark wrote: I really do need a set for the next part of the program, but taking your code and ideas I have now reduced the function to this: WordSet getWords(string filename, int wordsize) { WordSet words; File(filename).byLine .map!(line => line.until!(not!isAlpha)) .filter!(word => word.count == wordsize) .each!(word => words[word.to!string.toUpper] = 0); return words; } This is also 4x faster than my version that used a regex -- thanks! Why did you use string.count rather than string.length? Your solution is fine, but also void main () { auto file = ["word one", "my word", "word"] ; writeln (uniqueWords(file, 4)); } auto uniqueWords(string[] file, uint wordsize) { import std.algorithm, std.array, std.conv, std.functional, std.uni; return file .map!(line => line.until!(not!isAlpha)) .filter!(word => word.count == wordsize) .map!(word => word.to!string.toUpper) .array .sort .uniq .map!(x => tuple (x, 0)) .assocArray ; }
Re: Problem with std.algorithm.iteration::substitute
You can also turn your function into a fold. auto searches = ["1", "2"]; writeln (searches.fold!((a, b) => a.substitute(b, "number").to!string)("come 1 come 2")) ;
Re: Problem with std.algorithm.iteration::substitute
On Saturday, 11 January 2020 at 17:10:02 UTC, Martin Brezl wrote: Hi, i have a function like this: ``` import std.algorithm.iteration : substitute; //... string replace(string content, string[] searches , string replace) { if(searches.empty) return content; auto result = content.substitute(searches.front,replace); for(size_t i=1; i < searches.length; i++) { searches.popFront(); result = result.substitute(searches.front,replace); } //... return "example return"; } ``` The issue is the double assigned result. auto result = content.substitute(searches.front,replace); result = result.substitute(searches.front,replace); `substitute` is going to return a template range typed off `content` then it uses that type to perform another substitution. `content` and `result` don't have the same type.
Re: D's equivalent List Comprehension
On Friday, 13 December 2019 at 15:35:24 UTC, mipri wrote: It might help your blog posts to use drepl in your examples: https://code.dlang.org/packages/drepl That is nice. Is there a web frontend? Rightnow I am using run.dlang.io from my phone. Prior to that I didn't compile anything.
D's equivalent List Comprehension
I had mentioned my take on list comprehension here: https://forum.dlang.org/post/qslt0q$2dnb$1...@digitalmars.com#post-ycbohbqaygrgmidyhjma:40forum.dlang.org However someone put together a more comprehensive tutorial of its power. So I took the opportunity to demonstrate the parallel in D. https://dev.to/jessekphillips/list-comprehension-in-d-4hpi D is like writing English. Wait I thought that was supposed to be Python, maybe I am thinking ruby.
Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 04:10:23 UTC, FireController#1847 wrote: I'm an extreme beginner to DLang (just started using it.. oh, an hour ago?), and I already can't figure out a, what I'd consider, fairly simplistic thing. This is my current code: module DTestApp1; import std.stdio; int main() { write("Press any key to continue..."); stdin.read(); return 0; } I am using Visual Studio to write it, and no matter what I do I cannot get it to work. I attempted to import std.stream;, but it said that while it could find the file, it cannot be read. Am I using the wrong function? For those who don't know, what I'm trying to do is pause the program until literally any key is pressed while in the console. execute(["pause"]);
Re: Which is the active fork in DFL gui library ?
On Sunday, 3 November 2019 at 16:48:52 UTC, Vinod K Chandran wrote: On Sunday, 3 November 2019 at 14:01:03 UTC, Jesse Phillips https://github.com/Rayerd/dfl @Jesse Phillips, Thank you for the reply. Does DWT is built upon Java's SWT ? I heard that SWT is somewhat slower in windows. Anyhow, what about the easiness of DWT ? Actually, i just want to make GUI for Windows only. I dont need a cross platform GUI. DTW is a translation of swt, I can speak to speed comparisons but I don't think you could apply anything out their related to comparing dfl and dwt. You can write windows only apps in dwt, don't compile for Linux, it uses native drawing.
Re: Which is the active fork in DFL gui library ?
On Saturday, 2 November 2019 at 20:01:27 UTC, Vinod K Chandran wrote: Hi all, I just found that DFL gui library very interesting. But after some searching, i can see that DFL is inactive and there is few other forks for it. So this is my question - Which fork is good for a gui development in windows platform. BTW, i just tested the gtkD and successfully compiled a hello app. How do i avoid the console window when compiling gtkD app ? Thanks in advance. The last one I used was from rayerd. But even that is behind. I switched my app to dwt. https://github.com/Rayerd/dfl
Re: Permission to Use Comments?
On Monday, 14 October 2019 at 11:14:50 UTC, Ron Tarrant wrote: Hi all, I've been thinking about how to take GtkDcoding to the next level and one idea is to use (favourable) comments made here on the forum to help promote the blog. So, since I'm not clear on copyright law and how it affects forum posts, I decided to ask... 1) Does anyone know how copyright laws stand regarding reuse of comments on a forum? 2) Does anyone object to me quoting them for promotional purposes? Pretty sure since this is a public forum, legally you just need to reference your sources (if even that). Asking permission is just polite. I don't say anything good, but you're free to use mine.
Simplifying process piping
As noted in this announcement, I started writing some basic tutorials for D. https://forum.dlang.org/post/efpyegvrezybdrmug...@forum.dlang.org At a post a week, I've got 10 weeks of backlog posts. One of these is a post on input output piping. https://github.com/JesseKPhillips/std.process-example/ I'm wondering if there are any thoughts for simplification. I don't mean simplify to perform the same end result, but is the threading and data copies as simple as they could be? Did I misrepresent anything?
Re: Question about generation of template functions
On Wednesday, 28 August 2019 at 20:56:25 UTC, Machine Code wrote: I was writing a recursive function that uses template, I thought it would generate the proper template function on the fly to match the type in the parameter but it seems to not so so and try to use the called function, resulting in the error: Error: function foo.serialize!(B).serialize(ref B output) is not callable using argument types (A) cannot pass argument output of type A to parameter ref B output Error: template instance `foo.serialize!(A)` error instantiating Code: void serialize(T)(ref T output) { import std.traits : hasUDA, getUDAs, isAggregateType; import std.meta : Alias; foreach(fieldName; __traits(derivedMembers, T)) { alias field = Alias!(__traits(getMember, T, fieldName)); static if(isAggregateType!(typeof(field))) { serialize!(typeof(field))(output); } static if(hasUDA!(field, Attr)) { enum className = getUDAs!(field, Attr)[0]; writefln("className = [%s]", className); } } } You're asking it to be the field type but passing it output. serialize!(typeof(field))(output);
Re: Executing a D script without an [extension in the filename] leads to an error
On Friday, 1 March 2019 at 11:38:51 UTC, BoQsc wrote: "And indeed rdmd won't call your script if it doesn't have the proper extension." Then why does Dlang Tour includes shebang: #!/usr/bin/env rdmd Instead of the one you mentioned, that is fool proof. (#!/bin/dmd -run) Is that an error/mistake in Dlang Tour guide? You may want to change that too: #!/bin/dmd -i -run DMD doesn't automatically compile imported files (at least not until -i came along), rdmd existed to solve that problem... I don't know what value it brings with the -i switch existing.
Re: Am I missing with ref in this code?
On Thursday, 24 January 2019 at 15:28:19 UTC, Suliman wrote: I am doing very small link-checker. Here is' code https://run.dlang.io/is/p8whrA I am expecting that on line: writefln("url: %s, status: %s", url.url, url.status); I will print link and it's status. But I am getting only: url: http://127.0.0.1:8081/hck, status: url: http://127.0.0.1:8081/hck2, status: url: http://127.0.0.1:8081/hck3, status: It's seems that I missed something with refs? Could you help me find error? You're writing asynchronous code and expecting it to process synchronized. Just make a synchronous call. If you need async use message passing with concurrency, probability on each call to the url so you can do the slow operations in parallel.
Re: Co-developing application and library
On Saturday, 5 January 2019 at 13:01:24 UTC, Russel Winder wrote: Dub seems to have the inbuilt assumption that libraries are dependencies that do not change except via a formal release when you developing an application. Clearly there is the workflow where you want to amend the library but not release as a part of developing an application. Does Dub have a way of doing this, I haven't been able to infer one to date. But I am a beginner at Dub. I use submoduals in git and then subpackage in dub. That doesn't help with packages I don't maintain but want to contribute back to because I don't submodual those in. I actually wish submoduals got more attention and was the expected way to manage dependencies.
Re: 9999999999999999.0 - 9999999999999998.0
On Sunday, 6 January 2019 at 00:20:40 UTC, Samir wrote: [1] https://news.ycombinator.com/item?id=18832155 [2] https://en.wikipedia.org/wiki/IEEE_754 Since you got your answer you may also like http://dconf.org/2016/talks/clugston.html
Re: dub doesn't work with dmd 1:2.082.0-1.0?
On Friday, 14 September 2018 at 05:41:41 UTC, rmc wrote: I do wonder if `dmd` by itself on the command line works. Could it be some sort of 32 bit bug in the latest release of dmd? Relating to argc/argv. "source/dub/compilers/compiler.d(127)" That doesn't look like DMD source code.
Re: dub doesn't work with dmd 1:2.082.0-1.0?
On Monday, 10 September 2018 at 09:23:19 UTC, SuperPrower wrote: dub was working nice until I updated my system (I run ArchLinux32) just now. dmd was updated from version 1:2.081.2-1.0 to 1:2.082.0-1.0 (according to pacman package manager). After that, I couldn't invoke dub for anything. Here is the attempt to run `dub --vverbose`: Can you find /usr/bin/dmd or run dmd?
Re: [Unit tests] Mocking D objects
On Wednesday, 22 August 2018 at 08:33:36 UTC, Andrey wrote: Hello, I know that D has build-in unit tests. If so, what mechanism D provides for mocking objects? I'd like to pose the question, what are you testing. This looks like you are testing that your mocked object returns 10. I usually try to make functions more pure like.
Re: D need an ORM library!
On Monday, 20 August 2018 at 02:30:16 UTC, binghoo dang wrote: hi, I thinks D need an ORM library for Sqlite/Mysql/PostgreSQL, entity currently support all the three targets, but entity's API is too complex and cumbersome for using. Is there a more light-weight and simpler implementation like ActiveAndroid ? Thanks! --- Binghoo Dang There are a number of things out there, but personally don't know there state or simplicity. 2016 there was a talk: http://dconf.org/2016/talks/nowak.html But personally I preferred this one: http://dconf.org/2016/talks/smith.html https://github.com/cruisercoder/dstddb
Re: Dependency injection pattern
On Sunday, 13 May 2018 at 07:42:10 UTC, Suliman wrote: Could anybody give small example of Dependency injection pattern? I googled about it, but found only C# examples and I am not quite sure how to use them. Also I would like get some explanation/comments for code. Here is a quick example of the difference, myProgram.execute utilizes a database connection. dInjection.execute utilizes a dependency injected database connection. class dbConnection {} class myProgram { void execute() { auto db = new dbConnection(); //... } } class dInjection { void execute(dbConnection db) { //... } } What you should notice from the first execute function is that the dependency, in this case dbConnection, is created as part of the application execution. While the second the dependency is declared at the function's arguments allowing the caller to inject the needed dependency. This could go a step further and accept an interface for DB connections, but is not necessary to meat dependency injection. Dependency injection also applies to magic numbers. enum maxProcessingTime = 3582; If this were declared inside a function rather than taken as a parameter, then the function would not correctly use dependency injection. Additionally, you could inject the dbConnection as part of the class constructor: -- class preInjection { dbConnection db; this(dbConnection data) { db = data} void execute() { //... } } -- Now I think what trips a lot of people up is that frameworks are created to help you do this. They try to make it easy to define all your dependencies in a single location and then you request the object you need and the DI framework will do whatever it needs to for building that object.
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 18:38:10 UTC, BoQsc wrote: Tested with these versions so far, and had all the same errors: C:\Users\Vaidas>dmd --version DMD32 D Compiler v2.079.1 C:\Users\Vaidas>dub --version DUB version 1.8.1, built on Apr 14 2018 C:\Users\Vaidas>dmd --version DMD32 D Compiler v2.080.0 C:\Users\Vaidas>dub --version DUB version 1.9.0, built on May 1 2018 Well I'm pretty sure the primary reason for my success is having Visual Studio installed and using the ms linker.
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 16:34:53 UTC, BoQsc wrote: On Tuesday, 8 May 2018 at 16:18:27 UTC, bachmeier wrote: On Tuesday, 8 May 2018 at 12:13:56 UTC, BoQsc wrote: This is the code example, that was presented on the https://dlang.org frontpage: Maybe that isn't the best choice of beginner example if even the D experts can't figure out how to get it to run. Might be a bug, I have already reported it and saw some bug duplicates like mine. However, since 2017 report, it seems to be - still not going well. If I have a chance I'll try to download latest dlang distribution and install on a completely clean Windows 10 Operating system. But I'm not hoping for any luck, but still in need of try trial. So I gave this a try and this command worked: >dub --arch=x86_64 --single start_minimal_server.d I'm on Windows 8 with All the visual studio versions installed DMD32 D Compiler v2.080.0-beta.1 DUB version 1.9.0-beta.1, built on Apr 17 2018
Re: dxml behavior after exception: continue parsing
On Monday, 7 May 2018 at 22:24:25 UTC, Jonathan M Davis wrote: I've been considering adding more configuration options where you say something like you don't care if any invalid characters are encountered, in which case, you could cleanly parse past something like an unescaped &, but you'd then potentially be operating on invalid XML without knowing it and could get undesirable results depending on what exactly is wrong with the XML. I haven't decided for sure whether I'm going to add any such configuration options or how fine-grained they'd be, but either way, the current behavior will continue to be the default behavior. - Jonathan M Davis I'm not going to ask for that (configuration). I may look into cloning dxml and changing it to parse the badly formed XML.
Re: dxml behavior after exception: continue parsing
On Monday, 7 May 2018 at 19:46:00 UTC, Jesse Phillips wrote: So I have an XML like document which fails to adhere completely to XML. One of these such events is that & is used without escaping. My observation is that after the exception it is possible to move to the next element without issue. Is this something expected and will be maintained? try { range.popFront(); } catch (Exception e) { range.popFront; } Ok so this worked when inside a quoted attribute value but not a normal tag body. Clearly I'm not parsing valid XML so I'm going outside the bounds of valid parameters. But rather than writing a custom parser to handle this, it would be nice to have: try { range.popFront(); } catch (Exception e) { range.moveToNextTag(); } Which would make front a MalformedParse containing the content up to the next <.
dxml behavior after exception: continue parsing
So I have an XML like document which fails to adhere completely to XML. One of these such events is that & is used without escaping. My observation is that after the exception it is possible to move to the next element without issue. Is this something expected and will be maintained? try { range.popFront(); } catch (Exception e) { range.popFront; } As an aside, here is a snippet for skipping over the BOM since dxml doesn't expect the BOM to be there: import std.encoding; import std.algorithm; auto fileContent = cast(ubyte[])read(file); if(getBOM(fileContent).schema != BOM.none) fileContent.skipOver(getBOM(fileContent).sequence);
Re: Is HibernateD dead?
You should get a hold of Vadim Lopatin and see if he would give you commit rights to the main repo. There was a great article I can't find by someone who would add contributors if they made good pull requests. It helped to keep his work living on and didn't need to keep involved. So I push for people to follow this model (remove contributors if it isn't working out.
Re: Windows to Linux Porting - timeCreated and timeLastAccessed
On Monday, 7 May 2018 at 14:31:23 UTC, Jesse Phillips wrote: I wouldn't use time created. It can be newer than last modified this wholey inacurate. Last accessed could be a much more appopriate choice if trying to determine what is important. Sorry, to answer your actual question, I do believe that using the OS version specification to select the function is correct.
Re: Windows to Linux Porting - timeCreated and timeLastAccessed
On Friday, 4 May 2018 at 11:49:24 UTC, Vino wrote: Hi All, Request your help, I have a D program written on Windows platform and the program is working as expected, now i am trying to port the same program to Linux, my program use the function "timeCreated" from std.file for Windows hugely where as in Linux we do not have the same function hence planned to use the function "timeLastAccessed" from std.file, so what is the best approach to port the program. I tried the below code but not working, so can you one please guide me on the right method to port the program to linux, below is the example code. I wouldn't use time created. It can be newer than last modified this wholey inacurate. Last accessed could be a much more appopriate choice if trying to determine what is important.
Re: Get files from directory sorted by name
On Thursday, 26 April 2018 at 16:59:45 UTC, Dr.No wrote: On Wednesday, 25 April 2018 at 19:25:11 UTC, Jesse Phillips wrote: On Wednesday, 25 April 2018 at 17:34:41 UTC, Dr.No wrote: Is there something implemented already to get the files from directory by name using D or I'm on my own and I have to write it myself? I didn't find how do that with dirEntries() I want to add that sorting can be done, if you just call std.algorithm.sort you'll find that file names with numbers in them will be sorted as a well strings. Newfile1.txt Newfile10.txt Newfile2.txt I've had realized that then implemented natural sort Thats what it was called. Looks like Rosetta Code has an implementation. https://rosettacode.org/wiki/Natural_sorting#D
Re: Get files from directory sorted by name
On Wednesday, 25 April 2018 at 17:34:41 UTC, Dr.No wrote: Is there something implemented already to get the files from directory by name using D or I'm on my own and I have to write it myself? I didn't find how do that with dirEntries() I want to add that sorting can be done, if you just call std.algorithm.sort you'll find that file names with numbers in them will be sorted as a well strings. Newfile1.txt Newfile10.txt Newfile2.txt
Re: unittests, dub and libraries
On Wednesday, 28 March 2018 at 21:29:22 UTC, Jesse Phillips wrote: And a note on the reverse, if you have an executable project $ dub test won't build in the app.d file since it contains main and dub test wants to avoid running your main function. For reference: https://github.com/dlang/dub/issues/1118
Re: unittests, dub and libraries
On Wednesday, 28 March 2018 at 03:07:23 UTC, Jonathan M Davis wrote: Run dub test The problem is that an executable needs a main, and a library doesn't have one, whereas when you're testing a library, you need an executable. So, a main must be inserted - e.g. with the -main flag to dmd. Just building the unittest build doesn't insert one. However, dub test _does_ deal with that for you. - Jonathan M Davis And a note on the reverse, if you have an executable project $ dub test won't build in the app.d file since it contains main and dub test wants to avoid running your main function.
Re: How to use an associative array with array values.
On Wednesday, 21 March 2018 at 18:31:29 UTC, tipdbmp wrote: I see. I guess the other would be: { int[8192] bar; int[8192][string] foo; foo["a"] = bar; foo["a"][8191] = -1; } https://run.dlang.io/is/AK2X2t Are you looking to use static arrays or dynamic? You can't use the new keyword if it static.
Re: Is there any web browser control in D Lang to display html file ?
On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote: I creating one simple desktop application using dlang. I need to display some html file in my desktop application. How can make it works ? I believe on is available in dtw. http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fbrowser%2FBrowser.html
Re: Vibe.d rest & web service?
On Wednesday, 7 February 2018 at 17:04:13 UTC, Nicholas Wilson wrote: Is it possible to have some urls routed to serve content and some to receive JSON in the same class? This seems unlikely to me, the function signature doesn't provide a way to distinguish between REST and not. I'm also not sure it is necessary, you can certainly have multiple class which provide REST and Web endpoints. You can even dynamically build routes within a route.
Re: invalid or corrupt file: duplicate COMDAT / Previous Definition Different
On Wednesday, 10 January 2018 at 19:32:28 UTC, Anonymouse wrote: /usr/bin/ld: Warning: size of symbol I think your case is this bug: https://issues.dlang.org/show_bug.cgi?id=15324 Another COMDAT error is: https://issues.dlang.org/show_bug.cgi?id=16687
Re: git workflow for D
I'm going to answer with something that others may not agree with, maybe they can enlighten me, but let me first get a generic principle of git and answer some questions. Git has 2 types of branches, local branches (you know them as just branches) and remotes (which have their own local branches). I say this to remove the confusion with having an original repository, a forked repository, and a cloned repository. When it comes to interactions with these repositories the only difference from your local branches is that you can't interact directly with them (i.e. you can't commit to them) and the interactions require specifying the remote location of the branch. Some of your other questions are about GitHub and Forking. Git doesn't know what a fork is, but GitHub ties a pull request to a branch. This means you can update/change your pull request by updating/changing your branch. From that you should realize each pull request needs its own branch. Back to git remotes. I'm sure you're aware of the commonly named "origin" remote and possible the second common "upstream." When you're dealing with many remotes your local branches can get complicated. For example many people utilize 'master' as a *tracking* branch to "origin" well, "upstream" if there is one. I'm to the point that in this situation my recommendation is just delete your 'master' branch both local and "origin." Don't worry you can bring it back if you need it, you won't need it. Here is the thing, you already have two, maybe 3 master branches 'master' 'origin/master' 'upstream/master' these are local branches (they are special in that you can't commit to them). And these are also your true tracking branches, whenever you fetch/pull from your remote these branches are updated, they will always reflect the branch of the remote and they will never conflict during updates. You can always create your own master $ git branch master upstream/master I want to note that 'origin/master' is different from such commands as `$ git push origin master` because in the first you are referring to a local branch and the second you reference your remote followed by your remotes local branch (actually I could be wrong here because the full syntax is `$ git push origin master:master` where the left: is your local and :right is the remote local branch [and note that `push origin :master` would delete the remote master branch because you're push no branch to it.). I hope that this along with answers other have given will help you to answer all of your questions.
Re: Object oriented programming and interfaces
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: Hi! I defined an interface: interface Medoid { float distance( Medoid other ); uint id() const @property; } and a class implementing that interface: class Item : Medoid { float distance( Item i ) {...} uint id() const @property {...} } The compiler says: Error: class Item interface function 'float distance(Medoid other)' is not implemented Is there a way to implement the Item.distance() member function taking any object whose class is Item? I think everyone here has missed the reason. The problem is that a derived type can do more, the interface only allows for two method calls while the class could theoretically do more. If the compiler allowed the class it would let you access functions and members not available to the interfaces, and the function would still be passed a Medoid. You could make a cast within your function, but then you're still really not handling the interface but that at least would be clear in the code rather than the compiler hiding it by ignoring the problem.
Re: Basic questions about D lang?
On Tuesday, 28 November 2017 at 13:39:11 UTC, Jayam wrote: Can we compile our program to multi program ? Based on your C# reference you must be referring to the "Mixed Platform" build option. No, that is a .NET thing and D is not on .NET (that project has died). D requires a more traditional approach to multiple platforms, you'll need to write your code with the needs of your supported platforms in mind. Luckily in pure D this is like no work, but when you interface to C/C++ libraries you'll hit sizes of types and structures changing almost randomly (ok it isn't that bad).
Re: "version" private word
On Tuesday, 31 October 2017 at 14:25:19 UTC, Igor Shirkalin wrote: On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips wrote: On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote: Hello! You goal should be to describe features. Version x86 ... Version = I can stand on my head ... pardon? Sorry I hate writing code on mobile. You can create an arbitrary version by assigning a symbol to it, use that symbol to describe a feature, assign that symbol for each architecture that supports it. Then write code in a version block of that symbol.
Re: "version" private word
On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote: Hello! You goal should be to describe features. Version x86 ... Version = I can stand on my head ...
Re: CSV with empty values for integer fields
Not really you'll need to parse it out as a string and do the conversion later. It probably would be good to support nullable!int pretty sure it doesn't currently.
Re: Assert and undefined behavior
On Saturday, 14 October 2017 at 09:32:32 UTC, Timon Gehr wrote: The compiler can easily prove that the value of data.length does not change between the two points in the program. According to the specification, the behavior of the program is undefined in case the assertion fails, not just the behavior of the program after the assertion would have failed if it had not been removed. You are right, in this example proving that there is no change between the condition and the assert is easy and possible. In fact there was an example of this in C I think with a function pointer which was uninitialized. Where the optimizer identified that there was only one valid function which could have been assigned and made lowered the indirect call to a direct one. My statement was more around if the compiler/optimizer can't determine the value void test(int[] data, bool goboom) { if (data.length == 0) { writeln("Not enough data!"); } else { control_nuclear_reactor(data); } assert(goboom); } The optimizer can generate code to match: void test(int[] data, bool goboom) { if(!goboom) { launch_nuclear_missile(); return; } if (data.length == 0) { writeln("Not enough data!"); } else { control_nuclear_reactor(data); } } Also, UB can and does sometimes mean that the program can execute arbitrary code. It's called "arbitrary code execution": https://en.wikipedia.org/wiki/Arbitrary_code_execution That article is about attacks not optimizers.
Re: Assert and undefined behavior
On Thursday, 12 October 2017 at 15:37:23 UTC, John Burton wrote: This is an example of what I mean :- undefined what it is meant to do anyway, so the compiler can "optimize" out the if condition as it only affects the case where the language doesn't define what it's supposed to do anyway, and compiles the code as if it was :- void test(int[] data) { control_nuclear_reactor(); } Yeah the C/C++ community/haters love to talk about all the code the compiler can inject because of undefined behavior. But that is not what it means. The compiler does not know the value of data.length so it could not make such a transformation of the code. Now had the assert been written before the if, you're telling the compiler some properties of data.length before you check it and it could make such optimizations. The point is assert tells the compiler something it can use to reason about its job, not that it can insert additional runtime checks to see if you code is invalid an then add new jumps to execute whatever the hell it wants.
Re: CSV crash: "Quote located in unquoted token"
On Friday, 13 October 2017 at 08:53:12 UTC, Dmitry wrote: Hi there. When I load csv, it crashes ("Quote located in unquoted token") on lines with quotes, like this: ResourceNode_RemoveFromView_Confirm,You are about to remove ""{0}"" from view ""{1}"". Continue?,You are about to remove ""{0}"" from view ""{1}"". Continue?,,Resource Tree - confirmation of removal from the current view The problem is that a generic CSV parser can't tell what the expected data should look like if the data doesn't follow defined rules. std.csv is not filled with custom parsing rules. You can use Malformed.ignore[1], but your data will come out like: You are about to remove ""{0}"" from view ""{1}"" This would leave you needing to modify the "". 1. https://dlang.org/phobos/std_csv.html#.Malformed
Re: Undo?
On Thursday, 12 October 2017 at 02:18:49 UTC, Mr. Jonse wrote: A simple(incomplete) undo system. I'd think that for D you'd want to do type wrapping where a new type is created which saves changes and can manage an Undo tree. __gshared Data data = new Data(); auto undoable = Undo!data undoable.x = 5; assert(data.x == 5); undoable.undo(); assert(data.x == 0); undoable.redo(); assert(data.x == 5); This would be done by monitoring the members which contain storage, available with: https://dlang.org/phobos/std_traits.html#Fields This is of course specific to a single object and plan for handling order across multiple objects along with creating an "Edit" where many data points could change and be undone with a single undo.
Re: Does D have an equivalent to C#'s String.IsNullOrWhiteSpace?
On Thursday, 12 October 2017 at 18:17:54 UTC, Adam D. Ruppe wrote: On Thursday, 12 October 2017 at 18:11:55 UTC, Nieto wrote: Does D have an equivalent to C#'s String.IsNullOrWhiteSpace() in the standard library? import std.string; if(str.strip().length == 0) { // is null, empty, or all whitespace } Also if(str.strip().empty) std.array.empty() works essentially the same as IsNullOrEmpty()
Re: For fun: Expressive C++ 17 Coding Challenge in D
On Wednesday, 4 October 2017 at 15:26:02 UTC, Ali Çehreli wrote: On 10/04/2017 02:04 AM, Biotronic wrote: ... Hey where is the list of features used e.g: ranges, ufcs...
Re: Looking for a mentor in D
On Tuesday, 3 October 2017 at 06:54:01 UTC, eastanon wrote: I would like to choose D as my go to language and to do that I realise I need a mentor, someone who will walk and guide me and not get irritated by basic questions. I am pretty much a DIY person, so don't worry about mundane issues. I want to have someone with whom I can discuss some practical choices and algorithms. I am a self-taught programmer and never took CS classes. I am good in R, Python and Ruby. Please let me know if you would like to be a D mentor. I haven't seen anyone blasted for asking programming questions on these forms as long as they were using D to solve them. Though maybe that wouldn't be true if the forum was consumed by such questions. Feel free to shoot me an email though jesse.k.phill...@gmail.com and we can see how it goes.
Re: Vibe.d using Windows Certificate binding, possible?
On Wednesday, 4 October 2017 at 03:39:22 UTC, rikki cattermole wrote: On 04/10/2017 3:54 AM, Jesse Phillips wrote: https://msdn.microsoft.com/en-us/library/windows/desktop/cc307220(v=vs.85).aspx "Application program source files include the Http.h header file to access function prototypes and structure definitions for the HTTP Server API. Developers can use the Httpapi.lib library file to build applications that use the HTTP Server API. At runtime, applications link to the Httpapi.dll." So no, vibe.d can't work with it. This a special snow flake feature from 2k3 server days. Thank you, and it looks like core.sys.windows doesn't have this header file defined either. And now I've learned something new about MSDN docs.
Re: Vibe.d using Windows Certificate binding, possible?
On Tuesday, 3 October 2017 at 23:29:49 UTC, rikki cattermole wrote: On 03/10/2017 4:52 PM, Jesse Phillips wrote: I'm pretty sure this isn't possible, but maybe someone understands Windows better. Windows provides a means no bind a certificate to a port using netsh.exe. This means (at least for standard Windows networking calls) connections to that port will be given the bound cert. The Vibe.d documents state that a Certificate chain and key needs to be provided. I'm pretty sure that the port binding requires very specific Network API calls, possible .NET only. Can any confirm or deny? Perhaps you could reference the command (aka the args with an example)? Otherwise, its a lot harder to figure out what it is doing under the hood. Here is the command docs https://msdn.microsoft.com/en-us/library/windows/desktop/cc307220(v=vs.85).aspx
Vibe.d using Windows Certificate binding, possible?
I'm pretty sure this isn't possible, but maybe someone understands Windows better. Windows provides a means no bind a certificate to a port using netsh.exe. This means (at least for standard Windows networking calls) connections to that port will be given the bound cert. The Vibe.d documents state that a Certificate chain and key needs to be provided. I'm pretty sure that the port binding requires very specific Network API calls, possible .NET only. Can any confirm or deny?