Re: Singleton in Action?

2019-02-02 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 02 Feb 2019 17:34:11 +, Eugene Wissner wrote: > For creation get() should be always used, since it is the most > convenient way to ensure that there is really only one instance of the > singleton. Just make this() private, so only you can create new > instances: > > private this() > {

Re: How can I express the type of a function in D?

2019-01-30 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 30 Jan 2019 12:56:06 -0800, Ali Çehreli wrote: > I remember names like _add. Is that a Windows thing? A number of functions are implemented as manually-mangled names with preprocessor macros that forward to them. It's weird, but it happens.

Re: How can I express the type of a function in D?

2019-01-30 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 30 Jan 2019 10:39:21 -0800, Ali Çehreli wrote: > import core.demangle; > > extern(C) int add(int, int); > > void main() { >alias F = typeof(add); >pragma(msg, mangle!F("add")); >pragma(msg, add.mangleof); > } > > Output: > > _D3addUiiZi > add <-- Is that

Re: Should I prefix package names with the name of my program?

2019-01-28 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 28 Jan 2019 16:59:22 +, Victor Porton wrote: > Should I prefix all module names with `xmlboiler.` (where XML Boiler is > the name of my program). These packages are expected to be used > internally by my program, not as an exported API (however there are some > little chances that in

Re: Ordered set container?

2019-01-28 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 28 Jan 2019 17:18:52 +, Victor Porton wrote: > I want "ordered set" container (like list or vector but with the > warranty of no duplicate elements). > > Which type can I use? std.container.rbtree It has options to preserve or squash duplicates.

Re: How is this code supposed to work?

2019-01-25 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 25 Jan 2019 19:14:51 -0500, Steven Schveighoffer wrote: > Interestingly, It's not possible to do the second form, so it's a bit > curious why we don't just drop the requirements for nested > parentheses... The error messages there are really hideous, too: template Just(alias s) { alias

Re: How is this code supposed to work?

2019-01-25 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 25 Jan 2019 09:34:47 +, AndreasDavour wrote: >auto point3 = getResponse!Point!int("What's the point? "); This could be: getResponse!(Point!int) or: (getResponse!Point)!int D requires this to be disambiguated at the parsing stage, before the compiler works out what

Re: std.socket.Address not allowed in tuples

2019-01-23 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 24 Jan 2019 01:35:57 +, Steven O wrote: > Is there any documentation or examples of how to do that? The > RedBlackTree documentation gives trivial examples like You define a function implementing the "less" operation for a pair of Tuple!(Address, int) (or whatever you have). ---

Re: opEquals() non-standard return type

2019-01-23 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 23 Jan 2019 15:19:06 +, Jacob Shtokolov wrote: > I'm wondering, is that possible to declare multiple versions of > opEquals() and evaluate them in the different places depending on return > type? I looked at this a while ago for similar reasons. It didn't pan out. When you override

Re: std.socket.Address not allowed in tuples

2019-01-23 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 23 Jan 2019 15:56:15 +, Steven O wrote: > Why am I not allowed to put Address types in tuples? As always, it helps a lot to post the error message the compiler gave you. The message is: /usr/include/dmd/phobos/std/functional.d-mixin-215(215): Error: template

Re: Deprecation

2019-01-18 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 18 Jan 2019 22:53:23 +, Ali wrote: > Hello. I am having an issue with the code below. the out put after > compiling is this : > > Deprecation: foreach: loop index implicitly converted from size_t to > uint > > the code is : > > auto available = new int[cast(uint) max - min]; >

Re: Is there a nice syntax to achieve optional named parameters?

2019-01-18 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 18 Jan 2019 09:39:31 +, John Burton wrote: > On Thursday, 17 January 2019 at 01:43:42 UTC, SrMordred wrote: > >> struct Config { >> string title; >> int width; >> } >> >> struct Window { >> this(Config config) > > It likely is a bad idea for a small struct like this

Re: Runtime heterogeneous collections?

2019-01-18 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 18 Jan 2019 10:07:41 -0500, Steven Schveighoffer wrote: > But what is the common interface between those 2 types? Even in > Dcollections, where RedBlackTree came from, there was no interfaces that > didn't specify the type they were dealing with. In other words, there is > no common

Re: Runtime heterogeneous collections?

2019-01-16 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 17 Jan 2019 02:21:21 +, Steven O wrote: > I want to create a heterogeneous collection of red-black trees, and I > can't seem to figure out if it's possible. RedBlackTree!int and RedBlackTree!string are entirely different types (they just happen to be generated from the same

Re: unittest which uses a disk file

2019-01-16 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 16 Jan 2019 21:07:24 +, Victor Porton wrote: > What is the rule for unittest which uses a file (containing example data > for testing) available only in the source distribution, not in binary > distribution? > > I am writing a library. The easy way of doing things is to define a

Re: What is the Utility of Parent Class Method Hiding in Inheritance?

2019-01-16 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 16 Jan 2019 12:01:06 -0500, Steven Schveighoffer wrote: > It was 2.068 that removed the HiddenFuncError, and made this a compile > error instead. If your compiler is that or newer, definitely file a bug > report. Oh god, that must have been awful. I'm glad we're no longer in those

Re: problem extracting data from GtkSourceView using Gtkd

2019-01-14 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 14 Jan 2019 22:52:48 +, Chris Bare wrote: > auto start = new TextIter(); > auto end = new TextIter(); You shouldn't need to new these. `out` means that the function is going to overwrite the variables. Other than that, I'm not sure.

Re: What is the Utility of Parent Class Method Hiding in Inheritance?

2019-01-14 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 14 Jan 2019 09:10:39 +, Vijay Nayar wrote: > a.foo(1); // issues runtime error (instead of calling > A.foo(int)) Calling the function doesn't issue any sort of error. Overriding one overload without overloading or explicitly aliasing in the rest issues a compile-time error.

Re: nice-curses releases / dub version git?

2019-01-12 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 12 Jan 2019 12:10:25 +, Droggl wrote: > 2. Is there a way to get a certain git-version (eg. commit or maybe even > just "latest") for a package in dub? git submodule and path-based dependencies, if you need a particular version. > 3. How is everyone in general using curses with D?

Re: Coedit almost works for me, except when I go to add peggged

2019-01-11 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 11 Jan 2019 17:25:29 +, Enjoys Math wrote: > Package peggged not found for registry at https://code.dlang.org/ The package name is pegged, not peggged. Two g's, not three.

Re: Forward declaration inside Function block, no error?

2019-01-06 Thread Neia Neutuladh via Digitalmars-d-learn
On Sun, 06 Jan 2019 20:19:59 +, Rubn wrote: > You can declare functions inside of functions in D. You weren't forward > declare grow() in the module namespace, so much as you were forward > declaring a new function grow. Unfortunately, you can't do forward declarations for nested functions.

Re: Co-developing application and library

2019-01-05 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 05 Jan 2019 17:44:27 +, Neia Neutuladh wrote: > 2. Different build configurations. The same source code has two > different build targets; the executable doesn't depend on the library. > Or, with enough bludgeoning, you can make the executable depend on the > library. Hit 'send' too

Re: Co-developing application and library

2019-01-05 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 05 Jan 2019 13:01:24 +, 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

Re: reimplementing an interface in a derived class

2019-01-04 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 04 Jan 2019 08:46:24 +, Alex wrote: > Let's assume this is right. How to force a B object to behave like an A > object? I thought casting is a possible approach... It requires a bit of surgery: import std.stdio; class A { void foo() { writeln("hello from A!"); }

Re: reimplementing an interface in a derived class

2019-01-03 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 04 Jan 2019 00:19:05 +, Alex wrote: > B.foo overrides A.foo. By casting a B object to be an A object, A's > behavior should be granted, shouldn't it? I can't think of a single class system that works like that. C++, Java, C#, Dart, and TypeScript all work like D here. GObject in C

Re: reimplementing an interface in a derived class

2019-01-03 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 03 Jan 2019 23:44:15 +, Alex wrote: > I assume that is another bug and has nothing to do with interfaces... B.foo is both overriding A.foo and implementing D.foo, so that's not a bug.

Re: reimplementing an interface in a derived class

2019-01-03 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 03 Jan 2019 22:30:48 +, kdevel wrote: > class A : D { > int foo() { return 1; } > } > > class B : A, D { > [...] > > What is the meaning of the ", D"? It does not seem to make a difference > if it is omitted. B must provide its own implementation of D. It can't simply use A's

Re: What's wrong with this template function?

2019-01-03 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 03 Jan 2019 20:34:17 +, Machine Code wrote: > Thank you very much, Ali. So the issue was basically I can't return from > a static foreach() loop right? The static foreach is done at compile time and the return is done at runtime. After the template is expanded, your code ends up

Re: Subtypes with tighter constraints

2019-01-01 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 01 Jan 2019 14:05:43 +, Victor Porton wrote: > In Ada2012 there are "subtypes". Subtypes can have tighter constraints > (such as type invariants) than their base types. > > I have a struct X in D. Is it possible to define a type equivalent to X > except that having tighter invariants?

Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 01 Jan 2019 14:46:15 +, Ron Tarrant wrote: > I've found a ton of syntax highlighter plugins for WordPress, but none > that admit to supporting D. Anyone know of one? I believe I use Enlighter for that: https://wordpress.org/plugins/enlighter/

Re: Why can't or shouldn't I just hash the address of an object? And how.

2018-12-29 Thread Neia Neutuladh via Digitalmars-d-learn
On Sun, 30 Dec 2018 05:36:41 +, Enjoys Math wrote: > Is it: > > typeof(T).getHash()? This gets the hashcode for the object by calling toHash() on it. > Or does that do something other than just get the address? It XORs the address with a bitwise rotation of the address. This reduces

Re: class template conflict

2018-12-25 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 25 Dec 2018 18:34:04 +, bauss wrote: > I think there is a bigger problem at stake here in terms of software > architecture. > > What's the point needed for them to have the same identifier? A probably abstract base class with only one child class. Normally you have "Foo" and

Re: Determination of thread status.

2018-12-25 Thread Neia Neutuladh via Digitalmars-d-learn
1. Find the Thread object: Tid threadId = spawn(); auto thread = Thread.getAll.filter!(x => x.id == threadId).front; 2. Check the `isRunning` property. The indirection with spawn() is awkward.

Re: class template conflict

2018-12-25 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 25 Dec 2018 16:55:36 +, Neia Neutuladh wrote: And I forgot part of it. Let's say we did the work to make this function: class X {} template X(int N) { // `: X` somehow refers to the X in the outer scope class X : X {} } How do you distinguish between the

Re: class template conflict

2018-12-25 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 25 Dec 2018 13:03:13 +, Michelle Long wrote: > But I am not talking about inside the template being used. The whole > point of doing this is so that one can refer to the base class using the > same name as the derived with a template parameter to make a composite > structure. The

Re: Mysteries of the Underscore

2018-12-24 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 24 Dec 2018 08:16:01 -0800, H. S. Teoh wrote: > Rather, it's *conventionally* taken to mean "unused". The language > actually does not treat it in any special way apart from "normal" > identifiers. It's perfectly valid (though probably not recommended!) to > declare functions or

Re: How to deprecate member function from outside?

2018-12-22 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 22 Dec 2018 21:33:14 +, Dru wrote: > The first example shows that it is possible to deprecate a function > separately from it's definition. No, it doesn't. You declared two *different* functions. One was deprecated; the other wasn't. > I want to know if it is possible to "fix" the

Re: How to deprecate member function from outside?

2018-12-22 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 22 Dec 2018 18:55:47 +, Dru wrote: > I would like to use "deprecated" on a member function, but do it from a > separate file > > this works: > /// > void func() {} > > deprecated { >void func(); > } You're defining two functions, presumably in two different modules and with two

Re: using dub to compile plugins

2018-12-21 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 21 Dec 2018 10:56:39 +, Atila Neves wrote: > I don't see how you can do this with dub, and I wouldn't attempt it > either. Just use make, and have make call dub for the main project (and > potentially any plugins that need it). Remember to make the dub targets > `.PHONY` since you

Re: Mixin operator 'if' directly

2018-12-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 19 Dec 2018 15:12:14 +, bauss wrote: > That's assuming that it's compile-time data though. > > If not then you can't do what you want to do. > > What you can do is wrap it in a function in the mixin template which you > just call after instantiating it. Or while instantiating it:

Re: using dub to compile plugins

2018-12-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 19 Dec 2018 12:57:14 +, Codifies wrote: > I could do this with a few simple rules in a Makefile, but I have no > clue how to achieve this using dub. If you need dub, you can create a wrapper script that generates the dub file for the plugins directory. Make is a lot better for this

Re: saving std.random RNG state

2018-12-17 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 17 Dec 2018 22:20:54 +, harfel wrote: > I am looking for a way to serialize/deserialize the state of the > std.random.Random number generator, ideally using orange > (https://github.com/jacob-carlborg/orange) or another serialization > library. From looking at the module source code, I

Re: Shared static this() not executed for unittest

2018-12-15 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 15 Dec 2018 17:19:05 +, Timoses wrote: > Running `dub test` will output: > Running ./unit-test-library writeln: unittest All unit tests have been > run successfully. > > Why is the `shared static this()` not executed? Run `dub clean; dub test -v` and you'll see that main.d isn't

Re: How to initialize a globle variable nicely and properly?

2018-12-15 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 15 Dec 2018 13:49:03 +, Heromyth wrote: > Yes, it's very dangerous to create a new thread in shared static this(). > For a big project, it sometimes hard to identify this problem. Maybe, > the compiler should do something for this, should it? The runtime, more likely. There are plenty

Re: How to initialize a globle variable nicely and properly?

2018-12-14 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 15 Dec 2018 02:54:55 +, Heromyth wrote: > shared static this() { > writeln("running A in shared static this(), > sharedField=", sharedField); > > Thread th = new Thread(() { }); > th.start(); When you start a D thread, thread-local static constructors

Re: Bug in shifting

2018-12-13 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 14 Dec 2018 00:16:51 +, Michelle Long wrote: > byte x = 0xF; > ulong y = x >> 60; "Error: shift by 60 is outside the range 0..31" This is the result of integer promotion rules. Change the 30 to a 60 and it works, and the result is, as you would expect, 0. > I thought D required

Re: How to set constant value to environment variable at compile time?

2018-12-10 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 10 Dec 2018 17:58:32 +, aliak wrote: > string parseConfig(string str) { >string ret; >foreach (line; str.split("\n")) { > auto parts = line.split("="); > ret ~= `string ` ~ parts[0] ~ ` = "` parts[2] `";`; >} >return ret; > } That works as long as none of the

Re: How to set constant value to environment variable at compile time?

2018-12-10 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 10 Dec 2018 11:08:23 +, Narxa wrote: > Hello, people! > > I would like to have a constant with the value of some environment > variable that is defined at compile time. In your build script, echo the environment variable into a file. Then import() that file and use the value. > I

Re: dmd -unittest works poorly with executables

2018-12-08 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 08 Dec 2018 20:16:09 +, Andrew Pennebaker wrote: > I think it's lame to have to use magical code like `version(unittest) {} > else` to guard our main functions, when we run unit tests. Could D go > ahead and do the right thing, automatically shadowing our main functions > when the unit

Re: Compiling a template

2018-12-06 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 06 Dec 2018 22:50:49 +, albertas-jn wrote: > If templates are a compile-time feature and instances of templates are > generated by compiler at compile time, why is it possible to compile a > template definition with dmd -lib or -c? You compile files, not individual declarations like a

Re: Trying to get current function name results in compiler error with __traits

2018-12-06 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 07 Dec 2018 02:37:34 +, Arun Chandrasekaran wrote: > I'm trying to get the current function name and apparently the commented > line errors out. > > What am I doing wrong? Referring to nested functions is weird. Dotted identifiers let you traverse aggregates. Modules, C++ namespaces

Re: .dup vs operation on all elements

2018-12-03 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 03 Dec 2018 21:27:52 +, faissaloo wrote: > Then shouldn't the following output false, false, true? An object reference is a pointer value. The pointer values are copied. The pointed-at objects are not copied. Furthermore, the syntax Object[6] array = new Object(); only

Re: what are the rules for @nogc and @safe attributes inference?

2018-11-30 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 30 Nov 2018 22:10:11 +, ikod wrote: > Thanks for explanation, got it. > > My case is actually > > interface I(K,V) > { > int get()(K); > } Interface functions must be abstract. Templated functions are implicitly final. Final things can't be abstract. If there's something

Re: what are the rules for @nogc and @safe attributes inference?

2018-11-30 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 30 Nov 2018 20:41:03 +, ikod wrote: > I can't find the reason why nogc/nothrow can't be inferred in this case: > > class S(K,V) > { > auto get/*()*/(K a) { > return 0; > } > } > void main() @nogc nothrow { > S!(int, string) sia; > auto v = sia.get(1); > }

Re: Function signature as string

2018-11-29 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 29 Nov 2018 21:11:06 +, John Chapman wrote: > Is there any way to get a string representing a function's exact > signature as declared in the source? I can generate it myself using > reflection but it might not be 100% verbatim so wanted to know if > there's anything built in? > >

Re: What can I use to parse a date string in a custom format?

2018-11-27 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 27 Nov 2018 18:22:17 +, PacMan wrote: > I've been looking for a function or library to parse a date in a custom > format (for validation) similar to C#'s [1] > TryParseExactbut I couldn't find any. so far I only found > fromISOExtString(), and fromSimpleString() which doesn't allow me

Re: How do I the temlate parameter name as string?

2018-11-26 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 27 Nov 2018 02:00:44 +, PacMan wrote: > f is defined as: > >> void f(T)(T t, string p) >> if(is(T == A) || is(T == B)) >>{ >> // ... >>} > > my goal is get "p" as string. `f` is a template that generates functions. Before you instantiate that template, the function doesn't

Re: D Language 2.1

2018-11-25 Thread Neia Neutuladh via Digitalmars-d-learn
On Sun, 25 Nov 2018 20:46:28 +, Tony wrote: > From std.compiler.D_major and std.compiler.D_minor I see that my D > language version is at 2.0 . But the version of gdc front-end I am using > (via Debian default gdc package as of a few months ago) from > std.compiler.version_major and

Re: How to get all modules in a package at CT?

2018-11-24 Thread Neia Neutuladh via Digitalmars-d-learn
Easiest way is to put this in your build script: find path/to/package -name '*.d' | \ xargs grep '^module ' | \ sed 's,^module,import,' \ > data/modules.d Add `-J data` to your DMD command line, or add `"stringImportPaths": ["data"]` to dub.json. Then in your file:

Re: version(StdDoc)

2018-11-23 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 23 Nov 2018 21:43:01 -0700, Jonathan M Davis wrote: > A solution like that might work reasonably well, but you still > have the problem of what to do when a symbol is documented in multiple > version blocks, and having almost all the documentation in one version > block and a few pieces of

Re: version(StdDoc)

2018-11-23 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 23 Nov 2018 17:21:25 -0800, H. S. Teoh wrote: > Ddoc may have its stink points, but in this case, the stuff inside > version(Windows) blocks simply isn't compiled, so you can't expect ddoc > to do much about it. You can't just arbitrarily ddoc everything inside > version blocks, because

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-22 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 22 Nov 2018 15:50:01 +, Stefan Koch wrote: > I'd say the problem here is not just false positives, but false > negatives! False negatives are a small problem. The compiler fails to catch some errors some of the time, and that's not surprising. False positives are highly vexing

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 21 Nov 2018 20:15:42 +, welkam wrote: > In D classes are reference type and unless you mark them as final they > will have vtable. Even if you mark your class as final, it has a vtable because it inherits from Object, which has virtual functions. The ProtoObject proposal is for a

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 21 Nov 2018 17:00:29 +, Alex wrote: > C# wouldn't reject the case above, would it? C# *would* reject that (you can't call any methods on a null object), but in D, it compiles and runs and doesn't segfault.

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-20 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 20 Nov 2018 23:14:27 +, Johan Engelen wrote: > When you don't call `a.foo()` a dereference, you basically say that > `this` is allowed to be `null` inside a class member function. (and then > it'd have to be normal to do `if (this) ...` inside class member > functions...) That's what

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-20 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 20 Nov 2018 15:29:50 +, Kagamin wrote: > On Tuesday, 20 November 2018 at 11:11:43 UTC, aliak wrote: >> This only applies to little scripts and unittests maybe. >> >> Not when you're writing any kind of relatively larger application that >> involves being run for longer or if there's

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 20 Nov 2018 00:30:44 +, Jordi Gutiérrez Hermoso wrote: > On Monday, 19 November 2018 at 21:57:11 UTC, Neia Neutuladh wrote: > >> Programmers coming from nearly any language other than C++ would find >> it expected and intuitive that declaring a class instance variable >> leaves it

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

2018-11-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 19 Nov 2018 14:32:55 -0800, H. S. Teoh wrote: >> Standard caveats about byte order and alignment. > > Alignment shouldn't be a problem, since local variables should already > be properly aligned. Right, and the IO layer probably doesn't need to read to aligned memory anyway. Struct

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

2018-11-19 Thread Neia Neutuladh via Digitalmars-d-learn
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 > now is something like this > > byte[4] fake_integer; > auto fd = File("binary.data", "r"); >

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 19 Nov 2018 21:23:31 +, Jordi Gutiérrez Hermoso wrote: > When I was first playing with D, I managed to create a segfault by doing > `SomeClass c;` and then trying do something with the object I thought I > had default-created, by analogy with C++ syntax. Seasoned D programmers > will

Re: Neater enum + version

2018-11-18 Thread Neia Neutuladh via Digitalmars-d-learn
On Sun, 18 Nov 2018 17:47:07 +, Vladimirs Nordholm wrote: > Is there anyway to make it "neater"? Maybe something in one line: > > enum foo = version (Posix) { "posix" } : { "other" } ; If you're doing it often: T ifPosix(T)(T a, T b) { version (Posix) return a; else return b; } enum

Re: How do you debug @safe @nogc code? Can't figure out how to print.

2018-11-17 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 17 Nov 2018 21:16:13 +, aliak wrote: > Could do. But it's not scalable. I'd have to comment out all the > unittests that call the template function with a T that allocates inside > the @nogc template (if I understood you correctly that it) I meant something like: void

Re: Making external types available to mixins

2018-11-17 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 17 Nov 2018 17:58:54 +, John Chapman wrote: > The idea is that users could type (for example) makeWith!`Calendar`(…) > instead of the longer makeWith!ICalendarFactory(…). Your project might define a hundred types named ICalendarFactory; the compiler can't figure out which one you're

Re: How do you debug @safe @nogc code? Can't figure out how to print.

2018-11-17 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 17 Nov 2018 13:55:24 +, aliak wrote: > You can use "debug blah" to hide inside functions that are attributed, > but when you have an attributed function that calls a template, > attribtues of which are supposed to be inferred, it seems to fail. You can explicitly mark a templated

Re: Could not setup D extension on vs code

2018-11-14 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 14 Nov 2018 19:28:44 +, WebFreak001 wrote: > It's a real pain that you can't select specific commits in dub, but I > try to keep up with the updates and make them work somehow. Yeah, I've used submodules and path-based dependencies once or twice because of that. It's not the best.

Re: dip1000: why can't the addressee come into existence later?

2018-11-10 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 10 Nov 2018 16:25:40 +, Stanislav Blinov wrote: > Yep, you just over-simplified the first case. It is too simple to clearly illustrate why the code is invalid, but not so simple that the compiler accepts that code. > Consider: > > int* p; > { > int i; > p = > } > *p =

Re: dip1000: why can't the addressee come into existence later?

2018-11-10 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 10 Nov 2018 11:47:24 +, Nicholas Wilson wrote: > On Saturday, 10 November 2018 at 06:56:29 UTC, Neia Neutuladh wrote: >> Is this right? > > Are you sure you added @safe to the second example? > https://run.dlang.io/is/2RbOwK fails to compile. Maybe take another look at the post

dip1000: why can't the addressee come into existence later?

2018-11-09 Thread Neia Neutuladh via Digitalmars-d-learn
The following code doesn't work with @safe -dip1000: int* p; int i; p = i has a shorter lifetime than p, the compiler complains. But this code does: int i; int* p; p = In both cases, p can't point to i before i exists, and p ceases to exist when i ceases to exist.

Re: Why is stdio ... stdio?

2018-11-08 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 09 Nov 2018 02:03:36 +, Chris Katko wrote: > Simple curious question. > > Why isn't : > > import std.stdio; > > instead: > > import std.io; IO includes things like memory mapping, sockets, listing files, named pipes, that sort of thing. Standard IO includes only reading and

Re: Exception slipping through the catch block?

2018-11-08 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 08 Nov 2018 17:27:40 -0700, Jonathan M Davis wrote: > You ran into one of the rare cases where it makes sense catch an Error > or a Throwable, and you're one of the few people who understands the > situation well enough to deal with it properly. The vast majority of D > programmers don't.

Re: scoped classes and dependency inversion

2018-11-08 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 08 Nov 2018 11:04:19 +, Sjoerd Nijboer wrote: > I'm trying to invert the dependency from the classes `Bar -> Foo` to > `Foo -> IFoo <- Bar` at compile time. > > I do want `Foo's` to be embedded into `Bar` These goals are a *little* at odds with each other; having a scoped!Foo puts

Re: scoped classes and dependency inversion

2018-11-08 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 08 Nov 2018 12:45:57 +, Alex wrote: > Hmm... not sure, if I got your idea... Do you think about something like > this? The point is dependency inversion. The class shouldn't need to know how to build its dependencies; it should leave that to other code. The fact that you can use the

Re: Is this a bug? +goto

2018-11-05 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 06 Nov 2018 00:33:56 +, MatheusBN wrote: > Just to be clear, when you say "x exists at the label Q", you mean at > the same scope, right? The same or an outer scope. It's also invalid to write: goto Y; { int x; { Y: } } > That's interesting but a bit confusing isn't? > >

Re: Dealing with raw types as attributes

2018-11-01 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 02 Nov 2018 04:01:00 +, Nicholas Wilson wrote: > By noting that all (interesting for the purpose of UDA's i.e. not void) > types have a .init > > or you could do > > static if (is(typeof(uda) == Foo) || is(uda == Foo)) Which, again, only tests for presence, when I want to check for

Re: Dealing with raw types as attributes

2018-11-01 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 02 Nov 2018 00:36:18 +, Nicholas Wilson wrote: >> What do you do to handle this? > > @Foo() int bar; > > instead of > > @Foo int bar; Right. And if you're offering a library with UDAs for other people to use?

Re: Removing the precision from double

2018-11-01 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 01 Nov 2018 23:59:26 +, kerdemdemir wrote: > I am doing trading and super scared of suprices like mathematical errors > during the multiplications(or division 1/tickSize) since market will > reject my orders even if there is a small mistake. > > Is this safe? Or is there a better way

Re: Dealing with raw types as attributes

2018-11-01 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 01 Nov 2018 20:01:51 +, Stanislav Blinov wrote: > Check if an UDA is a type?.. As in, not just `is(uda == Foo)`, > but simply `is(uda)`: Which works, but generally makes things more complex in code that's already pretty deeply nested. It's also something I have to worry about every

Re: Dealing with raw types as attributes

2018-11-01 Thread Neia Neutuladh via Digitalmars-d-learn
On Thu, 01 Nov 2018 11:35:27 -0700, Ali Çehreli wrote: > On 11/01/2018 09:14 AM, Neia Neutuladh wrote: >> The spec says that a user-defined attribute must be an expression, but >> DMD accepts a wide range of things as UDAs: >> >>struct Foo { string name = "unknown"; } >>@Foo int bar; >>

Dealing with raw types as attributes

2018-11-01 Thread Neia Neutuladh via Digitalmars-d-learn
The spec says that a user-defined attribute must be an expression, but DMD accepts a wide range of things as UDAs: struct Foo { string name = "unknown"; } @Foo int bar; `bar` has the *type* Foo as an attribute. It's not an *instance* of Foo. So if I try to look at the UDAs: static

Re: how to make '==' safe for classes?

2018-10-28 Thread Neia Neutuladh via Digitalmars-d-learn
On Sun, 28 Oct 2018 18:00:06 +, Stanislav Blinov wrote: > On Sunday, 28 October 2018 at 12:38:12 UTC, ikod wrote: > >> and object.opEquals(a,b) do not inherits safety from class C >> properties, and also I can't override it. > > Yep. Since Object is the base class and it defines opEquals

Re: Dub Renaming source/app.d makes project a library

2018-10-27 Thread Neia Neutuladh via Digitalmars-d-learn
targetType "executable" does it for me (dub 1.11.0). Can you post your full dub.sdl?

Re: static foreach

2018-10-10 Thread Neia Neutuladh via Digitalmars-d-learn
On 10/10/2018 04:03 PM, James Japherson wrote:> Says that it cannot interpret X(the class that contains the static> opApply). It's a bit hard to diagnose the problem you're getting using that function when we don't have the code that uses it. Or the context that's referenced with the foreach

Re: Simple parallel foreach and summation/reduction

2018-09-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Thursday, 20 September 2018 at 05:34:42 UTC, Chris Katko wrote: All I want to do is loop from 0 to [constant] with a for or foreach, and have it split up across however many cores I have. You're looking at std.parallelism.TaskPool, especially the amap and reduce functions. Should do pretty

Re: Fast linear search for non-null key in slice of Nullable(T, T.max)

2018-09-16 Thread Neia Neutuladh via Digitalmars-d-learn
On Sunday, 16 September 2018 at 16:28:20 UTC, Per Nordlöw wrote: If I have alias N = Nullable!(T, T nullValue) fed as template parameter to another template how can I at compile-time get the `nullValue` ? import std.traits; enum nullValue = TemplateArgsOf!(N)[1];

Re: Shared, ref, arrays, and reserve template instantiation

2018-09-12 Thread Neia Neutuladh via Digitalmars-d-learn
On Wednesday, 12 September 2018 at 23:41:16 UTC, James Blachly wrote: When I add the "shared" attribute to an array, I am no longer able to call reserve because the template won't instantiate: Error: template object.reserve cannot deduce function from argument types !()(shared(int[]), int),

Re: Load entire file, as a char array.

2018-09-02 Thread Neia Neutuladh via Digitalmars-d-learn
On Monday, 3 September 2018 at 03:04:57 UTC, Chris Katko wrote: This should be simple? All I want to do is load an entire file, and access individual bytes. The entire thing. I don't want to have know the file size before hand, or "guess" and have a "maximum size" buffer. So far, all google

Re: How to use listener.d example?

2018-08-31 Thread Neia Neutuladh via Digitalmars-d-learn
On Friday, 31 August 2018 at 07:38:54 UTC, Marcin wrote: https://github.com/dlang/dmd/blob/master/samples/listener.d Can some one add more comment to that example? I need to make code that connects to local application, very similar to this. Assumptions: 1. Create an application that

Re: extern __gshared const(char)* symbol fails

2018-08-31 Thread Neia Neutuladh via Digitalmars-d-learn
On Friday, 31 August 2018 at 06:20:09 UTC, James Blachly wrote: Hi all, I am linking to a C library which defines a symbol, const char seq_nt16_str[] = "=ACMGRSVTWYHKDBN"; In the C sources, this is an array of 16 bytes (17 I guess, because it is written as a string). In the C headers, it

Re: Are properties mature enough?

2018-08-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Sunday, 19 August 2018 at 18:32:17 UTC, QueenSvetlana wrote: In the D Style Guide, it says: Properties https://dlang.org/dstyle.html#properties Functions should be property functions whenever appropriate. In particular, getters and setters should generally be avoided in favor of property

Re: Dub project has both .sdl and .json files. Is this normal or did I do something wrong?

2018-08-04 Thread Neia Neutuladh via Digitalmars-d-learn
On Friday, 3 August 2018 at 19:41:32 UTC, Bastiaan Veelo wrote: But if you commit it, and a compiler deprecation causes a dependency in that pinned version to fail to compile, then your app won't compile either, even though your code itself does not suffer from the deprecation and even though

  1   2   >