Re: Why doesn't this work when the function is a static method?

2021-01-13 Thread Jack via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 17:21:23 UTC, Paul Backus wrote: On Wednesday, 13 January 2021 at 17:14:04 UTC, Jack wrote: but if I wrap this within a class: class Foo { static int f(HWND hwnd, int n) { return n*10; } static void baa() { HWND foo;

Why doesn't this work when the function is a static method?

2021-01-13 Thread Jack via Digitalmars-d-learn
works fine (this is defined at global scope, g and baa are same as static) int f(HWND hwnd, int n) { return n*10; } void baa() { HWND foo; writeln(foo.f(10)); } but if I wrap this within a class: class Foo { static int f(HWND hwnd, int n)

How to get call stack for InvalidMemoryOperationError while doing unittest?

2021-01-13 Thread apz28 via Digitalmars-d-learn
core.exception.InvalidMemoryOperationError@src\core\exception.d(647): Invalid memory operation reference D runtime unittest executor codes try { fp(); ++results.passed; } catch ( Throwable e ) { import core.stdc.stdio;

Re: Collections in D

2021-01-13 Thread mw via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 12:06:05 UTC, Roguish wrote: which seems perfectly adequate. What about sets? You can also search https://code.dlang.org I use: https://code.dlang.org/packages/emsi_containers Which has hashset:

Re: Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread sighoya via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 16:17:02 UTC, Marcone wrote: import std; void a(int b){ } void main() { Variant c = 10; a(c); // Error } Need more sugar. Two problems: 1.) Variant is library defined, compared to the language level there isn't a default strategy to choose int32 here,

Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread Marcone via Digitalmars-d-learn
import std; void a(int b){ } void main() { Variant c = 10; a(c); // Error } Need more sugar.

Re: Why doesn't this work when the function is a static method?

2021-01-13 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 17:14:04 UTC, Jack wrote: but if I wrap this within a class: class Foo { static int f(HWND hwnd, int n) { return n*10; } static void baa() { HWND foo; writeln(foo.f(10)); } } I get the error: Error: no property

Re: Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread Ali Çehreli via Digitalmars-d-learn
On 1/13/21 8:17 AM, Marcone wrote: > import std; > > void a(int b){ > } > > void main() > { >Variant c = 10; >a(c); // Error > } > > Need more sugar. That can't work in a strongly statically typed language. The call a(c) is decided at compile time but Variant is not an int at compile

Why many programmers don't like GC?

2021-01-13 Thread Marcone via Digitalmars-d-learn
I've always heard programmers complain about Garbage Collector GC. But I never understood why they complain. What's bad about GC?

Re: Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 18:09:08 UTC, sighoya wrote: A more natural conclusion would be to infer c to the most common supertype as other inferences would unnecessarily exclude future assignments to c. But the most common supertype doesn't seem to exist, and I'm unsure if this type

Re: Developing and running D GUI app on Android

2021-01-13 Thread aberba via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 02:02:16 UTC, H. S. Teoh wrote: On Sun, Jan 10, 2021 at 06:58:13PM +, aberba via Digitalmars-d-learn wrote: [...] First, you need a way to build an APK, and then transfer that to your Android device for testing. Building an APK *can* be done manually

Re: Why many programmers don't like GC?

2021-01-13 Thread Imperatorn via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 18:58:56 UTC, Marcone wrote: I've always heard programmers complain about Garbage Collector GC. But I never understood why they complain. What's bad about GC? I would guess because of performance issues.

Re: Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread sighoya via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 19:38:55 UTC, Paul Backus wrote: That's what Variant is--a struct that models the universal supertype (sometimes called "Top" or "Any"). Ahh right. Good point, so it already fits.

Re: Developing and running D GUI app on Android

2021-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 13, 2021 at 07:51:08PM +, aberba via Digitalmars-d-learn wrote: [...] > So Adam's tool setup is pretty clear (talked to him). What remains is > calling Java classes and interacting with the Android's API. I know a > little bit of Java but not enough Android. Just the calling >

Re: Why many programmers don't like GC?

2021-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 13, 2021 at 06:58:56PM +, Marcone via Digitalmars-d-learn wrote: > I've always heard programmers complain about Garbage Collector GC. But > I never understood why they complain. What's bad about GC? It's not merely a technical issue, but also a historical and sociological one.

Re: Why many programmers don't like GC?

2021-01-13 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 18:58:56 UTC, Marcone wrote: I've always heard programmers complain about Garbage Collector GC. But I never understood why they complain. What's bad about GC? SHORT VERSION: While garbage collection is great for many applications, GC also has some significant

Re: Developing and running D GUI app on Android

2021-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 20:23:22 UTC, H. S. Teoh wrote: Adam may be written a script for this, I'm not 100% sure. Yeah, my code does it all, though the auto-generation is more about accessing Java from D than vice versa, since implementing the D parts are simple. See the

Re: writeln and write at CTFE

2021-01-13 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 11:50:26 UTC, Andrey wrote: Today is 2021. Dlang still doesn't have ctfe write functions? You make it sound like D is behind the times. Is CTFE I/O a standard feature in other languages? How many other languages even have a CTFE feature comparable to D's?

Re: Why many programmers don't like GC?

2021-01-13 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 18:58:56 UTC, Marcone wrote: I've always heard programmers complain about Garbage Collector GC. But I never understood why they complain. What's bad about GC? tsbockman gave a good answer. In short: - You need to design the language for GC for it to be a

Re: Why many programmers don't like GC?

2021-01-13 Thread mw via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 18:58:56 UTC, Marcone wrote: I've always heard programmers complain about Garbage Collector GC. But I never understood why they complain. What's bad about GC? I want to stress: in D you can *MIX* GC with manual memory management, which gives you the best of

Re: Why many programmers don't like GC?

2021-01-13 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 21:56:58 UTC, mw wrote: I think this flexibility to mix GC & manual memory management is very unique in D. Actually I'm not sure if it can be done in other languages at all. Yes, this is one of the great things about D. There are miscellaneous problems with

Re: How to define delegate with needed parameters

2021-01-13 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 14 January 2021 at 00:19:24 UTC, Tim wrote: I would like to be able to create a delegate but also supply the function parameters to be used for the function call. How can I go about doing this? Example: void foo(int i){ } void bar(string m){ } doSomething((q));

Re: Why many programmers don't like GC?

2021-01-13 Thread mw via Digitalmars-d-learn
On Thursday, 14 January 2021 at 00:15:12 UTC, Ola Fosheim Grøstad wrote: On Wednesday, 13 January 2021 at 21:56:58 UTC, mw wrote: I think this flexibility to mix GC & manual memory management is very unique in D. Actually I'm not sure if it can be done in other languages at all. It sure can.

Re: writeln and write at CTFE

2021-01-13 Thread oddp via Digitalmars-d-learn
On 13.01.21 21:47, tsbockman via Digitalmars-d-learn wrote: Is CTFE I/O a standard feature in other languages? How many other languages even have a CTFE feature comparable to D's? Just two langs I use from time to time: 1) nim via forced ctfe; way faster than d by running through a vm: const

How to define delegate with needed parameters

2021-01-13 Thread Tim via Digitalmars-d-learn
I would like to be able to create a delegate but also supply the function parameters to be used for the function call. How can I go about doing this? Example: void foo(int i){ } void bar(string m){ } doSomething((q)); doSomething(("test");

Re: Why many programmers don't like GC?

2021-01-13 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 21:56:58 UTC, mw wrote: I think this flexibility to mix GC & manual memory management is very unique in D. Actually I'm not sure if it can be done in other languages at all. It sure can. Most AOT languages that provide GC also provide C-interfaces and manual

writeln and write at CTFE

2021-01-13 Thread Andrey via Digitalmars-d-learn
Hello all, Tell me please how can I "writeln" and "write" in function that is used in CTFE? At the moment I get this: import\std\stdio.d(4952,5): Error: variable impl cannot be modified at compile time Or may be exist some other ways to do it?

Re: Anything in D to avoid check for null everywhere?

2021-01-13 Thread ddcovery via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 21:37:11 UTC, Jack wrote: I was looking for a way to avoid null checks everywhere. I was checking the Null object pattern, or use something like enforce pattern, or even if I could make a new operator and implement something like C#'s .? operator, that Java was

Re: writeln and write at CTFE

2021-01-13 Thread Guillaume Piolat via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 08:35:09 UTC, Andrey wrote: Hello all, Tell me please how can I "writeln" and "write" in function that is used in CTFE? At the moment I get this: import\std\stdio.d(4952,5): Error: variable impl cannot be modified at compile time Or may be exist some other

Re: Member variables in method are null when called as delegate from thread

2021-01-13 Thread Arafel via Digitalmars-d-learn
On 13/1/21 3:15, Tim wrote: Fantastic response, thank you! I did some more digging and properly narrowed down where the issue is and created a test script that demonstrates the problem. Let me know what you think and if it could still be a similar problem to what you have stated above. I'll

Re: writeln and write at CTFE

2021-01-13 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 23:38:54 UTC, oddp wrote: Just two langs I use from time to time: 1) nim via forced ctfe; way faster than d by running through a vm: const foo = fib(42) static: echo "foobar" 2) crystal via macros: {{ puts "foobar" }} Another one would be zig via

Re: How to define delegate with needed parameters

2021-01-13 Thread Tim via Digitalmars-d-learn
On Thursday, 14 January 2021 at 00:29:23 UTC, Paul Backus wrote: Easiest way is to use a lambda: doSomething(() => foo(q)) This worked perfectly, thank you for your timely response~

Re: writeln and write at CTFE

2021-01-13 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 09:11:53 UTC, Guillaume Piolat wrote: On Wednesday, 13 January 2021 at 08:35:09 UTC, Andrey wrote: Hello all, Tell me please how can I "writeln" and "write" in function that is used in CTFE? At the moment I get this: import\std\stdio.d(4952,5): Error: variable

Re: Anything in D to avoid check for null everywhere?

2021-01-13 Thread ddcovery via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 09:02:37 UTC, ddcovery wrote: Find more details here: https://run.dlang.io/gist/392c06e745d1a35df71084ce4d29fed7 Ups... it seems that the link is not working (it is the first time I try to generate a dalng/gist link... I'm not sure if this can really be

Re: Anything in D to avoid check for null everywhere?

2021-01-13 Thread ddcovery via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 21:37:11 UTC, Jack wrote: I was looking for a way to avoid null checks everywhere. I was checking the Null object pattern, or use something like enforce pattern, or even if I could make a new operator and implement something like C#'s .? operator, that Java was

Re: Collections in D

2021-01-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 11:58:11 UTC, Roguish wrote: I can't find anything about collections in D. All I have found are arrays and maps ("associative arrays"). What about lists and sets? What if I just want a linked list? You can refer to the docs for them:

Re: Collections in D

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 11:58:11 UTC, Roguish wrote: I can't find anything about collections in D. All I have found are arrays and maps ("associative arrays"). What about lists and sets? What if I just want a linked list? It seems collections are called "containers" in D's standard

Collections in D

2021-01-13 Thread Roguish via Digitalmars-d-learn
I can't find anything about collections in D. All I have found are arrays and maps ("associative arrays"). What about lists and sets? What if I just want a linked list?

Re: writeln and write at CTFE

2021-01-13 Thread Andrey via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 11:31:16 UTC, Bastiaan Veelo wrote: On Wednesday, 13 January 2021 at 09:11:53 UTC, Guillaume Piolat wrote: On Wednesday, 13 January 2021 at 08:35:09 UTC, Andrey wrote: Hello all, Tell me please how can I "writeln" and "write" in function that is used in CTFE?

Re: Collections in D

2021-01-13 Thread evilrat via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 12:06:05 UTC, Roguish wrote: What about sets? There is no specific set container, they just implemented as generic algorithms over the ranges. There is a section for set operations (std.algorithm.setops module). https://dlang.org/phobos/std_algorithm.html

Re: Collections in D

2021-01-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 12:06:05 UTC, Roguish wrote: On Wednesday, 13 January 2021 at 11:58:11 UTC, Roguish wrote: I can't find anything about collections in D. All I have found are arrays and maps ("associative arrays"). What about lists and sets? What if I just want a linked list?

Is there a way to work with processes in Windows without extern(c)?

2021-01-13 Thread dog2002 via Digitalmars-d-learn
I need to get a list of processes in Windows (and their pid). I could use extern(c) and Process Walking (Process32First, Process32Next), but maybe there is a way to get the list by means of D?

Re: How to debug D on Linux

2021-01-13 Thread drug via Digitalmars-d-learn
On 1/13/21 4:47 PM, Roguish wrote: Also, what does it mean to "always emit a stackframe" (compiler option -gs) ? Short answer - sometimes the compiler does not emit a stackframe (due to optimization for example). In general if you are able to debug your binary by gdb then you don't need to

Re: How to debug D on Linux

2021-01-13 Thread evilrat via Digitalmars-d-learn
if you are looking for back trace someone recently posted a hint for linux where there is no back trace by default is to import core.sys.linux.backtrace or something that has back trace info and using it in exception handler for runtime to print the stack trace.

Re: How to debug D on Linux

2021-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 13:47:55 UTC, Roguish wrote: One specific question I have is: what's the difference between -g and -debug and -d-debug? -debug enables the `debug` keyword inside the D code itself. This lets you bypass other rules temporarily. For example void foo() pure {

Re: How to debug D on Linux

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 14:13:07 UTC, drug wrote: Short answer - sometimes the compiler does not emit a stackframe (due to optimization for example). OK, so -gs prevents a certain optimization that would make debugging harder in certain situations. Thanks for clearing that up.

Re: How to debug D on Linux

2021-01-13 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Jan 13, 2021 at 4:10 PM Roguish via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Wednesday, 13 January 2021 at 14:17:51 UTC, Rikki Cattermole > wrote: > > > > Same thing. > > Clear, thanks. > > I'm just discovering today that DMD and LDC are two different >

Re: Is there a way to work with processes in Windows without extern(c)?

2021-01-13 Thread dog2002 via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 15:11:40 UTC, Dennis wrote: On Wednesday, 13 January 2021 at 14:04:52 UTC, dog2002 wrote: [...] I don't think this is part of the standard library. Here's a piece of code I wrote a while ago if that's useful: [...] Thank you so much!

Re: How to debug D on Linux

2021-01-13 Thread drug via Digitalmars-d-learn
On 1/13/21 4:47 PM, Roguish wrote: On Wednesday, 13 January 2021 at 13:30:48 UTC, Roguish wrote: Anything else I need to know when debugging on Linux, without an IDE? One specific question I have is: what's the difference between -g and -debug and -d-debug? Also, what does it mean to

Re: How to debug D on Linux

2021-01-13 Thread Rikki Cattermole via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 13:47:55 UTC, Roguish wrote: On Wednesday, 13 January 2021 at 13:30:48 UTC, Roguish wrote: Anything else I need to know when debugging on Linux, without an IDE? One specific question I have is: what's the difference between -g and -debug and -d-debug? From

Re: writeln and write at CTFE

2021-01-13 Thread z via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 11:50:26 UTC, Andrey wrote: Function "ctfeWriteln" doens't exist. pragma(msg, ...) is used only for CT values. Today is 2021. Dlang still doesn't have ctfe write functions? Yes.(afaik) It has shot me on the foot once, to the point i abandoned the idea of

Re: How to debug D on Linux

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 14:13:17 UTC, evilrat wrote: if you are looking for back trace someone recently posted a hint for linux where there is no back trace by default is to import core.sys.linux.backtrace or something that has back trace info and using it in exception handler for

Re: How to debug D on Linux

2021-01-13 Thread user1234 via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 13:47:55 UTC, Roguish wrote: On Wednesday, 13 January 2021 at 13:30:48 UTC, Roguish wrote: Anything else I need to know when debugging on Linux, without an IDE? One specific question I have is: what's the difference between -g and -debug and -d-debug? Also,

Re: How to debug D on Linux

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 14:13:11 UTC, Adam D. Ruppe wrote: -debug enables the `debug` keyword inside the D code itself. This lets you bypass other rules temporarily. For example ... It does NOT do anything related to running D in debuggers like gdb, it just enables code guarded by

Re: How to debug D on Linux

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 14:17:51 UTC, Rikki Cattermole wrote: Same thing. Clear, thanks. I'm just discovering today that DMD and LDC are two different compilers. I got a different impression from the following webpage, which claims that ldmd2 is a wrapper invoking ldc2.

Re: Collections in D

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 12:39:50 UTC, evilrat wrote: There is no specific set container, they just implemented as generic algorithms over the ranges. I see. Thanks for pointing that out.

How to debug D on Linux

2021-01-13 Thread Roguish via Digitalmars-d-learn
How to debug D? My little trial app gives a segmentation fault. Probably a null pointer somewhere, which I could find simply by reading my code. But I'm puzzled that the program outputs very little helpful info when it crashes, even though I've compiled with all the debug options I could find

Re: Collections in D

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 12:48:47 UTC, Ferhat Kurtulmuş wrote: I read many posts that rbtree can be a replacement for sets in dlang. see its behaviour is identical. Thanks, will read up.

Re: How to debug D on Linux

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 13:22:01 UTC, Roguish wrote: How to debug D? be possible to get at least a stack trace? I've discovered that GDB works with the binary generated by the D compiler, so that's great. Anything else I need to know when debugging on Linux, without an IDE?

Re: How to debug D on Linux

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 13:30:48 UTC, Roguish wrote: Anything else I need to know when debugging on Linux, without an IDE? One specific question I have is: what's the difference between -g and -debug and -d-debug? Also, what does it mean to "always emit a stackframe" (compiler

Re: Is there a way to work with processes in Windows without extern(c)?

2021-01-13 Thread Dennis via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 14:04:52 UTC, dog2002 wrote: I could use extern(c) and Process Walking (Process32First, Process32Next), but maybe there is a way to get the list by means of D? I don't think this is part of the standard library. Here's a piece of code I wrote a while ago if

Re: How to debug D on Linux

2021-01-13 Thread Roguish via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 14:27:48 UTC, user1234 wrote: You really mostly only requires -g. Then you have to learn gdb. A few basis to get started I've used GDB before, but I've forgotten nearly all of it. Your recap of the basics is appreciated. :-)