Re: Escape this in pure members

2020-09-22 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-19 21:50, Per Nordlöw wrote: On Saturday, 19 September 2020 at 18:48:31 UTC, Jacob Carlborg wrote: A nested class seems to be able to escape the `this` reference: Ahh, thanks. I just realized that it can escape into other parameters without the `scope` qualifier? This class

Re: Escape this in pure members

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-19 18:07, Per Nordlöw wrote: If an aggregate member is pure but not scope when can it escape the `this` pointer?. Only via return? I'm not sure if returning the `this` pointer is considered escaping it. The caller already had access to it. Under the hood, the `this` pointer is

Re: Good repos to learn D

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On Saturday, 19 September 2020 at 08:26:36 UTC, Imperatorn wrote: What are some good examples of pretty large/medium size, good structured repos in D? I'm looking for examples to learn from Thanks! Here are some examples of large projects: * DWT [1]. This is one of the largest D projects

Re: DDoc generation

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On Saturday, 19 September 2020 at 07:43:24 UTC, Russel Winder wrote: Doesn't that then make the whole DDoc system fairly useless, despite it's use in Phobos? If you use Dub, you can run `dub build -b ddox` and it will use Ddox to build the documentation. This will include an index page

Re: DDoc generation

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On Saturday, 19 September 2020 at 07:43:24 UTC, Russel Winder wrote: Doesn't that then make the whole DDoc system fairly useless, despite it's use in Phobos? Yes. The problem is that most things in D are compared with C or C++. People are praising that the built-in support for unit tests

Re: Question about linker errors when using slices

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-19 04:45, tspike wrote: I’ve been using D for personal projects for almost a year now and I really love it. I recently ran across a linker error that I’m a little confused by. Consider the following files: platform.d:     module platform;     import app;     struct

Re: Proper way to exit with specific exit code?

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-17 16:58, drathier wrote: What's the proper way to exit with a specific exit code? I found a bunch of old threads discussing this, making sure destructors run and the runtime terminates properly, all of which seemingly concluding that it's sad that there isn't a way to do this

Re: DDoc generation

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-18 13:41, Russel Winder wrote: Hi, I am trying to get to grips with DDoc for documenting an application. Getting the individual module HTML files seems to be the easy bit. The question is how to get an index.html (or equivalent) so as to have an application level entry point to the

Re: get element index when using each!(x)

2020-09-18 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-17 05:16, Paul Backus wrote: Worth knowing that the tuples you get from enumerate actually have named members, so you can write:     s.enumerate.each!(x => writeln(x.index, ":", x.value)); It actually works out of the box for `each`: s.each!((index, value) => writeln(index,

Re: Neater "not version (...)" ?

2020-09-18 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-16 21:04, Vladimirs Nordholm wrote: Ah, I guess it boils down to this then. Doesn't really make it "neater", but thank you for the tip! You only need to declare the enums ones. -- /Jacob Carlborg

Re: Neater "not version (...)" ?

2020-09-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-16 19:53, Vladimirs Nordholm wrote: Hello. I wonder if there is a better way to compile something if the current operating system is _not_ a specific platform. For example, I only want some code to compile if the operating system is not Windows. Currently I do this:    

Re: tupleof seems to break encapsulation

2020-09-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-05 07:14, 60rntogo wrote: I wouldn't dispute that it is useful, but that's besides the point. If I declare something private, it's usually because I want to preserve certain invariants and I want the compiler to provide a guarantee that I don't accidentally violate them. As it

Re: tupleof seems to break encapsulation

2020-09-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-04 12:16, 60rntogo wrote: Consider the following code. foo.d --- module foo; struct Foo {   private int i; } --- main.d --- void main() {   import std.stdio;   import foo;   auto x = Foo();   writeln(x);   // ++x.i;   ++x.tupleof[0];   writeln(x); } --- As expected, the

Re: Install multiple executables with DUB

2020-09-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-03 14:41, glis-glis wrote: Yes I already tried that, but I get the error Error: only one main allowed. Previously found main at src/scripts/copy.d Looks like DUB doesn't like multiple binaries? Oh, multiple binaries, I missed that. You can try to add multiple configurations [1].

Re: Install multiple executables with DUB

2020-09-03 Thread Jacob Carlborg via Digitalmars-d-learn
On Thursday, 3 September 2020 at 08:22:25 UTC, glis-glis wrote: I usually would just write a makefile for that, but I thought I'd give DUB a go. Unfortunately, the DUB-documentation is a little thin and I cannot find a way to tell DUB "compile all the files in the scripts folder and put the

Re: Installing D on Fresh Windows 10 machine is a pain

2020-08-28 Thread Jacob Carlborg via Digitalmars-d-learn
On Friday, 28 August 2020 at 05:38:59 UTC, novice3 wrote: DMD x86 on Windows have no dependencies, just unpack .zip and use. It's a pitty, that DMD x64 depend on VS :( It does not. If VS is not installed the MinGW provided libraries, which are bundled, will be used. -- /Jacob Carlborg

Re: How does D's templated functions implementation differ from generics in C#/Java?

2020-08-08 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-08-07 23:03, aberba wrote: Syntactically they look the same (although D's can do more things) so I'm trying to understand how why in D it's called template but in languages like C#/Java they're generics. I guess I have fair understanding of D's code generation but isn't it same as

Re: How does D's templated functions implementation differ from generics in C#/Java?

2020-08-08 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-08-07 23:39, H. S. Teoh wrote: They are *very* different. Java generics are based on "type erasure", i.e., at the syntactic level, containers are parametrized with the element types, but at the implementation level, the element types are merely "erased" and replaced with Object (a top

Re: Invoking the compiler during runtime

2020-08-05 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-08-05 09:57, cy wrote: Well, I did find this: https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/ That is more for using the frontend, not the backend for generating code. But it's pretty advanced... probably just invoking dmd would be good... You can

Re: Using D within a rust codebase

2020-07-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-07-27 13:43, Ali Çehreli wrote: They should be taken care of when the program is linked with a D compiler. Just linking with a D compiler is not sufficient. There needs to be a D main function for the runtime to automatically be initialized. If you make the D code a bit more

Re: Using D within a rust codebase

2020-07-27 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-07-27 03:03, Paul Backus wrote: extern(C) void hello() { import std.stdio: writeln; writeln("Hello from D!"); } The D runtime needs to be initialized first [1]. Then it should be terminated as well [2]. [1] https://dlang.org/phobos/core_runtime.html#.rt_init [2]

Re: Question about publishing a useful function I have written

2020-07-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-07-14 23:58, Cecil Ward wrote: What’s the best way to publish a D routine ? As others have already said, on GitHub. Then as a Dub package as well [1]. [1] https://code.dlang.org -- /Jacob Carlborg

Re: misc questions about a DUB package

2020-07-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-07-15 04:20, 9il wrote: No. Usually, a DUB package supports a range of C library version or just a fixes set of C API. The version behavior of the dub package is up to you. Usually, D API changes more frequently than the underlying C library. If you support a specific version of the C

Re: Bind C++ class to DLang : undefined reference to `Canvas::Foo()'

2020-07-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-07-14 05:33, Boris Carvajal wrote: Can you try passing -D_GLIBCXX_USE_CXX11_ABI=0 to g++ and -version=_GLIBCXX_USE_CXX98_ABI to dmd. That comes from: https://dlang.org/changelog/2.088.0.html#std_string C++11 ABI is currently not supported. I based on previous messages and the usage

Re: Choosing a non-default linker for dmd (via dub)

2020-07-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-07-12 18:36, Per Nordlöw wrote: The line dflags "-linker=gold" platform="linux-ldc" # use GNU gold linker in dub.sdl enables me to change linker for LDC. Is it possible to choose a specific linker for DMD aswell in a similar way? I only find the flag `-L` that sets flags but no

Re: App/lib config system

2020-07-09 Thread Jacob Carlborg via Digitalmars-d-learn
On Thursday, 9 July 2020 at 06:57:22 UTC, Kagamin wrote: If you suspect there's a contradiction in requirements, you need to specify them with better precision. What are the contradictions in the requirements? I don't see any. -- /Jacob Carlborg

App/lib config system

2020-07-08 Thread Jacob Carlborg via Digitalmars-d-learn
I'm looking for a way to configure applications and libraries. I'm imagining a way for libraries to hook into a single point to provide the configuration parameters the library provides. These parameters can then be changed in one location from the user of the libraries (usually an

Re: How can I make DMD stop on the first fatal error? (-Wfatal-errors)

2020-07-08 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 8 July 2020 at 00:54:40 UTC, Marcone wrote: How can I make DMD stop on the first fatal error like -Wfatal-errors on C++? With the `-verrors=1` flag. You can specify exactly how many errors the compiler should emit before halting the compilation. Specify `0` for unlimited. --

Re: Construct an used-defined hash table container type from an AA-literal expression

2020-07-08 Thread Jacob Carlborg via Digitalmars-d-learn
On Tuesday, 7 July 2020 at 12:41:23 UTC, Per Nordlöw wrote: What about construction and assignment from a static array of `Pair`'s? Wouldn't that be easier on the compiler? I you refer to it wouldn't be using templates, then yes, I guess so. -- /Jacob Carlborg

Re: Construct an used-defined hash table container type from an AA-literal expression

2020-07-06 Thread Jacob Carlborg via Digitalmars-d-learn
On Sunday, 5 July 2020 at 21:06:32 UTC, Per Nordlöw wrote: Is there a way to construct a custom written hash-table container (struct) from an AA-literal expression? I think your best bet is a tuple of pairs, because then you're not limited to compile time values, but it won't look pretty:

Re: Construct an used-defined hash table container type from an AA-literal expression

2020-07-06 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 6 July 2020 at 01:43:43 UTC, user1234 wrote: --- import std; struct AA { void opIndexAssign(int v, string k) @nogc {} } void main(string[] args) @nogc { AA myCustom; enum literal = ["one":1, "two":2].stringof[1..$-1]; enum pairs = literal.split(',').array;

Re: Construct an used-defined hash table container type from an AA-literal expression

2020-07-06 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 6 July 2020 at 01:43:43 UTC, user1234 wrote: Hereh we go ;) --- import std; struct AA { void opIndexAssign(int v, string k) @nogc {} } void main(string[] args) @nogc { AA myCustom; enum literal = ["one":1, "two":2].stringof[1..$-1]; enum pairs =

Re: Print only part of a stack trace

2020-07-01 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-07-01 19:44, Dennis wrote: On assertion failure, the default error handler prints a stack trace that looks like this [library functions] [application functions] [druntime start-up functions] I'm only interested in application functions, the rest is noise. I could easily filter

Re: Calling C functions

2020-06-30 Thread Jacob Carlborg via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 12:22:15 UTC, Steven Schveighoffer wrote: (i.e. one cannot use extern(D) functions for C callbacks). I don't think that's a big issue. Honestly, I don't think it's an issue at all. BTW, the order of arguments is not the only thing. Variadic functions in D and

Re: Calling C functions

2020-06-29 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 29 June 2020 at 16:34:33 UTC, Steven Schveighoffer wrote: Are you sure? On the ABI page [1] , it says "The extern (C) and extern (D) calling convention matches the C calling convention used by the supported C compiler on the host system." In that case the documentation is wrong.

Re: Calling C functions

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-26 18:54, Denis wrote: OK, now this makes sense. I tested calling the same callback function directly from D: it compiled and worked correctly. So at least prefixing the callback function with `extern(C)` doesn't prevent the rest of the D program from calling it too. No, of

Re: Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-26 15:16, Adam D. Ruppe wrote: Yeah, I've been wanting to change that and use the native apis for years but like I just haven't been able to figure out the documentation of them. That would be nice. That's the problem of everything Apple makes. Kinda drives me nuts trying to keep

Re: Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-26 14:43, User wrote: It is possible to statically link libcurl into your application. No need to use OpenSSL as libcurl can be built with SChannel. That sounds good. It looks like I remembered wrong. std.net.curl uses `dlopen` on libcurl, not OpenSSL. This might be less of an

Re: Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-26 14:41, Kagamin wrote: Maybe just start wget or something like that? The point was to avoid runtime dependencies. Since you want the latest certificate storage, you intend to support only the latest system. Many root certificates will timeout now. I didn't say the latest

Re: Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On Friday, 26 June 2020 at 11:10:27 UTC, ikod wrote: Hello, re `requests` - it uses dlopen (and variants for OSX and Windows, see https://github.com/ikod/dlang-requests/blob/master/source/requests/ssl_adapter.d#L50). The reason for dlopen is simple - compatibility with both openssl ver 1.0

Downloading files over TLS

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
Downloading files over TLS. This seems that it's something that should be quite simple to do. My high level goals are cross-platform and easy distribution. I don't need anything fancy just a simple API like this: download("https://url.com;, "/local/file"); Because of these goals, I have a

Re: Calling C functions

2020-06-26 Thread Jacob Carlborg via Digitalmars-d-learn
On Friday, 26 June 2020 at 00:30:22 UTC, Denis wrote: I have a two questions about calling C functions from D. (1) When passing a D callback to a C function, is there a way to write the code without having to prefix the callback declaration with "extern(C)"? It's not a big deal adding the

Re: How to correctly integrate D library to Swift/Obj-C mobile project?

2020-06-24 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 22 June 2020 at 14:32:21 UTC, Anton wrote: I have a static library (.a) compiled with LDC for iOS platform. But I can't figure out how to correctly connect it to the project and call its functions. I've already linked binary with library to the project but IDE still doesn't see its

Re: How to correctly integrate D library to Swift/Obj-C mobile project?

2020-06-24 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 22 June 2020 at 19:41:22 UTC, Vlad wrote: Is it even possible to compile D for iOS and use it the same way as compiled C++ static library? (We do need a D runtime) Yes, druntime/Phobos will need to be linked like any other static library. -- /Jacob Carlborg

Re: Some questions about strings

2020-06-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 22 June 2020 at 04:08:10 UTC, Denis wrote: The terminating null character was one of the reasons I thought strings were different from char arrays. Now I know better. String **literals** have a terminating null character, to help with integrating with C functions. But this null

Re: Dub Error Message "Invalid variable: DUB"

2020-06-07 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-06-07 11:24, Russel Winder wrote: Hi, Why on earth is Dub sending out this error message (Invalid variable: DUB) on GitLab but not on Travis-CI or locally? OK, that was slightly rhetorical, more reasonably, why is dub sending out this message at all? Dub is supposed to make an

Re: Objective C protocols

2020-05-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-17 11:32, John Colvin wrote: On Saturday, 16 May 2020 at 19:14:51 UTC, John Colvin wrote: What's the best way to implement an Objective C protocol in D? I see mention here https://dlang.org/changelog/2.085.0.html#4_deprecated_objc_interfaces but it's not clear where things are

Re: Get unknown symbol (struct, method, class) tagged with User Defined Attributes

2020-05-13 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-12 06:02, Steven Schveighoffer wrote: If you want a list of ALL symbols that have the UDA in the application, that would require some form of runtime reflection (like Java). D has very limited support for runtime reflection. In D, you would use some form of registration to tell the

Re: D and Async I/O

2020-05-12 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-12 11:23, Russel Winder wrote: As far as I can tell D has no futures… Future and async in vibe.d [1]. Future in Mecca [2]. [1] https://vibed.org/api/vibe.core.concurrency/async [2]

Re: Error running concurrent process and storing results in array

2020-05-11 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-07 02:17, data pulverizer wrote: What is the difference between -O2 and -O3 ldc2 compiler optimizations? `--help` says -O2 is "Good optimizations" and -O3 "Aggressive optimizations". Not very specific. -- /Jacob Carlborg

Re: D and Async I/O

2020-05-11 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-11 16:44, Russel Winder wrote: Crickey, a third option. This wil increase my dithering! ;-) Forth: Mecca [1] :) [1] https://github.com/weka-io/mecca -- /Jacob Carlborg

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 12:23, data pulverizer wrote: Yes, I'll do a blog or something on GitHub and link it. It would be nice if you could get it published on the Dlang blog [1]. One usually get paid for that. Contact Mike Parker. [1] https://blog.dlang.org -- /Jacob Carlborg

Re: Retrieve the return type of the current function

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-05 19:11, learner wrote: On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: Yes, kind of: void foo(string caller = __FUNCTION__)() { import

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 06:04, Mathias LANG wrote: In general, if you want to parallelize something, you should aim to have as many threads as you have cores. That should be _logical_ cores. If the CPU supports hyper threading it can run two threads per core. -- /Jacob Carlborg

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 08:54, drug wrote: Do you try `--fast-math` in ldc? Don't know if 05 use this flag Try the following flags as well: `-mcpu=native -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto` -- /Jacob Carlborg

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 05:25, data pulverizer wrote: I have been using std.parallelism and that has worked quite nicely but it is not fully utilising all the cpu resources in my computation If you happen to be using macOS, I know that when std.parallelism checks how many cores the computer has, it

Re: DConf 2017 Videos

2020-04-25 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-04-24 22:24, matheus wrote: Hi, please could someone tell me where can I find videos from DConf 2017? I pretty sure I watched them on Youtube sometime ago, but I can't find anymore. By the way, I'm looking from one video where someone shows some "C flaws" and how to D as Better C

Re: Array fill performance differences between for, foreach, slice

2020-04-01 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-03-31 23:30, data pulverizer wrote: $ dmd fill.d && ./fill You have not enabled optimizations. You should compile with `-O -release -inline` to enable all optimizations. Without optimizations I get numbers like these: Slice: Mean time(usecs): 92.91, Standard Deviation: 49.8002

Re: A question about C++ interop

2020-03-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-03-27 20:17, YD wrote: Hi, I have a C++ header file which looks like     class A {     public:     static A *create();     virtual int f() const = 0;     }; And there is a C++ library file which provides the implementation, so that if I write a C++ program and call    

Re: Best way to learn 2d games with D?

2020-03-16 Thread Jacob Carlborg via Digitalmars-d-learn
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer wrote: I want to try and learn how to write 2d games. I'd prefer to do it with D. I've found a ton of tutorials on learning 2d gaming with other languages. Is there a place to look that uses D for learning? Should I just start

Re: Typescript with vibe.d

2020-03-10 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 9 March 2020 at 09:42:16 UTC, GreatSam4sure wrote: I want to know if it is possible to use typescript with the vibe.d since typescript is a superset of javascript. I will appreciate any example if it is possible There's a Diet filter for TypeScript here [1], but it hasn't been

Re: dscanner and ref parameters

2020-02-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-02-23 13:28, mark wrote: Just realised that the arg is 'out' not 'ref'; don't know if that makes a difference to dscanner. Anyway, I've made a bug report: https://github.com/dlang-community/D-Scanner/issues/793 Same idea applies. dscanner should look at the signature. In the case of

Re: dscanner and ref parameters

2020-02-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-02-23 10:03, mark wrote: Then this would not only help dscanner, but also make it clear to programmers that the argument could be modified. It's not necessary for dscanner. It should look at the signature of `getKeyval` to see that it takes an argument by `ref`. -- /Jacob Carlborg

Re: Fastest linker on Mac OS X

2020-02-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-02-22 15:45, Per Nordlöw wrote: What's the fastest linker to use when building using dmd or ldc on Mac? There's only one linker that works properly, the official one, ld64. The LLVM LLD linker works in some cases but are missing some features. Some of the missing features are

Re: Porting D to custom OS

2020-02-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-02-22 20:30, IGotD- wrote: That's sound like a start. Is there some kind of automation behind this based on the target triple (-mtriple) or just some kind of hardcoded default versions identifiers somewhere in the source code? Have a look at [1] for a recent example. [1]

Re: CTFE, string mixins & code generation

2020-01-24 Thread Jacob Carlborg via Digitalmars-d-learn
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. Class objects kind of work. One can use static const/immutable instead. The following snippet compiles: class A { int a = 3; } const bar =

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 14:50:01 UTC, Per Nordlöw wrote: Will that incur an extra runtime cost compared to __cmp? I haven't looked at how `__cmp` is implemented but I would guess there's some extra overhead. Need to get type info and then there will be several virtual method calls

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 08:44:15 UTC, Per Nordlöw wrote: I just found import core.internal.array.comparison : __cmp; I presume that is a better alternative if Phobos' independence is desired. That looks like it's for internal use. There is a `compare` method in the `TypeInfo`

Re: Get memory used by current process at specific point in time

2020-01-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-01-15 19:45, Chris Katko wrote: Still, some internal instrumentation would be nice. But I'm not aware of any. There are some runtime flags that can be passed to the executable when running it to get some info about the GC. Of course these are not documented (except perhaps in the

Re: Get memory used by current process at specific point in time

2020-01-13 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-01-12 14:58, Per Nordlöw wrote: Is there a druntime/phobos function for getting the amount of memory (both, stack, malloc, and GC) being used by the current process? I don't think so. But if you're on macOS you can use Instruments (shipped with Xcode) and pick the Allocations

Re: Template mixin / unresolved external / scope problem?

2019-11-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-28 16:40, Robert M. Münch wrote: I have: a.d: extern (C) void myFuncA(); void myFuncB() { myFuncA(); } b.d: public import a; mixin template MYFUNCA() { extern (C) void myFuncA() {...} } c.d: import b; mixin MYFUNCA; ...further code... Compiling such a structure gives

Re: Leak-detection of references to scoped class instances

2019-11-25 Thread Jacob Carlborg via Digitalmars-d-learn
On Sunday, 24 November 2019 at 21:49:19 UTC, Per Nordlöw wrote: I guess we need a builtin language qualifier for scoped classes for that to work, right? We have that: scope a = new Object; — /Jacob Carlborg

Re: dmd memory usage

2019-11-24 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-18 01:20, Steven Schveighoffer wrote: I'm fighting some out of memory problems using DMD and some super-template heavy code. I have ideas on how to improve the situation, but it involves redesigning a large portion of the design. I want to do it incrementally, but I need to see

Re: equivalent of typeid(Class).name at compile-time

2019-11-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Thursday, 21 November 2019 at 20:44:19 UTC, Steven Schveighoffer wrote: I thought I could do typeid(Class).name to get the class name that will be returned at runtime if you did typeid(instance).name. But it's not accessible at compile-time. What compile-time string should I use for

Re: How to get child class Type and members from parent class?

2019-11-20 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 20 November 2019 at 10:05:11 UTC, zoujiaqing wrote: import std.stdio; class A { this(T)(T t) { } void write() { T _this = cast(T) this; writeln(this.v); } } class B : A { string v = "hello"; } void main() { auto b = new B;

Re: dmd memory usage

2019-11-18 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 18 November 2019 at 15:31:02 UTC, Steven Schveighoffer wrote: I don't think this will work for me, as this isn't CTFE, and I'm assuming the instantiated templates won't be collected because they stay referenced for the whole program. You could also combine that flag with the GC

Re: dmd memory usage

2019-11-18 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 18 November 2019 at 00:20:12 UTC, Steven Schveighoffer wrote: I'm fighting some out of memory problems using DMD and some super-template heavy code. Try to enable the GC using the `-lowmem` flag [1]. [1] https://dlang.org/changelog/2.086.0.html#lowmem — /Jacob Carlborg

Re: Translating Java into D

2019-11-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-14 20:50, NonNull wrote: Greetings, Java seems to be almost a subset of D in various ways. Has there been any work done to automatically translate Java source into D? Yes, I'm working on a tool, JPort [1], for automatically translating Java to D. It's not done yet and there's been

Re: Translating Java into D

2019-11-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-16 08:13, GreatSam4sure wrote: I am of the opinion that D is much more powerful than Java since I am familiar with the language to some extent. I am even to start a GUI app in java due to the fact I have no find a GUI toolkit in D that meet all my need. There's DWT [1], which is

Re: is the runtime implemented in betterC?

2019-11-09 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-08 16:25, dangbinghoo wrote: hmm, if runtime is implemented in regular D, how could the regular D code depends on regular D runtime be compiled when we doesn't have a D runtime even exists? thinking thant we just have xtensa-llvm, and building ldc for xtensa CPU,  the runtime will

Re: Which is the active fork in DFL gui library ?

2019-11-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-03 17:48, Vinod K Chandran wrote: @Jesse Phillips, Thank you for the reply.  Does DWT is built upon Java's SWT ? Yes. It's a full translation of the Java code to D. No JNI, JVM or Java or remains. I heard that SWT is somewhat slower in windows. I don't know if that's the

Re: Running unittests of a module with -betterC

2019-10-30 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-30 16:09, jmh530 wrote: I feel like this should be added into the compiler so that it just works. This will only run the unit tests in the current modules. The standard way of running the unit tests will run the unit tests in all modules. -- /Jacob Carlborg

Re: Read Once then reset/init value?

2019-10-30 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-30 00:28, Simen Kjærås wrote: Something like this? T readOnce(T)(ref T value) {     auto tmp = value;     value = T.init;     return tmp; } unittest {     int i = 3;     assert(i.readOnce == 3);     assert(i == 0); } Perhaps better to encapsulate it in a struct to avoid

Re: PHP to D Conversion

2019-10-18 Thread Jacob Carlborg via Digitalmars-d-learn
On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote: Hi All, Request your help in converting a PHP code to D equivalent code PHP Code: class avmtest { private $con; function __construct() { global $config; $this->con = new

Re: Uninstalling DMG file

2019-10-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-16 05:30, Joel wrote: Everything seems to be working again - yay! Great. If you see a lot of warnings when linking, I have a PR for that [1]. [1] https://github.com/dlang/dmd/pull/10476 -- /Jacob Carlborg

Re: A proper WAT moment

2019-10-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-15 09:06, John Colvin wrote: And all the other ones in my example that access members without an instance that also compile? There's something pretty strange about the rules here. The thing is that it should be possible to access a non-static member without an instance because

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-14 09:29, Robert M. Münch wrote: => nm /usr/lib/system/libdyld.dylib | grep _dyld_enumerate_tlv_storage 00017eca T _dyld_enumerate_tlv_storage Strange, the output shows that the symbol is present. -- /Jacob Carlborg

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-14 07:36, Joel wrote: I use Home Brew (brew upgrade dmd, and brew upgrade dub) Brew is only up to 2.087.1 at the moment - John Colvin seems to be the man that mantains dmd with brew. You can use DVM [1] to install the latest version of DMD. [1]

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-11 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-11 18:48, Robert M. Münch wrote: On 2019-10-10 18:31:25 +, Daniel Kozak said: What dmd version? I think I had an older one like 2.085 or so. I updated to 2.088 and it now seems to work. https://issues.dlang.org/show_bug.cgi?id=20019 I'm on OSX 10.14.6, so this might not

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-11 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-10 20:12, Robert M. Münch wrote: I have two project I want to compile and both times get this error: Undefined symbols for architecture x86_64:  "_dyld_enumerate_tlv_storage", referenced from: __d_dyld_getTLSRange in libphobos2.a(osx_tls.o) I'm wondering where this comes from

Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-27 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 25 September 2019 at 11:46:04 UTC, Ron Tarrant wrote: Hi y'all, I've been Googling how to do this, but coming up with nothing definitive. Are there any articles for how to do this for: Windows? Linux? other UNIX-alike OSs? For macOS you should distribute a GUI application for

Re: Deprecation message sources

2019-09-18 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-17 22:55, Johan Engelen wrote: Wow. How come this is not caught by the CI testing? That issue seems to be because "writeln" is printing "type", which is an enum. For enums, "writeln" prints the actual name of the enum member and not the value. It seems it extracts the names of

Re: C++ vs D: Default param values and struct to array casting

2019-09-07 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-06 11:14, Andrew Edwards wrote: C++ allows the for following: struct Demo { float a, b, c, d; Demo() { a = b = c = d = 0.0f; } Demo(float _a, float _b, float _c, float _d) {     a = _a;     b = _b;     c = _c;     d = _d; } float 

Re: Why are extern(C/C++) definitions and references mangled differently in separately compiled modules?

2019-09-07 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-06 21:03, Max Samukha wrote: Is there any practical use of having identically named .d and .di alongside? Same as in C/C++. This allows you to have a header file if you want to distribute a closed source library. -- /Jacob Carlborg

Re: Linking to -framework on MacOS

2019-09-05 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-04 17:12, Andrew Edwards wrote: Worked like a charm:  -L/System/Library/Frameworks/Cocoa.framework/Cocoa This probably not a good idea. It relies on how a framework is structured internally. Adam's solution is the correct one. -- /Jacob Carlborg

Re: Linking D Runtime

2019-09-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-03 03:45, Jonathan Levi wrote: It looks like what needs to be found are "libphobos2" and "libdruntime".  They can be found where ever your system puts lib files.  Windows (as far as I know) does not have a joined place for lib files so you need to look where dmd/ldc/etc installed

Re: Linking D Runtime

2019-09-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-03 10:43, Jacob Carlborg wrote: This depends on how the compiler is installed. There are several installers that do not put the libraries in `/usr/lib`. BTW, that directory doesn't exist by default anymore on macOS, even if Xcode and the command line tools are installed. My bad.

Re: Java to D

2019-08-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-08-28 10:14, GreatSam4sure wrote: Good day everyone. DWT is a library for creating cross-platform GUI applications. It's a port of the SWT Java library from Eclipse. Currently supported platforms are Windows, using Win32 and Linux, using GTK. What are the tools and step involved in

Re: What the abstrac final class mean?

2019-08-13 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-08-12 11:25, a11e99z wrote: its weird that next compiles in some weird form import std; static class A {     static a() { "a".writeln; } // forgot return type } Since you have specified an attribute on "a", the compiler can infer the return type. In this case it's inferred to

Re: How to get name of my application (project)

2019-08-05 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-08-03 17:58, Jonathan M Davis wrote: Also, the first element in the array passed to main is the name of the executable. No, what's passed to "main" is the path to however the application was invoked, not the executable. If you invoke it as "./foo" it will pass "./foo" to the "main"

  1   2   3   4   5   6   7   >