Re: how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();

2020-06-22 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 22, 2020 at 08:51:49PM +, mw via Digitalmars-d-learn wrote: [...] > >auto line = range.front; > >range.popFront; // pop immediately [...] This is dangerous, because it assumes .front is not invalidated by .popFront. It will not work, for example, with byLine because

Re: Parallel array append using std.parallelism?

2020-06-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 19, 2020 at 06:48:18AM +, Simen Kjærås via Digitalmars-d-learn wrote: [...] > There's an example of exactly this in std.parallelism: > https://dlang.org/phobos/std_parallelism.html#.TaskPool.workerIndex > > In short: > > Item[] targetArray = ...; // already contains data >

Parallel array append using std.parallelism?

2020-06-18 Thread H. S. Teoh via Digitalmars-d-learn
I have an array of input data that I'm looping over, and, based on some condition, generate new items that are appended onto a target array (which may already contain data). Since the creation of new items is quite expensive, I'm thinking to parallelize it with parallel foreach. To avoid data

Re: Should a parser type be a struct or class?

2020-06-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 17, 2020 at 02:32:09PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Wednesday, 17 June 2020 at 14:24:01 UTC, Stefan Koch wrote: > > Parser in dmd does even inherit from Lexer. > > why would a parser ever inherit from a lexer? Because, unlike a regular parser-driven

Re: Should a parser type be a struct or class?

2020-06-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 17, 2020 at 11:50:27AM +, Per Nordlöw via Digitalmars-d-learn wrote: > Should a range-compliant aggregate type realizing a parser be encoded > as a struct or class? Preferably a struct IMO, but see below. > In dmd `Lexer` and `Parser` are both classes. Probably for historical

Re: final switch problem

2020-06-13 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 13, 2020 at 09:02:21AM +, John Chapman via Digitalmars-d-learn wrote: [...] > module test; > > import std.uni; > > enum Cheese { cheddar, edam } > > void test(Cheese cheese) { > final switch (cheese) { > case Cheese.cheddar: break; > case Cheese.edam: break; > } > } >

Re: Looking for a Code Review of a Bioinformatics POC

2020-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 12, 2020 at 12:11:44PM +, duck_tape via Digitalmars-d-learn wrote: > On Friday, 12 June 2020 at 12:02:19 UTC, duck_tape wrote: > > For speedups with getting my hands dirty: > > - Does writef and company flush on every line? I still haven't found > > the source of this. writef, et

Re: What is the current stage of @property ?

2020-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 11, 2020 at 10:46:32AM +, Paul Backus via Digitalmars-d-learn wrote: > On Thursday, 11 June 2020 at 05:41:25 UTC, H. S. Teoh wrote: > > > > Ironically, just today I ran into this corner case where @property > > actually became a solution to a real problem: > > > >

Re: Finding the file and unittest that triggers an ICE during dub project build only when unittests are enabled

2020-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 12, 2020 at 09:29:06PM +, MoonlightSentinel via Digitalmars-d-learn wrote: > On Friday, 12 June 2020 at 18:18:25 UTC, Per Nordlöw wrote: > > How do I most easily track down which unittest in which file that > > causes the crash? [...] Compile your program with debugging symbols,

Re: Looking for a Code Review of a Bioinformatics POC

2020-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 12, 2020 at 03:32:48AM +, Jon Degenhardt via Digitalmars-d-learn wrote: [...] > I haven't spent much time on results presentation, I know it's not > that easy to read and interpret the results. Brief summary - On files > with short lines buffering will result in dramatic

Re: Looking for a Code Review of a Bioinformatics POC

2020-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 11, 2020 at 11:02:21PM +, duck_tape via Digitalmars-d-learn wrote: [...] > I will give that a shot! Also of interest, the profiler results on a > full runthrough do show file writing and int parsing as the 2nd and > 3rd most time consuming activities: > > ``` > Num

Re: Looking for a Code Review of a Bioinformatics POC

2020-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 11, 2020 at 10:41:12PM +, duck_tape via Digitalmars-d-learn wrote: > On Thursday, 11 June 2020 at 22:19:27 UTC, H. S. Teoh wrote: > > To encourage inlining, you could make it an alias parameter instead > > of a delegate, something like this: > > > > void overlap(alias

Re: Looking for a Code Review of a Bioinformatics POC

2020-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 11, 2020 at 04:13:34PM +, duck_tape via Digitalmars-d-learn wrote: [...] > Currently my D version is a few seconds slower than the Crystal > version. putting it very solid in third place overall. I'm not really > sure where it's falling behind crystal since `-release` removes

Re: What is the current stage of @property ?

2020-06-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 10, 2020 at 10:58:57PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > As things stand, @property has no real practical purpose but > frequently gets used to indicate that it's the intention of a > function's author for it to be used as if it were a variable. I >

Re: What is the current stage of @property ?

2020-06-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 10, 2020 at 10:50:17PM +, Paul Backus via Digitalmars-d-learn wrote: > On Wednesday, 10 June 2020 at 21:41:54 UTC, H. S. Teoh wrote: > > There are a few places where it's needed (like satisfying the range > > API, which implicitly checks for it) > > That may have been true at one

Re: What is the current stage of @property ?

2020-06-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 10, 2020 at 08:24:19PM +, Vinod K Chandran via Digitalmars-d-learn wrote: > Hi all, > I read in an old thread that authors of D wants to eliminate > @property. I just roughly read the big thread bu couldn't find a > conclusion. After all that thread is a 48 page longer jumbo

Re: Why is there no range iteration with index by the language?

2020-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 09, 2020 at 05:03:55PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: > On Tue, Jun 09, 2020 at 11:53:16PM +, Q. Schroll via Digitalmars-d-learn > wrote: > > Is there any particular reason why std.range : enumerate is a thing > > and > > >

Re: Why is there no range iteration with index by the language?

2020-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 09, 2020 at 11:53:16PM +, Q. Schroll via Digitalmars-d-learn wrote: > Is there any particular reason why std.range : enumerate is a thing > and > > foreach (i, e; range) { ... } > > doesn't work from the get-go? [...] std.range.indexed is your friend. ;-) T -- Let's eat

Re: Is there a list of things which are slow to compile?

2020-06-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 05, 2020 at 08:25:13AM +, aberba via Digitalmars-d-learn wrote: > On Wednesday, 3 June 2020 at 17:02:35 UTC, H. S. Teoh wrote: > > On Wed, Jun 03, 2020 at 09:36:52AM +, drathier via > > Digitalmars-d-learn wrote: > > > I'm wondering if there's a place that lists things which

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-06-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 04, 2020 at 06:09:35PM +, mw via Digitalmars-d-learn wrote: [...] > -- > class Person : NameI, AddrI { > mixin NameT!Person rename equals as name_equals; > mixin AddrT!Person rename equals as addr_equals; > >

Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 03, 2020 at 08:43:43PM +, BoQsc via Digitalmars-d-learn wrote: > On Wednesday, 3 June 2020 at 20:05:52 UTC, ttk wrote: [...] > > That works, but consider using chomp() instead. > > > > https://dlang.org/phobos/std_string.html#.chomp > > Chomp sounds kind of funny hahaha. > Who

Re: Is there a list of things which are slow to compile?

2020-06-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 03, 2020 at 09:36:52AM +, drathier via Digitalmars-d-learn wrote: > I'm wondering if there's a place that lists things which are > slower/faster to compile? DMD is pretty famed for compiling quickly, > but I'm not seeing particularly high speed at all, and I want to fix > that.

Re: Postblit segfault.

2020-06-01 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 01, 2020 at 03:27:11PM +, Basile B. via Digitalmars-d-learn wrote: [...] > Possibly a backend bug (keyword "wrong code"), caused by either of [1] or > [2] > > [1] https://github.com/dlang/dmd/pull/9357 > [2] https://github.com/dlang/dmd/pull/9623/files Yeah, it looks like a

Re: Postblit segfault.

2020-06-01 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 01, 2020 at 01:53:09PM +, Bastiaan Veelo via Digitalmars-d-learn wrote: > On Monday, 1 June 2020 at 09:42:44 UTC, Boris Carvajal wrote: > > On Monday, 1 June 2020 at 06:35:36 UTC, MaoKo wrote: > > > Hello, I don't understand why this code segfault on > > > > Reduced to: > > > >

Re: Static assert triggered in struct constructor that shouldn't be called

2020-05-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 24, 2020 at 09:34:53PM +, jmh530 via Digitalmars-d-learn wrote: > The following code results in the static assert in the constructor > being triggered, even though I would have thought no constructor would > have been called. I know that there is an easy fix for this (move the >

Re: How to use base class & child class as parameter in one function ?

2020-05-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 22, 2020 at 09:39:16PM +, Vinod K Chandran via Digitalmars-d-learn wrote: [...] > So in the same manner, i want > void function(Base) = fnPtr wiil work with > void function(Child) You cannot, because that's type unsafe: class Base {} class Derived : Base {

Re: How to use base class & child class as parameter in one function ?

2020-05-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 22, 2020 at 08:55:45PM +, Vinod K Chandran via Digitalmars-d-learn wrote: > On Friday, 22 May 2020 at 20:06:20 UTC, Adam D. Ruppe wrote: > > On Friday, 22 May 2020 at 20:04:24 UTC, Vinod K Chandran wrote: > > > sampleList.Add(New Child(10.5)) Is this possible in D without > > >

Re: to but nothrow?

2020-05-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 22, 2020 at 08:25:24PM +, bauss via Digitalmars-d-learn wrote: > Is there anyway to use the "to" template from std.conv but as nothrow? [...] There's std.conv.parse, though the interface is somewhat awkward, and it only works with character ranges. T -- I'm still trying to

Re: Can You Expand Arrays into an Argument List?

2020-05-15 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 15, 2020 at 06:44:52PM +, surlymoor via Digitalmars-d-learn wrote: [...] > I don't often miss JS, but one particular feature that I enjoyed is > the ability to expand arrays into argument lists using a unary > operator. > > Example: add(...[1, 1]) === add(1, 1) // IIRC > > I've

Re: Handle FormatSpec!char in the virtual toString() method of a class.

2020-05-14 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 13, 2020 at 12:26:21PM +, realhet via Digitalmars-d-learn wrote: > Hello, > > Is there a way to the following thing in a class instead of a struct? > > -- > static struct Point > { > int x, y; > > void toString(W)(ref W writer, scope

Re: Sum string lengths

2020-05-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 13, 2020 at 01:52:13PM +, Andrey via Digitalmars-d-learn wrote: > Hi, > I want to sum lengths of all strings in array: > > auto data = ["qwerty", "az", ""]; data.map!(s => s.length).sum; T -- It only takes one twig to burn down a forest.

Re: CTFE and Static If Question

2020-05-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 07, 2020 at 05:34:21PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] > Compared with LDC and GDC, DMD has a poor optimizer, [...] DMD's optimizer is the whipping boy around here, but to be fair, it is poor only when it comes to aggrssive inlining and optimizing loops. Other

Re: CTFE and Static If Question

2020-05-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 07, 2020 at 03:00:18PM +, jmh530 via Digitalmars-d-learn wrote: > I am curious how ctfe and static ifs interact. Then you should find this article helpful: https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time > In particular, if an enum bool passed as a

Re: Beginner's Comparison Benchmark

2020-05-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 06, 2020 at 09:59:48AM +, welkam via Digitalmars-d-learn wrote: > On Tuesday, 5 May 2020 at 20:29:13 UTC, Steven Schveighoffer wrote: > > the optimizer recognizes what you are doing and changes your code > > to: > > > > writeln(1_000_000_001); > > > Oh yes a classic constant

Re: real operations imprecise?

2020-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 05, 2020 at 01:44:18PM +, WebFreak001 via Digitalmars-d-learn wrote: > I was dumping the full PI value on my machine with the highest > precision it could get and got: > > $ rdmd --eval='printf("%.70llf\n", PI)' >

Re: Idomatic way to guarantee to run destructor?

2020-05-04 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, May 04, 2020 at 09:33:27AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > Now it's news to me that 'new' does not allocate on the heap when > 'scope' is used. I'm not sure I'm comfortable with it but that's true. > Is this unique? Otherwise, 'new' always allocates on the heap,

Re: Variable assignment in “if” condition in Dlang

2020-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 03, 2020 at 02:53:21PM +, Baby Beaker via Digitalmars-d-learn wrote: > How can I assign a variable in “if” condition in Dlang? if (auto obj = someFunction(...)) { // use obj here, it's guaranteed to be // true/non-null/etc. } T

Re: a function like writeln that returns a string rather than writes to a file

2020-05-01 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 02, 2020 at 02:22:42AM +, dan via Digitalmars-d-learn wrote: > I'm looking for a function something like writeln or write, but instead of > writing to stdout, it writes to a string and returns the string. [...] import std.format : format; string str = format("%s %s

Re: Python eval() equivalent in Dlang working in Runtime?

2020-05-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 01, 2020 at 06:37:41PM +, tsbockman via Digitalmars-d-learn wrote: > On Friday, 1 May 2020 at 18:07:54 UTC, H. S. Teoh wrote: [...] > > Actually, if you're willing to ship a working copy of dmd with your > > program, you *could* compile D code on-the-fly and dynamically load > >

Re: Python eval() equivalent in Dlang working in Runtime?

2020-05-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 01, 2020 at 05:44:27PM +, tsbockman via Digitalmars-d-learn wrote: > On Friday, 1 May 2020 at 15:42:54 UTC, Baby Beaker wrote: > > There is a Python eval() equivalent in Dlang working in Runtime? > > No, and there almost certainly never will be due to fundamental > differences

Re: Can't recreate a range?

2020-04-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 30, 2020 at 06:05:55PM +, Paul Backus via Digitalmars-d-learn wrote: [...] > Doing work in popFront instead of front is usually an anti-pattern, > since it forces eager evaluation of the next element even when that > element is never used. You should only do this if there's no >

Re: Is the behaviour of shift expressions with negative left operands defined / portable?

2020-04-28 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 28, 2020 at 08:30:27PM +, Harry Gillanders via Digitalmars-d-learn wrote: > The spec doesn't seem to explicitly mention what happens when the left > operand of a shift expression is signed and negative. [1] > But I know that D follows C's semantics for this sort of stuff, and >

Re: Implicit Function Template Instantiation (IFTI) Question

2020-04-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 27, 2020 at 05:19:35PM +, jmh530 via Digitalmars-d-learn wrote: > When using a template with multiple functions within it, is it > possible to access the underlying functions directly? Yes, but only if the template is not eponymous. > Not sure I am missing anything, but what

Re: Extracting user defined attributes on function parameters

2020-04-17 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 17, 2020 at 05:33:23PM +, Simen Kjærås via Digitalmars-d-learn wrote: > On Friday, 17 April 2020 at 16:54:42 UTC, Adam D. Ruppe wrote: [...] > > So pragma(msg) is doing something really weird, the bug doesn't > > appear to be in Phobos per se, I think it is the compiler doing the

Re: .get refuses to work on associative array

2020-04-15 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 15, 2020 at 09:46:58PM +, p.shkadzko via Digitalmars-d-learn wrote: > I am quite confused by the following exception during dub build: > > > dub build --single demo.d --compiler=ldc2 --force > Performing "debug" build using ldc2 for x86_64. > demo ~master: building configuration

Re: Extracting user defined attributes on function parameters

2020-04-14 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 15, 2020 at 12:01:51AM +, Adam D. Ruppe via Digitalmars-d-learn wrote: [...] > is() is a bit weird, but I described it in my "D Cookbook" to some > success... and writing that description helped me make sense of it. > The docs list like seven forms of it, but they are mostly just

Re: To get memory from another process.

2020-04-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 08, 2020 at 08:16:27PM +, Quantium via Digitalmars-d-learn wrote: > On Wednesday, 8 April 2020 at 16:25:01 UTC, Net wrote: [...] > > As far I know, you can't access other's program memory in any modern > > operating system. That's managed and protected by the OS through > >

Re: D on android and d_android

2020-04-07 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 07, 2020 at 03:06:16PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Tuesday, 7 April 2020 at 14:51:15 UTC, H. S. Teoh wrote: > > 1) Follow LDC wiki to build an Android cross-compiler and > >cross-compiled LDC libraries (this may already be prepackaged > >with the

Re: D on android and d_android

2020-04-07 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 07, 2020 at 12:43:20PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Monday, 6 April 2020 at 08:38:03 UTC, Jan Hönig wrote: > > Is there some "Hello World!" example for D on Android? [...] > > However there is just so much to know. > > It is really overwhelming. > > no

Re: How does one read file line by line / upto a specific delimeter of an MmFile?

2020-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 16, 2020 at 01:09:08PM +, Adnan via Digitalmars-d-learn wrote: [...] > Would it be wasteful to cast the entire content into a const string? Why would it be? It's just reinterpreting a pointer. > Can a memory mapped file be read with a buffer? That totally defeats the purpose

Re: How does one read file line by line / upto a specific delimeter of an MmFile?

2020-03-14 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Mar 14, 2020 at 10:37:37PM +, Adnan via Digitalmars-d-learn wrote: > https://dlang.org/library/std/mmfile/mm_file.html doesn't seem to > specify anything similar to lines() or byLine() or byLineCopy() etc. That's because a memory-mapped file appears directly in your program's memory

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 04:31:16PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > I would expect that something could be written to turn a signature > string into a mangling and also provide the correct type upon return. > Something like: > > auto f = getFunction!(@safe void

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 08:22:53PM +, wjoe via Digitalmars-d-learn wrote: [...] > So from what I understand, because, at least on Posix, since there's > only a symbol name there's nothing I can do in my loader to verify > that a function is or does what it claim to be/do. [...] As far as I

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 06:11:01PM +, wjoe via Digitalmars-d-learn wrote: > On Friday, 13 March 2020 at 17:05:32 UTC, Mike Parker wrote: > > On Friday, 13 March 2020 at 16:11:53 UTC, wjoe wrote: > > > On Friday, 13 March 2020 at 16:04:06 UTC, Mike Parker wrote: [...] > > > >

Re: Associative Array potential performance pitfall?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 09:30:16AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 3/13/20 5:24 AM, H. S. Teoh wrote: > > Note that `arg ~ arg` may allocate, but it also may not if the > > current buffer for `arg` is big enough to accomodate both. > > That always allocates. Only

Re: Associative Array potential performance pitfall?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 03:40:11AM +, Adnan via Digitalmars-d-learn wrote: > In my machine the following D code compiled with release flag and LDC > performs over 230ms while the similar Go code performs under 120ms. > > string smallestRepr(const string arg) { > import std.format :

Re: A set type implemented as an AA wrapper

2020-03-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 12, 2020 at 08:51:24AM +, mark via Digitalmars-d-learn wrote: [...] > YYY: The range() method is clearly not good D style but I don't know > how to support foreach (item; aaset) ... The usual idiom is to overload .opSlice, then you can do: foreach (item; aaset[]) { ... }

Re: in not working for arrays is silly, change my view

2020-03-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 02, 2020 at 07:51:34PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > On 3/2/20 6:46 PM, H. S. Teoh wrote: > > To prevent the optimizer from eliding "useless" code, you need to do > > something with the return value that isn't trivial (assigning to a > > variable

Re: in not working for arrays is silly, change my view

2020-03-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 02, 2020 at 06:27:22PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > Yeah, this looked very fishy to me. ldc can do some nasty "helpful" > things to save you time! When I posted my results, I was using DMD. > > I used run.dlang.io with ldc, and verified I get the

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 26, 2020 at 12:50:35AM +, Basile B. via Digitalmars-d-learn wrote: [...] > #!dmd -boundscheck=off -O -release -inline [...] TBH, I'm skeptical of any performance results using dmd. I wouldn't pay attention to performance numbers obtained this way, and rather look at the

Re: library dependencies nightmare, D edition

2020-02-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 25, 2020 at 10:26:48PM +, Marcel via Digitalmars-d-learn wrote: [...] > I can't give you the actual error messages right now, but both > libraries have packages that define modules with the same name. For > example, both libraries have packages with a module called > "utility.d".

Re: Lambda capture by value

2020-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 24, 2020 at 07:50:23PM +, JN via Digitalmars-d-learn wrote: > import std.range; > import std.stdio; > > alias NumberPrinter = void delegate(); > > NumberPrinter[int] printers; > > void main() > { > foreach (i; iota(5)) > { > printers[i] = () { write(i); }; >

Re: Unpack Variadic Args?

2020-02-13 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 13, 2020 at 12:32:01PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > Some syntax like expr(someTuple)... would be really cool to have in D. > > Or something like arg => expr syntax for templates might be useful: > > f(staticMap!(!a => foo(a), args)); // look ma,

Re: Type sequence concatenation / associative array implementation

2020-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 12, 2020 at 09:05:22PM +, user1234 via Digitalmars-d-learn wrote: > On Wednesday, 12 February 2020 at 20:58:49 UTC, Marcel wrote: > > Hello! > > I have two questions: > > > > 1- How can I concatenate two type sequences? > > alias Concatenated = AliasSeq!(TList1, TList2); [...]

Re: How to use sets in D?

2020-02-07 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 07, 2020 at 07:37:08PM +, mark via Digitalmars-d-learn 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

Re: Is it possible to use DMD as a library to compile strings at runtime?

2020-02-01 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Feb 02, 2020 at 03:16:46AM +, Saurabh Das via Digitalmars-d-learn wrote: > On Saturday, 1 February 2020 at 20:37:03 UTC, H. S. Teoh wrote: [...] > > I've actually done this before in an equation grapher program: the > > user inputs an equation, the program generates D code to compute

Re: Is it possible to use DMD as a library to compile strings at runtime?

2020-02-01 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 01, 2020 at 08:01:34PM +, Andre Pany via Digitalmars-d-learn wrote: [...] > Another approach: > - include the dmd compiler package with your application > - within your app call the compiler executable and compile the source > code to a dll / so > - call the dll / so function

Re: auto keyword

2020-01-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 30, 2020 at 09:37:40AM +, Michael via Digitalmars-d-learn wrote: [...] > auto elements = buf.to!string.strip.split(" ").filter!(a => a != ""); > > That line strips white space from buf, splits it, removes empty > elements and returns an array of strings. At least I thought so. If

Re: Question about alias and getOverloads

2020-01-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 30, 2020 at 06:20:47PM +, uranuz via Digitalmars-d-learn wrote: [...] > 1. Why API for __traits(getOverloads) is so strange. Why I need to > find parent for symbol myself and pass actual symbol name as string, > but not actually pass a symbol itself? It is very strange to me...

Re: Class member function with a Callback funtion parameter

2020-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 27, 2020 at 10:13:47PM +, Herbert via Digitalmars-d-learn wrote: > On Monday, 27 January 2020 at 21:51:35 UTC, Adam D. Ruppe wrote: > > On Monday, 27 January 2020 at 21:21:55 UTC, Herbert wrote: > > > My project does not allow dynamic memory. So I can't use > > > delegates. > > >

Re: Subrange type

2020-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 27, 2020 at 09:15:58PM +, Herbert via Digitalmars-d-learn wrote: [...] > How can I have a function parameter with this type (DiceValue)? Just take an integer type and add a contract that enforces range. For example: auto myFunc(int diceValue) in (diceValue

Re: CTFE, string mixins & code generation

2020-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 24, 2020 at 08:26:50PM +0100, Jacob Carlborg via Digitalmars-d-learn wrote: > On 2020-01-24 19:43, H. S. Teoh wrote: > > > (enums cannot take AA's or class objects as values, also, once > > assigned they are immutable). > > AA enums work. Ah you're right, it's

Re: CTFE, string mixins & code generation

2020-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 24, 2020 at 04:21:48PM +, Jan Hönig via Digitalmars-d-learn 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

Re: weekly news?

2020-01-23 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 23, 2020 at 03:44:10PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: [...] > Or delete all that wordpress junk and make something in D :P +1. ;-) T -- The fact that anyone still uses AOL shows that even the presence of options doesn't stop some people from picking the

Re: CTFE and assoc array

2020-01-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 21, 2020 at 04:51:35PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > It would be really cool to make AA's at CTFE change into runtime AAs > when used at runtime, and be accessible as compile-time AAs otherwise. [...] I've been wishing for this since the early

Re: lambda alias import

2020-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 17, 2020 at 04:12:18PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 1/17/20 3:04 PM, Petar Kirov [ZombineDev] wrote:> On Friday, 17 January > 2020 at 21:40:05 UTC, JN wrote: > > > I think the problem comes from the way you compile and link your > > code. I you compile both

Re: confused about string and lambda args

2020-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 16, 2020 at 05:03:33PM +, mark via Digitalmars-d-learn wrote: [...] > auto wordCharCounts4 = words // I added this and it won't compile > .map!(a => a.count); // Error: no property count for type string > writeln(wordCharCounts4); You need to import std.algorithm to

Re: Reading a file of words line by line

2020-01-15 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 15, 2020 at 07:50:31PM +, mark via Digitalmars-d-learn wrote: [...] > Why did you use string.count rather than string.length? The .length of a `string` type is the number of bytes that it occupies, which is not necessarily the same thing as the number of characters in the string.

Re: Fetching an element using find

2020-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 13, 2020 at 12:58:57PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/13/20 12:47 PM, H. S. Teoh wrote: > > > > Why not write your own convenience wrapper? > > > > auto firstElement(R)(R r) > > if (isInputRange!R) > > { > > if

Re: Fetching an element using find

2020-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 13, 2020 at 12:39:30PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > I have a range (array), I want to find an element and get it from that > array. > > The code I'm writing looks like this: > > auto answer = arr.find!((item,x) => item.id == x)(id); >

Re: books for learning D

2020-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 13, 2020 at 04:23:19AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 1/13/20 2:28 AM, mark wrote: > > I'm just starting out learning D. > > > > Andrei Alexandrescu's "The D Programming Language" is 10 years old, > > so is it still worth getting? (I don't know how much D has

Re: Calling D code from C

2020-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 08, 2020 at 09:42:03PM +, Ferhat Kurtulmuş via Digitalmars-d-learn wrote: [...] > What is going on here? The original post date appears as to be of 2005 > :D. [...] Haha yeah, I'm not sure why Stefan replied to a post dating from 2005. T -- Just because you can, doesn't mean

Re: linkererrors when reducion phobos with dustmite

2020-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 06, 2020 at 10:27:09AM +, berni44 via Digitalmars-d-learn wrote: > As mentioned on the dustmite website [1] I copied the folder std from > Phobos in a separate folder and renamed it to mystd. The I changed all > occurences of std by mystd in all files. > > That works most of the

Re: Practical parallelization of D compilation

2020-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 08, 2020 at 09:13:18AM +, Chris Katko via Digitalmars-d-learn wrote: > On Wednesday, 8 January 2020 at 06:51:57 UTC, H. S. Teoh wrote: [...] > > Generally, the recommendation is to separately compile each package. [...] > What's the downsides / difficulties / "hoops to jump

Re: Practical parallelization of D compilation

2020-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 08, 2020 at 06:56:20PM +, Guillaume Lathoud via Digitalmars-d-learn wrote: > Thanks to all for the answers. > > The package direction is precisely what I am trying to avoid. It is > still not obvious to me how much work (how many trials) would be > needed to decide on

Re: Calling D code from C

2020-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 08, 2020 at 06:12:01PM +, Stefan via Digitalmars-d-learn wrote: [...] > But you can easily do the initialization in your D code, by calling > rt_init() and rt_term(), like this: [...] > extern(C) int rt_init(); > extern(C) int rt_term(); > extern(C) __gshared bool rt_initialized =

Re: @disable("reason")

2020-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 08, 2020 at 06:06:33AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Wednesday, January 8, 2020 4:54:06 AM MST Simen Kjærås via Digitalmars-d- > learn wrote: [...] > > struct S { > > @disable this(); > > @disable static S init(); > > } > > > > This will give

Re: What is the difference between a[x][y] and a[x,y]?

2020-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 08, 2020 at 09:09:23AM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > On 2020-01-07 19:06:09 +, H. S. Teoh said: > > > It's up to you how to implement all of this, of course. The language > > itself doesn't ship a built-in type that implements this, but it > > does

Re: Practical parallelization of D compilation

2020-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 08, 2020 at 04:40:02AM +, Guillaume Lathoud via Digitalmars-d-learn wrote: > Hello, > > One of my D applications grew from a simple main and a few source > files to more than 200 files. Although I minimized usage of > templating and CTFE, the compiling time is now about a minute.

Re: What is the difference between a[x][y] and a[x,y]?

2020-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 07, 2020 at 06:38:59PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > I read all the docs but I'm not toally sure. Is it that [x][y] is a 2D > array-index, where as [x,y] is a slice? arr[x][y] is indexing an array of arrays. arr[x,y] is indexing an actual multi-dimensional

Re: What type does byGrapheme() return?

2020-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 04, 2020 at 08:19:14PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > On 2019-12-31 21:36:56 +, Steven Schveighoffer said: > > > The fact that a Grapheme's return requires you keep the grapheme in > > scope for operations seems completely incorrect and dangerous IMO > >

Re: Using tasks without GC?

2020-01-03 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 04, 2020 at 12:51:15AM +, Chris Katko via Digitalmars-d-learn wrote: [...] > I'm looking through D's parallelism module and the docs state, > up-front: > > >Creates a Task on the GC heap that calls an alias. > > The modern, scalable way to make a parallel game engine uses

Re: What type does byGrapheme() return?

2019-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 31, 2019 at 04:36:56PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/31/19 4:22 PM, H. S. Teoh wrote: [...] > > import std; > > void main() { > > auto x = "Bla\u0301hbla\u0310h\u0309!"; > > auto r = x.byGrapheme; > >

Re: What type does byGrapheme() return?

2019-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 31, 2019 at 04:02:47PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/31/19 2:58 PM, H. S. Teoh wrote: > > On Tue, Dec 31, 2019 at 09:33:14AM -0500, Steven Schveighoffer via > > Digitalmars-d-learn wrote: > > > e.g.: > > > > > > writeln(" Text = ", gr1.map!((ref

Re: What type does byGrapheme() return?

2019-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 31, 2019 at 09:33:14AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/30/19 6:31 PM, H. S. Teoh wrote: > > On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via > > Digitalmars-d-learn wrote: [...] > > Haha, it's actually right there

Re: Finding position of a value in an array

2019-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 31, 2019 at 09:41:49AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/30/19 6:15 PM, JN wrote: > > On Sunday, 29 December 2019 at 08:31:13 UTC, mipri wrote: > > > > > > int i = a.countUntil!(v => v == 55); > > > assert(i == 2); > > > > I also had to ask because I

Re: What type does byGrapheme() return?

2019-12-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 30, 2019 at 03:31:31PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: > On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via Digitalmars-d-learn > wrote: > [...] > > I suspect the cause is that whatever Grapheme.opSlice returns is > > going out-of-scop

Re: What type does byGrapheme() return?

2019-12-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > I suspect the cause is that whatever Grapheme.opSlice returns is going > out-of-scope when used with .map, that's why it's malfunctioning. [...] Haha, it's actually right there in the Graphem

Re: What type does byGrapheme() return?

2019-12-30 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Dec 29, 2019 at 01:19:09PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > On 2019-12-27 19:44:59 +, H. S. Teoh said: [...] > > If you want to add/delete/change graphemes, what you *really* want > > is to use an array of Graphemes: > > > > Grapheme[] editableGraphs; > >

Re: Some code that compiles but shouldn't

2019-12-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 30, 2019 at 06:18:49PM +, uranuz via Digitalmars-d-learn wrote: [...] > void getCompiledTemplate(HTTPContext ctx) > { > import std.exception: enforce; > enforce(ctx, `ctx is null`); > enforce(ctx.request, `ctx.request is null`);

<    2   3   4   5   6   7   8   9   10   11   >