Re: Article: Writing Julia style multiple dispatch code in D
On Friday, 25 August 2017 at 20:54:05 UTC, jmh530 wrote: See below. I haven't implemented the random variables yet, but otherwise it seems to be working well. There is some trickiness with deprecated stuff that I had to hard code, but other than that it's pretty generic. Also, I think it is ignoring my check to only include public/export stuff. Not sure why that is. module distribAlt; ... Wow, I didn't realise that you'd go off and work on it. You need to start a package for it! I'll bookmark this one as a little reminder of mixin techniques.
Re: D as a Better C
On Friday, 25 August 2017 at 23:13:53 UTC, Mengu wrote: On Friday, 25 August 2017 at 00:24:14 UTC, Michael V. Franklin wrote: On Thursday, 24 August 2017 at 19:21:31 UTC, Walter Bright wrote: [...] Great! I look forward to seeing improvements and hope to help. [...] i believe that should be an opt-out. what about newcomers? will they have to learn how to link std lib? No, because the dmd.conf that is delivered with the toolchain is already ready to go with reasonable defaults; and not hard-coded into the compiler. Advanced users can update dmd.conf or point the compiler to a different dmd.conf as they choose. Mike
Re: D as a Better C
On Friday, 25 August 2017 at 00:24:14 UTC, Michael V. Franklin wrote: On Thursday, 24 August 2017 at 19:21:31 UTC, Walter Bright wrote: [...] Great! I look forward to seeing improvements and hope to help. [...] i believe that should be an opt-out. what about newcomers? will they have to learn how to link std lib?
Re: Article: Writing Julia style multiple dispatch code in D
On Friday, 25 August 2017 at 16:01:27 UTC, data pulverizer wrote: Your wrapping strategy looks sensible though I would probably generate them all using string mixins. See below. I haven't implemented the random variables yet, but otherwise it seems to be working well. There is some trickiness with deprecated stuff that I had to hard code, but other than that it's pretty generic. Also, I think it is ignoring my check to only include public/export stuff. Not sure why that is. module distribAlt; private template isMemberOf(alias T, string x) { import std.traits : hasMember; enum bool isMemberOf = hasMember!(T, x); } private void hasMemberCheck(alias T, string x)() { static assert(isMemberOf!(T, x), T.stringof ~ " must have " ~ x ~" member to call " ~ x ~ " function"); } private string genStructInternals(string funcName, string structName)() { import dstats.distrib; import std.array : appender; import std.algorithm.searching : endsWith; enum spaces = ""; auto aliasBuf = appender!string(); auto importBuf = appender!string(); enum string invName = "inv" ~ structName; enum bool anyPDForPMF = false; importBuf.put(spaces); importBuf.put("import dstats.distrib : "); foreach(member; __traits(allMembers, dstats.distrib)) { static if (__traits(getProtection, member) == "public" || __traits(getProtection, member) == "export") { import std.algorithm.searching : startsWith, findSplitAfter; import std.string : toLower; static if (startsWith(member, funcName)) { enum string memberAfter = findSplitAfter(member, funcName)[1]; enum string lowerMemberAfter = toLower(memberAfter); importBuf.put(member ~ ", "); aliasBuf.put(spaces); aliasBuf.put("alias " ~ lowerMemberAfter ~ " = " ~ member ~ ";"); aliasBuf.put("\n"); static if ((lowerMemberAfter == "pdf") || (lowerMemberAfter == "pmf")) { aliasBuf.put(spaces); aliasBuf.put("alias density = " ~ lowerMemberAfter ~ ";"); aliasBuf.put("\n"); } } else static if (startsWith(member, invName)) { enum string memberAfter = findSplitAfter(member, invName)[1]; importBuf.put(member ~ ", "); aliasBuf.put(spaces); aliasBuf.put("alias i" ~ toLower(memberAfter) ~ " = " ~ member ~ ";"); aliasBuf.put("\n"); } } } if (endsWith(importBuf.data, ", ")) { string importOut = importBuf.data[0 .. ($ - (", ".length))] ~";\n"; if (endsWith(aliasBuf.data, "\n")) return importOut ~ aliasBuf.data[0 .. ($ - ("\n").length)]; else assert(0, "No relevant functions in dstats.distrib"); } else { assert(0, "No relevant functions in dstats.distrib"); } } private string toLowerFirst(string name)() { import std.string : toLower; import std.conv : to; string firstLetter = name[0].toLower.to!string; return firstLetter ~ name[1 .. $]; } private string toUpperFirst(string name)() { import std.string : toUpper; import std.conv : to; string firstLetter = name[0].toUpper.to!string; return firstLetter ~ name[1 .. $]; } private template GenDistStruct(string name) { const char[] GenDistStruct = "///"~ "\n" ~ "struct " ~ toUpperFirst!(name) ~ "\n" ~ "{\n" ~ genStructInternals!(name, toUpperFirst!(name)) ~ "\n" ~ "}"; } string GenDistStructs() { import dstats.distrib; import std.array : appender; import std.algorithm.searching : startsWith, endsWith, canFind, findSplitBefore, findSplitAfter; string[__traits(allMembers, dstats.distrib).length] createdStructs; size_t i; auto structsBuf = appender!string(); foreach(member; __traits(allMembers, dstats.distrib)) { static if (__traits(getProtection, member) == "public" || __traits(getProtection, member) == "export") { static if ((member.endsWith("PDF") || member.endsWith("PMF") || member.endsWith("CDF") || member.endsWith("CDFR"))) { static if (member.endsWith("PDF")) enum string memberBefore = findSplitBefore(member, "PDF")[0]; else static if (member.endsWith("PMF"))
Re: D as a Better C
On Friday, 25 August 2017 at 15:29:54 UTC, Swoorup Joshi wrote: On Friday, 25 August 2017 at 08:54:02 UTC, Kagamin wrote: On Thursday, 24 August 2017 at 19:09:58 UTC, Parke wrote: What is "intermediate D"? D with minimal runtime. 5 years later... D - BetterC++ (no gc) D - BetterJava (full on gc + other goodie tissue) D - BetterRust (full interoperability with rust) Forgive my cynicism D - BetterC# (no simple and easy-to-use generics, complex templates instead) Phobos - Better.NET (pointless names, weird structure, outdated stuff) DCD - BetterIntelliSense (tends to always not find about ~10 of all real possibilities, is rather "patched into" IDEs/editors than integrated)
Re: D as a Better C
> On Thursday, 24 August 2017 at 19:09:58 UTC, Parke wrote: >> What is "intermediate D"? On Fri, Aug 25, 2017 at 1:54 AM, Kagamin via Digitalmars-d-announcewrote: > D with minimal runtime. Is there any documentation on how to access and use the minimal runtime? -Parke
Re: Article: Writing Julia style multiple dispatch code in D
On Friday, 25 August 2017 at 16:01:27 UTC, data pulverizer wrote: Your wrapping strategy looks sensible though I would probably generate them all using string mixins. That might require less maintenance going forward.
Re: Article: Writing Julia style multiple dispatch code in D
On Friday, 25 August 2017 at 14:30:03 UTC, jmh530 wrote: On Friday, 25 August 2017 at 01:04:31 UTC, data pulverizer wrote: [snip] With respect to your point about immutability, you might be interested in the parameterize function in dstats.distrib. I hadn't noticed that was there, but I think it accomplishes, to a limited extent, the behavior of what you want. It returns a delegate with the values of the distribution fixed in there. Along the same lines, I think below is how I would set it up, rather than the mixin approach I discussed above. While it does not currently work with the parametrize funciton currently, I believe that with some simple adjustments it could. import std.stdio : writeln; struct Normal { ... Your wrapping strategy looks sensible though I would probably generate them all using string mixins.
Re: D as a Better C
On Friday, 25 August 2017 at 08:54:02 UTC, Kagamin wrote: On Thursday, 24 August 2017 at 19:09:58 UTC, Parke wrote: What is "intermediate D"? D with minimal runtime. 5 years later... D - BetterC++ (no gc) D - BetterJava (full on gc + other goodie tissue) D - BetterRust (full interoperability with rust) Forgive my cynicism
Re: Article: Writing Julia style multiple dispatch code in D
On Friday, 25 August 2017 at 01:04:31 UTC, data pulverizer wrote: [snip] With respect to your point about immutability, you might be interested in the parameterize function in dstats.distrib. I hadn't noticed that was there, but I think it accomplishes, to a limited extent, the behavior of what you want. It returns a delegate with the values of the distribution fixed in there. Along the same lines, I think below is how I would set it up, rather than the mixin approach I discussed above. While it does not currently work with the parametrize funciton currently, I believe that with some simple adjustments it could. import std.stdio : writeln; struct Normal { import dstats : normalCDF, normalCDFR, normalPDF, invNormalCDF; alias cdf = normalCDF; alias cdfr = normalCDFR; alias pdf = normalPDF; alias density = pdf; alias icdf = invNormalCDF; } struct LogNormal { import dstats : logNormalCDF, logNormalCDFR, logNormalPDF; alias cdf = logNormalCDF; alias cdfr = logNormalCDFR; alias pdf = logNormalPDF; alias density = pdf; //no icdf for LogNormal in dstats } private void hasMemberCheck(alias T, string x)() { import std.traits : hasMember; static assert(hasMember!(T, x), T.stringof ~ " must have " ~ x ~" member to call " ~ x ~ " function"); } auto cdf(alias T, U...)(U u) { hasMemberCheck!(T, "cdf"); return T.cdf(u); } auto pdf(alias T, U...)(U u) { hasMemberCheck!(T, "pdf"); return T.pdf(u); } auto pmf(alias T, U...)(U u) { hasMemberCheck!(T, "pmf"); return T.pmf(u); } auto cdfr(alias T, U...)(U u) { hasMemberCheck!(T, "cdfr"); return T.cdfr(u); } auto density(alias T, U...)(U u) { hasMemberCheck!(T, "density"); return T.density(u); } auto icdf(alias T, U...)(U u) { hasMemberCheck!(T, "icdf"); return T.icdf(u); } void main() { writeln(Normal.cdf(0.5, 0.0, 1.0)); writeln(cdf!Normal(0.5, 0.0, 1.0)); writeln(icdf!Normal(cdf!Normal(0.5, 0.0, 1.0), 0.0, 1.0)); writeln(LogNormal.cdf(0.5, 0.0, 1.0)); writeln(cdf!LogNormal(0.5, 0.0, 1.0)); //writeln(icdf!LogNormal(cdf!LogNormal(0.5, 0.0, 1.0), 0.0, 1.0)); //error }
Re: D as a Better C
On Friday, 25 August 2017 at 10:01:25 UTC, Basile B. wrote: On Friday, 25 August 2017 at 09:50:39 UTC, Suliman wrote: On Friday, 25 August 2017 at 08:54:02 UTC, Kagamin wrote: On Thursday, 24 August 2017 at 19:09:58 UTC, Parke wrote: What is "intermediate D"? D with minimal runtime. How to pass to dub -betterC flag? { ... "dflags" : ["betterC"], ... } oops, add the hyphen before, so { ... "dflags" : ["-betterC"], ... }
Re: D as a Better C
On Friday, 25 August 2017 at 09:50:39 UTC, Suliman wrote: On Friday, 25 August 2017 at 08:54:02 UTC, Kagamin wrote: On Thursday, 24 August 2017 at 19:09:58 UTC, Parke wrote: What is "intermediate D"? D with minimal runtime. How to pass to dub -betterC flag? { ... "dflags" : ["betterC"], ... }
Re: D as a Better C
On Friday, 25 August 2017 at 08:54:02 UTC, Kagamin wrote: On Thursday, 24 August 2017 at 19:09:58 UTC, Parke wrote: What is "intermediate D"? D with minimal runtime. How to pass to dub -betterC flag?
Re: D IDE Coedit - version 3, update 3 released
On Friday, 25 August 2017 at 04:29:51 UTC, user1234 wrote: On Friday, 14 July 2017 at 06:10:08 UTC, Basile B. wrote: Better integration of D-Scanner. D-Scanner binary is itself included from now, in addition to DCD. See https://github.com/BBasile/Coedit/releases/tag/3_update_3 for the download links and a complete changelog. update 4 is available too: indeed. https://github.com/BBasile/Coedit/releases/tag/3_update_4 mostly fixes at first glance. ~~mostly~~ only.
Re: D as a Better C
On Thursday, 24 August 2017 at 19:09:58 UTC, Parke wrote: What is "intermediate D"? D with minimal runtime.
Re: Visual Studio Code code-d serve-d beta release
On Thursday, 24 August 2017 at 21:45:48 UTC, WebFreak001 wrote: On Thursday, 24 August 2017 at 08:21:41 UTC, Paolo Invernizzi wrote: On Wednesday, 23 August 2017 at 20:10:01 UTC, WebFreak001 wrote: [...] Can you check? If I want to build it, what repo and revision should I use? [...] git clone https://github.com/Pure-D/serve-d.git cd serve-d dub build --build=release That's what I've done above in the previous post... I was meaning, in `.vscode/extensions/webfreak.code-d-beta-0.17.3/bin` in the macOS installation there's a linux workspace-d binary. If I want to rebuild it for macOS, what version of `workspace-d` have I to use? There's no `workspace-d` source files in `webfreak.code-d-beta-0.17.3`, only the binary. Thanks! --- Paolo