Re: version(StdDoc)

2018-11-23 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 23, 2018 at 09:53:59PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Friday, 23 November 2018 at 21:47:51 UTC, Tony wrote: > > What is the situation in which the identifier StdDoc is set? > > When the phobos website is being compiled, its own makefile sets that. > > It is

Re: D is supposed to compile fast.

2018-11-23 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 23, 2018 at 05:37:46PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Friday, 23 November 2018 at 17:21:46 UTC, H. S. Teoh wrote: > > Are you using template-heavy Phobos functions? > > Merely importing a Phobos module is liable to cost you a quarter > second or more of

Re: D is supposed to compile fast.

2018-11-23 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 23, 2018 at 08:57:57AM +, Chris Katko via Digitalmars-d-learn wrote: > Any time I see people mention the benefits of D, I see "compile times" > "compile times" "compile times" over and over. D is extremely fast at compilation ... of C-like code. :-D Anything involving heavy use

Re: Can't read a constant value in compile time?

2018-11-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Nov 20, 2018 at 06:54:58PM +, Adnan via Digitalmars-d-learn wrote: > Godbolt: https://godbolt.org/z/SWWOu7 > > When I write `something!(aNumber)()` and if a number is an > immutable/enum it should be able to be read at compile time, right? > Why is this different? [...] Read this

Re: What is best way to read and interpret binary files?

2018-11-19 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 19, 2018 at 10:14:25PM +, Neia Neutuladh via Digitalmars-d-learn wrote: > On Mon, 19 Nov 2018 21:30:36 +, welkam wrote: > > So my question is in subject/title. I want to parse binary file into D > > structs and cant really find any good way of doing it. What I try to do > >

Re: Why is stdio ... stdio?

2018-11-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 09, 2018 at 05:36:54PM +, Chris Katko via Digitalmars-d-learn wrote: [...] > FYI, Allegro.CC just uses > > > int main() > { > return 0; > } > > > as well as for pre-formatted "monospace" text. > > Neither of those would pollute a mailing list in plain-text mode > because

Re: How do I install a library?

2018-11-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 09, 2018 at 05:38:18PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Friday, 9 November 2018 at 01:18:51 UTC, bachmeier wrote: > > There's no obvious reason it can't be done that way in D > > It is trivial, really. Just download the files to your import path and > `dmd

Re: Why is stdio ... stdio?

2018-11-08 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 09, 2018 at 02:03:36AM +, Chris Katko via Digitalmars-d-learn wrote: > Simple curious question. > > Why isn't : > > import std.stdio; > > instead: > > import std.io; The reason is that std.stdio is basically just a nice D wrapper with syntactic sugar around the C library's

Re: Exception slipping through the catch block?

2018-11-08 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 09, 2018 at 01:14:08AM +, Neia Neutuladh via Digitalmars-d-learn wrote: [...] > This isn't, strictly speaking, safe. Your program detected an error, > and in Walter's book, that means you can't trust the program to do > *anything*. Unwinding the stack, formatting a stacktrace,

Re: How do I install a library?

2018-11-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 08, 2018 at 11:51:39PM +, bachmeier via Digitalmars-d-learn wrote: > On Thursday, 8 November 2018 at 23:43:38 UTC, Murilo wrote: > > > It finally worked, but I can't just compile it normally, I have to > > use dub run, I wish it were something simple that I just download > > into

Re: Exception slipping through the catch block?

2018-11-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 08, 2018 at 01:28:47PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Thursday, November 8, 2018 10:55:45 AM MST Stanislav Blinov via > Digitalmars-d-learn wrote: > > On Thursday, 8 November 2018 at 16:13:55 UTC, Mike Parker wrote: [...] > > > No, you should never catch

Re: Checking for CTFE at compile-time

2018-11-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 07, 2018 at 10:01:15PM +, Per Nordlöw via Digitalmars-d-learn wrote: > Opposite to run-time checking via > > if (__ctfe) > { > // > } It's actually not a "run-time" check, because the backend optimizer will optimize out the true branch (check the emitted asm to confirm

Re: Removing the precision from double

2018-11-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 01, 2018 at 11:59:26PM +, kerdemdemir via Digitalmars-d-learn wrote: > I have two numbers > > First The price = 0.0016123 > Second Maximum allowed precision = 0.0001(it can be only 0.001, > 0.0001, 0.1, ..., 0.01 bunch of zeros and than a one that > is it)

Re: std.math log and family

2018-10-31 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 31, 2018 at 11:29:17AM +, kinke via Digitalmars-d-learn wrote: > On Wednesday, 31 October 2018 at 01:26:19 UTC, H. S. Teoh wrote: > > Is it true that on modern hardware computing with `real` reverts to > > slow x87 emulation in the CPU instead of using SSE/MMX/whatever > > native

Re: std.math log and family

2018-10-30 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 31, 2018 at 01:14:37AM +, kinke via Digitalmars-d-learn wrote: > On Wednesday, 31 October 2018 at 00:48:03 UTC, Joe wrote: > > I'd like to know if the lack of double/float versions of 'log', > > 'log10', etc. are intentional, i.e., there's some rationale behind > > it, or an

Re: std.math log and family

2018-10-30 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 31, 2018 at 12:48:03AM +, Joe via Digitalmars-d-learn wrote: [...] > I'd like to know if the lack of double/float versions of 'log', > 'log10', etc. are intentional, i.e., there's some rationale behind it, > or an oversight. It's an oversight. Thanks for bringing it to our

Re: How in the name of D do you deal with more than one optional template parameter?

2018-10-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 30, 2018 at 08:46:31PM +, aliak via Digitalmars-d-learn wrote: > Hi, > > Do you guys have any strategies for dealing with templates when they > have more than one optional parameter? > > E.g let's say we have a type C that takes three parameters > > struct B(T) {} > struct

Re: anyway to set a const object after the fact?

2018-10-29 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Oct 29, 2018 at 09:50:32PM +, aliak via Digitalmars-d-learn wrote: > Hi, so if you have this piece of code: > > struct C { > > void f() { > string[] others; > const string[] restArgs; > foreach (i, arg; args) { > if (isValidArg(arg)) { > restArgs = args[i

Re: Dealing with ranges where front and popFront do the same logic / eager ranges

2018-10-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 16, 2018 at 10:59:50PM +, Dennis via Digitalmars-d-learn wrote: > I've always been curious around the design choice of ranges to make > front and popFront separate functions, instead of having popFront > return the front. I suppose it is useful sometimes to be able to > access

Re: Is there a function for this?

2018-10-06 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Oct 06, 2018 at 08:07:42PM +, bauss via Digitalmars-d-learn wrote: [...] > The whole problem is actually that they do not work with ranges that > aren't sorted. Things like .group and .uniq should work without sorted > ranges. You can't always expect a range to be sorted to perform

Re: Can I create static c callable library?

2018-09-28 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 28, 2018 at 02:08:25PM +, Atila Neves via Digitalmars-d-learn wrote: > On Thursday, 27 September 2018 at 23:53:50 UTC, Steven Schveighoffer wrote: [...] > > Since C initialization functions have no order to them, it's > > possible that some initialization functions in the D

Re: Can I create static c callable library?

2018-09-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 27, 2018 at 09:48:50PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 27 September 2018 at 21:41:31 UTC, H. S. Teoh wrote: > > Though I'm not sure what will happen if your C program tries loading > > two or more D libraries that use this trick... is rt_init() > >

Re: Can I create static c callable library?

2018-09-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 27, 2018 at 03:11:26PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: > On Thursday, September 27, 2018 6:16:13 AM MDT Atila Neves via Digitalmars- > d-learn wrote: [...] > > Even easier, compile this C file and add the resulting object > > file to your (now mostly) D static

Re: dealing with very long paths and names

2018-09-14 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 14, 2018 at 07:05:35PM +, Basile B. via Digitalmars-d-learn wrote: > On Friday, 14 September 2018 at 17:59:38 UTC, Josphe Brigmo wrote: > > Seems to break dirEntries when trying to deal with long pathnames(> > > 512) on windows. > > > > It's a strange error because it just fails

Re: remove file access denied(remove broke)

2018-09-14 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 14, 2018 at 02:36:34PM +, Josphe Brigmo via Digitalmars-d-learn wrote: [...] > It happens on a bunch. I do get errors or overlong file names but this > doesn't seem to be the case. > > The fact is, that simply using execute shell using the same file name > works. So this is a D

Re: crash when using in struct constructor

2018-07-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 16, 2018 at 10:08:34PM +, Eric via Digitalmars-d-learn wrote: > This makes the compiler crash. Is it illegal code? > > struct List { > private List* head; > private List* tail; > > this(int x) { > head = null; > tail = // <-- crasher > } > } > > List2 ls = 2;

Re: Struct template cannot deduce function from argument types

2018-06-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 27, 2018 at 04:19:56PM +, Luka Aleksic via Digitalmars-d-learn wrote: [...] > struct pair(T, U) { > T first; > U second; > > this(T arg_first, U arg_second) { > first = arg_first; > second = arg_second; > } > }; > > void main()

Re: foreach / mutating iterator - How to do this?

2018-06-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 25, 2018 at 05:29:23PM +0200, Robert M. Münch via Digitalmars-d-learn wrote: > I have two foreach loops where the inner should change the iterator > (append new entries) of the outer. > > foreach(a, candidates) { > foreach(b, a) { > if(...) candidates ~=

Re: Confusion/trying to understand CTFE keywords

2018-06-08 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 08, 2018 at 02:57:26PM +, jmh530 via Digitalmars-d-learn wrote: [...] > May I suggest that you add a flow chart that gives a very high level > understanding of the compiler steps. Like how Rust's introduction to > MIR has: > https://blog.rust-lang.org/2016/04/19/MIR.html I would,

Re: Confusion/trying to understand CTFE keywords

2018-06-08 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 08, 2018 at 02:36:01PM +, Gopan via Digitalmars-d-learn wrote: > On Friday, 8 June 2018 at 05:10:16 UTC, H. S. Teoh wrote: > > All this talk of CTFE and "compile-time", along with the confusion > > that arises from conflating everything done by the compiler into the > > blanket

Re: Confusion/trying to understand CTFE keywords

2018-06-07 Thread H. S. Teoh via Digitalmars-d-learn
All this talk of CTFE and "compile-time", along with the confusion that arises from conflating everything done by the compiler into the blanket term "compile-time" makes me want to scream: https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time ;-) tl;dr: D's "compile-time"

Re: Error: module `hello` is in file 'hello.d' which cannot be read

2018-05-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 04, 2018 at 11:29:12PM +, Alex via Digitalmars-d-learn wrote: > Hi > > I just installed D on my windows 10 and want to try to compile a hello > world. My source is a classical > > import std.stdio; > void main() { > writeln("Hello, World!"); > } > > And I try to compile and get

Re: dynamically allocating on the stack

2018-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Apr 21, 2018 at 01:30:55PM +, Cym13 via Digitalmars-d-learn wrote: > On Saturday, 21 April 2018 at 12:08:09 UTC, Dmitry Olshansky wrote: [...] > > Unbounded allocation on stack is kind of anti-pattern and a > > potential DoS vector. > > I'm having trouble seeing how unbounded heap

Re: Range length property

2018-04-10 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 10, 2018 at 10:07:40PM +, Cym13 via Digitalmars-d-learn wrote: [...] > On the other hand I don't think the end user should have to scratch > his head to find the length of a range, especially if it's not trivial > to get (say, O(log n) kind of case). Therefore exposing a method in

Re: Compile-time variables

2018-04-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 05, 2018 at 11:53:00PM +, Kayomn via Digitalmars-d-learn wrote: [...] > --- > alias NodeTypeID = uint; > > enum NodeTypeID getNodeID() { > static NodeTypeID lastID = 0; > > return lastID++; >

Re: Constructor qualifiers; bug or expected behavior?

2018-04-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 02, 2018 at 10:26:32AM +, RazvanN via Digitalmars-d-learn wrote: > Hi all, > > Let's say we have this code: > > struct B > { > int a; > this(int a) immutable > { > this.a = 7; > } > > this(int a) > { > this.a = 10; > } > } > > void

Re: dynamically compile and load glue logic

2018-03-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 30, 2018 at 02:24:45PM +, yawniek via Digitalmars-d-learn wrote: > in how far is it or would the following be possible: > > dynamically compile and execute some glue logic that is also written > in D under linux? > > and what happens if that code uses phobos or other dub libs

Re: "in" no longer "scope" since 2.079.0?

2018-03-27 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 27, 2018 at 04:16:15PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Tuesday, 27 March 2018 at 09:27:07 UTC, Jonathan M Davis wrote: > > it was deemed too dangerous to have in suddenly really mean both > > scope and const, because it would potentially break a lot of code. >

Re: OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-21 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 21, 2018 at 07:30:28PM +, Russel Winder via Digitalmars-d-learn wrote: [...] > But :-( > > Why does version have to be a keyword? [...] version(all) { ... } version(none) { ... } version(Posix) { ... } version(Windows) { ... } But yeah, using

Re: Template condition evaluation (shortcircuit)

2018-03-21 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 21, 2018 at 05:42:34PM +, rumbu via Digitalmars-d-learn wrote: > I tried to define a template: > > enum isFoo(alias T) = > T.stringof.length >= 3 && T.stringof[0..3] == "abc"; > > int i; > pragma(msg, isFoo!i); > > Error: string slice [0 .. 3] is out of bounds > Error:

Re: Incomprehensible error message

2018-03-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 20, 2018 at 11:05:59PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Tuesday, 20 March 2018 at 21:18:01 UTC, H. S. Teoh wrote: > > Which means error messages would need to be constructed as an > > abstract object that the error message printer can then inspect to > >

Re: Incomprehensible error message

2018-03-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 20, 2018 at 10:04:30PM +0100, Jacob Carlborg via Digitalmars-d-learn wrote: > On 2018-03-19 19:03, H. S. Teoh wrote: > > > Yeah, the compiler really ought to be outputting FQNs in error > > messages, since otherwise you get baffling A != A messages. Though > > outputting FQNs

Re: Testing D database calls code for regression

2018-03-19 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 19, 2018 at 06:45:49PM +, aberba via Digitalmars-d-learn wrote: [...] > The thing about functional programming where functions are > decoupled/testable doesn't seem to apply to database call code. I > guess its because databases introduces a different state...another > point of

Re: Incomprehensible error message

2018-03-19 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 19, 2018 at 05:01:32PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Monday, 19 March 2018 at 16:33:28 UTC, Russel Winder wrote: > > I have been staring at this message so long, I have clearly stopped > > actually reading it, hence outside assistance needed. > > So I would

Re: Incomprehensible error message

2018-03-19 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 19, 2018 at 04:33:28PM +, Russel Winder via Digitalmars-d-learn wrote: [...] > I have been staring at this message so long, I have clearly stopped > actually reading it, hence outside assistance needed. > > Can someone please explain to me (probably in words of one syllable >

Re: Testing D database calls code for regression

2018-03-18 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Mar 18, 2018 at 07:51:18PM +, aberba via Digitalmars-d-learn wrote: > On Friday, 16 March 2018 at 21:15:33 UTC, H. S. Teoh wrote: > > On Fri, Mar 16, 2018 at 08:17:49PM +, aberba via Digitalmars-d-learn > > wrote: > > > [...] > > > > The usual way I do this is to decouple the code

Re: Testing D database calls code for regression

2018-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 16, 2018 at 08:17:49PM +, aberba via Digitalmars-d-learn wrote: > How will you test D code which makes calls to database to detect bugs > and regression. Unlike where you can inject data like assert (2+1 == > 3), database interfacing code will be crazy... Or there's some mocking >

Re: core.stdc.stdlib._compare_fp_t and qsort

2018-03-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 12, 2018 at 01:04:06AM +, Joe via Digitalmars-d-learn wrote: > On Sunday, 11 March 2018 at 23:26:04 UTC, Stefan Koch wrote: > > You have to pass a pointer to the function. > > Otherwise it'll be a parenthsis-less call. > > use : qsort(recs, num_recs, (Record *).sizeof, ); > >

Re: Returning constant / literal struct value (pod)

2018-03-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 09, 2018 at 09:30:53PM +, Cecil Ward via Digitalmars-d-learn wrote: > Can we return a literal struct value straight from a return statement? > > ie something like > mystruct_t myfunc() > { // ... blah > return { field1: val1, field2: val2; }; > } > assuming that the

Re: issue with each specifically for x86

2018-03-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 07, 2018 at 10:21:42PM +0200, ketmar via Digitalmars-d-learn wrote: [...] > it looks like ignoring `double` result causes FPU stack imbalance > ('cause compiler doesn't insert "FPU pop" instruction), and that > affects the computations. > > on 64 bit it doesn't matter, 'cause no FPU

Re: log for complex

2018-03-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 07, 2018 at 10:47:40AM +, J-S Caux via Digitalmars-d-learn wrote: > On Wednesday, 7 March 2018 at 10:28:23 UTC, Simen Kjærås wrote: > > On Wednesday, 7 March 2018 at 10:10:49 UTC, J-S Caux wrote: > > > On Wednesday, 7 March 2018 at 08:04:36 UTC, Simen Kjærås wrote: > > > > auto

Re: How to use globals correctly?

2018-03-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 06, 2018 at 11:46:04AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, March 06, 2018 18:34:34 bauss via Digitalmars-d-learn wrote: [...] > > Singletons are always smelly code tbh. > > > > Especially in D with thread-local storage. > > > > I can't think of a

Re: Speed of math function atan: comparison D and C++

2018-03-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 06, 2018 at 06:05:59PM +, jmh530 via Digitalmars-d-learn wrote: > On Tuesday, 6 March 2018 at 17:51:54 UTC, H. S. Teoh wrote: > > [snip] > > > > I'm not advocating for getting *rid* of 80-bit float support, but > > only to make it *optional* rather than the default, as currently >

Re: Speed of math function atan: comparison D and C++

2018-03-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 06, 2018 at 08:12:57AM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > On 2018-03-05 20:11:06 +, H. S. Teoh said: > > > Walter has been adamant that we should always compute std.math.* > > functions with the `real` type, which on x86 maps to the non-IEEE > > 80-bit

Re: Speed of math function atan: comparison D and C++

2018-03-05 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 05, 2018 at 06:39:21PM +, J-S Caux via Digitalmars-d-learn wrote: [...] > I've tested these two very basic representative codes: > https://www.dropbox.com/s/b5o4i8h43qh1saf/test.cc?dl=0 > https://www.dropbox.com/s/zsaikhdoyun3olk/test.d?dl=0 > > Results: > > C++: > g++ (Apple

Re: Is it possible to return the subclass from a method of the parent class in dlang?

2018-03-02 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Mar 03, 2018 at 01:13:43AM +0100, Christian Köstlin via Digitalmars-d-learn wrote: > >> class Timer : Thread { > >>    override Timer start() { ... } > >> } > >> > >> https://dlang.org/spec/function.html#virtual-functions > >> > >> (see item 6) > >> > >> -Steve > > Thanks for this. > > It

Re: Garbage collected pointers?

2018-03-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 01, 2018 at 02:52:26PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > There are a few in there, which I think are over-the-top. Such as > "don't cast a pointer to a non-pointer", [...] Isn't that necessary for a precise GC? Also, AIUI the current GC already does

Re: Function template declaration mystery...

2018-02-28 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 28, 2018 at 09:36:33PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: [...] > Yes, that's what the docs state. And I can imagin this. Bit this > sentence is a bit hard to understand: "If fun is not a > string, unaryFun aliases itself away to fun." Whatever this means. [...]

Re: Function template declaration mystery...

2018-02-28 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 28, 2018 at 06:47:22PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > Hi, I'm lost reading some code: > > A a; > > auto do(alias f, A)(auto ref A _a){ > alias fun = unaryFun!f; > return ... > ... > } > > How is this alias stuff working? I mean what's the

Re: iota to array

2018-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 26, 2018 at 07:50:10PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > One case that I found interesting was that in writing > core.time.convClockFreq so that it didn't require floating point > values, it not only avoided the inaccuracies caused by using FP, but > it

Re: iota to array

2018-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 26, 2018 at 05:18:00PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Monday, February 26, 2018 16:04:59 H. S. Teoh via Digitalmars-d-learn > wrote: [...] > > (There *are* exact representations for certain subsets of > > irrationals that allow fast com

Re: iota to array

2018-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 27, 2018 at 12:26:56AM +, psychoticRabbit via Digitalmars-d-learn wrote: > On Tuesday, 27 February 2018 at 00:04:59 UTC, H. S. Teoh wrote: > > > > A 64-bit double can only hold about 14-15 decimal digits of > > precision. Anything past that, and there's a chance your > >

Re: iota to array

2018-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 26, 2018 at 11:34:06PM +, psychoticRabbit via Digitalmars-d-learn wrote: [...] > and what's going on here btw? > > assert( 1 == 1.01 ); // assertion error in DMD but not in > LDC > assert( 1 == 1.001 ); // no assertion error?? > > (compiled in

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 21, 2018 at 11:16:44PM -0500, Nick Sabalausky (Abscissa) via Digitalmars-d-learn wrote: > Are there any tutorials or articles out there for "getting started > with converting a C++ codebase to D one module at a time?" Or at the > very least: tips, tricks, lessions learned, from those

Re: iota to array

2018-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Feb 25, 2018 at 06:22:03AM +, psychoticRabbit via Digitalmars-d-learn wrote: [..] > printArray(doubleArr); // why is it printing ints instead of doubles?? [...] > void printArray(T)(const ref T[] a) if (isArray!(T[])) > { > foreach(t; a) > writeln(t); Try:

Re: Template Constraints

2018-02-23 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 24, 2018 at 02:54:13AM +, Jonathan via Digitalmars-d-learn wrote: > I am having trouble finding many useful explanations of using template > constraints beyond basic usage. > > I would like to have a template constrant to enforce that a type can > be explicitly cast to another

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 22, 2018 at 10:43:24AM +0200, ketmar via Digitalmars-d-learn wrote: > Nick Sabalausky (Abscissa) wrote: > > > Are there any tutorials or articles out there for "getting started > > with converting a C++ codebase to D one module at a time?" Or at the > > very least: tips, tricks,

Re: What should I use for concat string into array in loop?

2018-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 13, 2018 at 01:58:42AM +, Marc via Digitalmars-d-learn wrote: > appender doesn't support string[] so in such case: Why not? This seems to work: import std.array; import std.stdio; void main() { auto app = appender!(string[]);

Re: uint[3] not equivalent to void[12]?

2018-02-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 09, 2018 at 03:05:33PM +, Ralph Doncaster via Digitalmars-d-learn wrote: > This seems odd to me. Is there a way I can make a function that takes > an array of any type but only of a specific size in bytes? > > void.d(8): Error: function void.foo (void[12] arr) is not callable >

Re: Performance of default and enum parameters

2018-02-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 07, 2018 at 11:04:29PM +, jmh530 via Digitalmars-d-learn wrote: [...] > If check is not passed, I think it depends on how default function > arguments work. I could imagine that it works in two ways: 1) if you > call bar(x), then the compiler effectively re-writes it to bar(x, >

Re: Getting compiler Segfault

2018-02-06 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 05, 2018 at 07:30:09PM +, Ur@nuz via Digitalmars-d-learn wrote: > On Monday, 5 February 2018 at 12:20:05 UTC, Jacob Carlborg wrote: > > On 2018-02-04 13:52, Ur@nuz wrote: > > > Getting compiler stack overflow when building my project, but > > > still do not know how to localize

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 06, 2018 at 06:33:02PM +, Ralph Doncaster via Digitalmars-d-learn wrote: > I've been reading std.conv and std.range, trying to figure out a > high-level way of converting a hex string to bytes. The only way I've > been able to do it is through pointer access: > > import

Re: How to convert hex string to string or ubytes? Thanks.

2018-02-04 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 05, 2018 at 05:48:00AM +, FrankLike via Digitalmars-d-learn wrote: > Now,I can get the string from hex string in compile time,but how to > get it in run time? > > How to get it in run time? [...] Oh wait, I think I misunderstood your original question. Perhaps this is closer to

Re: How to convert hex string to string or ubytes? Thanks.

2018-02-04 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 05, 2018 at 05:48:00AM +, FrankLike via Digitalmars-d-learn wrote: > Now,I can get the string from hex string in compile time,but how to > get it in run time? > > How to get it in run time? > > Thanks. import std.conv; string hex = "900D1DEA"; uint value

Re: Getting compiler Segfault

2018-02-04 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Feb 04, 2018 at 12:52:22PM +, Ur@nuz via Digitalmars-d-learn wrote: > Getting compiler stack overflow when building my project, but still do > not know how to localize piece of code that triggers this bug. Maybe > this bug is already registered in bugzilla or someone could give some >

Re: Should the "front" range primitive be "const" ?

2018-02-02 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 02, 2018 at 07:06:56AM +, Simen Kjærås via Digitalmars-d-learn wrote: [...] > Which code would you rather write? > > void foo(T)(const T t) {} > foo(myValue); > > or: > > void foo(T)(T t) if (isTailConst!T) {} > foo(myValue.tailConst); [...] More thoughts on this: what if we

Re: Should the "front" range primitive be "const" ?

2018-02-02 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 02, 2018 at 07:06:56AM +, Simen Kjærås via Digitalmars-d-learn wrote: > On Thursday, 1 February 2018 at 18:58:15 UTC, H. S. Teoh wrote: > > However, if we go back to the idea of tail-const, we could > > potentially eliminate the need for casts and also avoid breaking > >

Re: Don't expect class destructors to be called at all by the GC

2018-02-01 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 31, 2018 at 01:38:07PM +, Bienlein via Digitalmars-d-learn wrote: > On Thursday, 21 December 2017 at 18:45:27 UTC, Adam D. Ruppe wrote: > > On Thursday, 21 December 2017 at 18:20:19 UTC, H. S. Teoh wrote: > > > When the scoped destruction of structs isn't an option, > > >

Re: Should the "front" range primitive be "const" ?

2018-02-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 01, 2018 at 07:52:32AM +, Simen Kjærås via Digitalmars-d-learn wrote: > On Wednesday, 31 January 2018 at 01:45:57 UTC, H. S. Teoh wrote: > > I haven't thought through it carefully, but if .headConst is a > > viable solution to the head-const problem, then conceivably we could > >

Re: Should the "front" range primitive be "const" ?

2018-01-31 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 31, 2018 at 07:08:58AM +, Simen Kjærås via Digitalmars-d-learn wrote: > On Wednesday, 31 January 2018 at 01:45:57 UTC, H. S. Teoh wrote: > > .headConst > > .headMutable. :p Head-const is something we generally want to avoid. [...] *facepalm* Yes, .headMutable, not .headConst.

Re: Should the "front" range primitive be "const" ?

2018-01-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 30, 2018 at 06:05:47PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, January 30, 2018 07:49:28 H. S. Teoh via Digitalmars-d-learn > wrote: [...] > > Simen has had some ideas recently about "head mutable" aka > > tail-const, which c

Re: Should the "front" range primitive be "const" ?

2018-01-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 30, 2018 at 08:54:00AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/29/18 8:20 PM, Jonathan M Davis wrote: [...] > > If you want to put an attribute on it, inout is better, because then > > it will work with any constness, but in general, I'd suggest just > >

Re: dmd error - unrecognized file extension

2018-01-29 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 29, 2018 at 02:12:13PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/29/18 12:25 PM, Evan Burkey wrote: > > Hi there, I have a problem that is eluding me, hoping someone can > > help me see the light. I'm on Windows 10 using the latest version of > > dmd. I have a

Re: Looks like wrong error message

2018-01-28 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jan 28, 2018 at 10:53:39PM +, welkam via Digitalmars-d-learn wrote: > On Sunday, 28 January 2018 at 20:42:52 UTC, Jonathan M Davis wrote: [...] > > However, you're not going to get an error message that says anything > > like "the arguments aren't the same type." The compiler doesn't >

Re: D generates large assembly for simple function

2018-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 27, 2018 at 07:41:21PM +, Matt via Digitalmars-d-learn wrote: > Playing around with Godbolt, D seems to generate an embarassing amount > of assembly for a simple function (50ish for squaring an int vs 4 for > C++ and 7 for Rust). Even Go compiles to less assembly. > > Is there

Re: Help me understand how to contribute to bugs report / fixing

2018-01-26 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 26, 2018 at 08:43:05PM +, Fra Mecca via Digitalmars-d-learn wrote: [...] > Pull request are done via git and bugs reported by the tracker. The > problem is when I want to understand if the bug of the tracker is > referenced in the repo of the organization and has an open PR. The

Re: Class instance memory overhead lower than 3 words?

2018-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 24, 2018 at 09:48:21PM +, Nordlöw via Digitalmars-d-learn wrote: > Why is the memory overhead for a class instance as high as 3 words (24 > bytes on 64-bit systems? I find that annoyingly much for my knowledge > database application. [...] There's been an attempt to get rid of the

Re: Local static variables must have unique names within a function's scope.

2018-01-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 19, 2018 at 02:16:24PM +, tipdbmp via Digitalmars-d-learn wrote: > > Mostly, it's just a bad idea - it's very easy for a person reading > > the code after you've written it to get the two x's mixed up. > > // example from: 19.17.1.3 > void main() > { > { static int x; } >

Re: Struct initialization syntax

2018-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 18, 2018 at 03:50:15AM +, arturg via Digitalmars-d-learn wrote: > On Wednesday, 17 January 2018 at 17:37:07 UTC, H. S. Teoh wrote: > > On Wed, Jan 17, 2018 at 05:31:03PM +, Azi Hassan via > > Digitalmars-d-learn wrote: > > > The D tour for structs uses a syntax similar to that

Re: Struct initialization syntax

2018-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2018 at 05:31:03PM +, Azi Hassan via Digitalmars-d-learn wrote: > The D tour for structs uses a syntax similar to that of C++ in order > to initialize a Person struct : Person p(30, 180). Is this syntax > supported in D ? Running that part of the code neither works on the >

Re: Any sample how to use Sqlite-d?

2018-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2018 at 01:36:26PM +, Marc via Digitalmars-d-learn wrote: > I was looking for a library to use SQLite with D, found this > (https://code.dlang.org/packages/sqlite-d) but it has no documentation > or code example. I looked into files in the source code and wrote > this: > > >

Re: Function hijack on selective import

2018-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 16, 2018 at 07:14:00PM +, rumbu via Digitalmars-d-learn wrote: > On Tuesday, 26 December 2017 at 20:21:11 UTC, Adam D. Ruppe wrote: > > On Tuesday, 26 December 2017 at 19:41:47 UTC, rumbu wrote: > > > "Custom" is a templated struct. I cannot imagine all the > > > instantiations of

Re: private selective import + overload = breaks accessibility rules

2018-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 16, 2018 at 06:13:27PM +, rumbu via Digitalmars-d-learn wrote: > module a; > > private import std.math: isNaN; > > //custom overload > public bool isNaN(int i) { return false; } > > > = > > module b; > import a; > > void foo() > { > bool b =

Re: core.sys.posix.setjmp unavailable for OS X?

2018-01-15 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 16, 2018 at 08:29:57AM +0100, Jacob Carlborg via Digitalmars-d-learn wrote: > On 2018-01-16 08:29, Jacob Carlborg wrote: > > > They're used to implement Objective-C exceptions on macOS 32bit and > > iOS. > > Forgot the second part: > > ... so I assume that means it works. [...] So

Re: core.sys.posix.setjmp unavailable for OS X?

2018-01-15 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 15, 2018 at 07:06:42PM +, bpr via Digitalmars-d-learn wrote: > Is there a reason that it's unavailable on OS X when it works fine on > Linux? The functions exist on OS X, and it's easy enough to compile C > programs using setjmp there; but not D programs. I don't think I'm >

Re: continue in static foreach

2018-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 12, 2018 at 10:03:40PM +, Marc via Digitalmars-d-learn wrote: > How do I use? > > > static foreach(enum string member; members) { > > static if(isFunction!(__traits(getMember, C, member))) { > > continue; > > } >

Re: How to move an associative array between modules?

2018-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 12, 2018 at 08:46:50PM +, WhatMeWorry via Digitalmars-d-learn wrote: [...] > I hate to keep being a bother, but my project with the below static > this() now compiles fine, but aborts during runtime with a "a problem > caused the program to stop working ..." Is there a way to get

Re: union/toString: crash/segfault: What's happening here?

2018-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 12, 2018 at 10:49:45AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: > On Fri, Jan 12, 2018 at 11:09:47AM +, kdevel via Digitalmars-d-learn > wrote: > [...] [...] > > https://issues.dlang.org/show_bug.cgi?id=18232 > > Yep, definitely a codegen bu

Re: union/toString: crash/segfault: What's happening here?

2018-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 12, 2018 at 11:09:47AM +, kdevel via Digitalmars-d-learn wrote: [...] > On Friday, 12 January 2018 at 02:16:39 UTC, Adam D. Ruppe wrote: [...] > > I'd file this as a compiler codegen bug. > > https://issues.dlang.org/show_bug.cgi?id=18232 Yep, definitely a codegen bug.

Re: Error: out of memory

2018-01-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 10, 2018 at 07:21:21PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: [...] > (and ugh dmd REALLY needs to get its memory consumption under control! > maybe just enabling the GC would help sometimes.) Yeah, no kidding! Recently I also ran into trouble with dmd's memory

<    5   6   7   8   9   10   11   12   13   14   >