Re: How to use Vector Extensions in an opBinary

2022-04-21 Thread HuskyNator via Digitalmars-d-learn
On Sunday, 17 April 2022 at 17:04:57 UTC, Bastiaan Veelo wrote: On Sunday, 17 April 2022 at 11:16:25 UTC, HuskyNator wrote: I recently found out there is [support for vector extensions](https://dlang.org/spec/simd.html) But I have found I don't really understand how to use it, not even

Re: Cannot always deduce template arguments when using implicitly cast array literals

2022-04-21 Thread HuskyNator via Digitalmars-d-learn
On Friday, 23 July 2021 at 13:53:27 UTC, Rekel wrote: As one can see, implicitly casting array literals in templates works fine in the case of bar, as does explicit use of templates in the case of foo, but for some reason foo does not manage to deduce its arguments like bar does.

Re: dub import local D package

2022-04-21 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 21 April 2022 at 03:59:26 UTC, Steven Schveighoffer wrote: OK, so reviewing with that in mind, it looks like you're trying to import `myPackage.modules.mymodule`, but the file `../myPackageName/source/myPackageName/modules/mymodule.d` doesn't exist. Is there one too many

Understanding alias template parameters

2022-04-21 Thread JG via Digitalmars-d-learn
Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); } void popFront() { r.popFront; } auto save() { return

Re: Understanding alias template parameters

2022-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 21, 2022 at 09:02:47PM +, JG via Digitalmars-d-learn wrote: > Hi, > > Could someone possibly help me to understand why the commented line > doesn't compile? > > > ```d > import std; > > struct MapResult(R,F) > { > R r; > const F f; > auto empty() { return r.empty; }

What is the difference between a static assert and a unit test?

2022-04-21 Thread Alain De Vos via Digitalmars-d-learn
I don't know when to use a static assert and when to use a unit test ?

Re: How to use Vector Extensions in an opBinary

2022-04-21 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 21 April 2022 at 15:31:04 UTC, HuskyNator wrote: On Sunday, 17 April 2022 at 17:04:57 UTC, Bastiaan Veelo wrote: You might want to have a look at https://code.dlang.org/packages/intel-intrinsics — Bastiaan. This does not discuss core.simd or __vector type, or did I

Re: Understanding alias template parameters

2022-04-21 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 21 April 2022 at 21:02:47 UTC, JG wrote: Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); }

Re: Understanding alias template parameters

2022-04-21 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 21 April 2022 at 21:38:14 UTC, Ali Çehreli wrote: ```d auto myMap(alias f, R)(R r) { pragma(msg, typeof(f)); return MapResult!(R, f)(r); } ``` It looks delicious when the convenience function works magic with Voldemort: ```d import std.range, std.stdio; auto myMap(alias

Re: How to use Vector Extensions in an opBinary

2022-04-21 Thread Guillaume Piolat via Digitalmars-d-learn
On Sunday, 17 April 2022 at 11:16:25 UTC, HuskyNator wrote: As a small disclaimer; I don't know to what extent the compiler already automates these kind of operations, and mostly want to use this as a learning experience. For your particular case, it is very likely LDC and GDC will be able

Re: Understanding alias template parameters

2022-04-21 Thread Ali Çehreli via Digitalmars-d-learn
On 4/21/22 14:02, JG wrote: > Could someone possibly help me to understand why the commented line > doesn't compile? iota(10).myMap!(x=>2*x).writeln; It is because x=>2*x is just a template. I don't know why the compiler chooses 'void' for typeof(f) but apparently that's how it represents

Re: What is the difference between a static assert and a unit test?

2022-04-21 Thread frame via Digitalmars-d-learn
On Thursday, 21 April 2022 at 22:26:57 UTC, Alain De Vos wrote: I don't know when to use a static assert and when to use a unit test ? There is `assert()`, `static assert()` and `unittest`. `static assert()` is used while compiling, to find errors or circumstances that can lead to errors in

Re: What is the difference between a static assert and a unit test?

2022-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/21/22 6:26 PM, Alain De Vos wrote: I don't know when to use a static assert and when to use a unit test ? An assert in general is something that must be true for the program to be valid. A normal assert is some runtime condition that must be true or the program will be terminated. A

Re: Infinite fibonacci sequence, lazy take first 42 values

2022-04-21 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 21 April 2022 at 04:36:13 UTC, Salih Dincer wrote: My favorite is the struct range. Because it is more understandable and personalized. Moreover, you can limit it without using ```take()```. And it's inherently lazy, so no extra processing/calculation other than what's

Re: How to get an IP address from network interfaces

2022-04-21 Thread dangbinghoo via Digitalmars-d-learn
On Thursday, 21 April 2022 at 07:38:04 UTC, Alexander Zhirov wrote: On Thursday, 21 April 2022 at 07:20:30 UTC, dangbinghoo wrote: On Thursday, 21 April 2022 at 07:04:18 UTC, Alexander Zhirov wrote: I want to get the IP address of the network interface. There is both a wireless interface and a

Re: How to get an IP address from network interfaces

2022-04-21 Thread dangbinghoo via Digitalmars-d-learn
On Friday, 22 April 2022 at 05:28:52 UTC, dangbinghoo wrote: On Thursday, 21 April 2022 at 07:38:04 UTC, Alexander Zhirov wrote: [...] ```d struct ifreq { private union ifr_ifrn_ { char[IFNAMSIZ] ifrn_name; /* if name, e.g. "en0" */ }

Re: How to get an IP address from network interfaces

2022-04-21 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 21 April 2022 at 07:20:30 UTC, dangbinghoo wrote: On Thursday, 21 April 2022 at 07:04:18 UTC, Alexander Zhirov wrote: I want to get the IP address of the network interface. There is both a wireless interface and a wired one. Is it possible, knowing the name of the network

Re: stack frame & dangling pointer weirdness

2022-04-21 Thread max haughton via Digitalmars-d-learn
On Thursday, 21 April 2022 at 05:49:12 UTC, Alain De Vos wrote: Following program: ``` import std.stdio; void main() @trusted { int *p=null; void myfun(){ int x=2; p= writeln(p); writeln(x); } myfun(); *p=16; writeln(p); writeln(*p); } ``` outputs :

How to get an IP address from network interfaces

2022-04-21 Thread Alexander Zhirov via Digitalmars-d-learn
I want to get the IP address of the network interface. There is both a wireless interface and a wired one. Is it possible, knowing the name of the network interface, to get its IP address?

Re: How to get an IP address from network interfaces

2022-04-21 Thread dangbinghoo via Digitalmars-d-learn
On Thursday, 21 April 2022 at 07:04:18 UTC, Alexander Zhirov wrote: I want to get the IP address of the network interface. There is both a wireless interface and a wired one. Is it possible, knowing the name of the network interface, to get its IP address? ```d import

Re: stack frame & dangling pointer weirdness

2022-04-21 Thread ag0aep6g via Digitalmars-d-learn
On 21.04.22 07:49, Alain De Vos wrote: int *p=null; void myfun(){ int x=2; p= writeln(p); writeln(x); } myfun(); *p=16; writeln(p); writeln(*p); `p` is no longer valid after `myfun` returns. Dereferencing it is an error. The two `writeln` calls in `main` re-use the memory

Re: How to get an IP address from network interfaces

2022-04-21 Thread dangbinghoo via Digitalmars-d-learn
On Thursday, 21 April 2022 at 07:20:30 UTC, dangbinghoo wrote: On Thursday, 21 April 2022 at 07:04:18 UTC, Alexander Zhirov wrote: I want to get the IP address of the network interface. There is both a wireless interface and a wired one. Is it possible, knowing the name of the network

Re: stack frame & dangling pointer weirdness

2022-04-21 Thread bauss via Digitalmars-d-learn
On Thursday, 21 April 2022 at 05:49:12 UTC, Alain De Vos wrote: Following program: ``` import std.stdio; void main() @trusted { int *p=null; void myfun(){ int x=2; p= writeln(p); writeln(x); } myfun(); *p=16; writeln(p); writeln(*p); } ``` outputs :

Re: Infinite fibonacci sequence, lazy take first 42 values

2022-04-21 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 21 April 2022 at 05:00:53 UTC, Alain De Vos wrote: This example limits the maximum value returned by the fibonacci function. f(n) < limit But it does not allow to return the n-th element of a fibonacci function. You are free to use ```take():``` ```d struct FibonacciRange(long

Re: stack frame & dangling pointer weirdness

2022-04-21 Thread Alain De Vos via Digitalmars-d-learn
On Thursday, 21 April 2022 at 06:57:41 UTC, drug wrote: On 21.04.2022 08:49, Alain De Vos wrote: Following program: ``` import std.stdio; void main() @trusted { int *p=null; void myfun(){ int x=2; p= writeln(p); writeln(x); } myfun(); *p=16; writeln(p); writeln(*p); } ```

Re: stack frame & dangling pointer weirdness

2022-04-21 Thread ag0aep6g via Digitalmars-d-learn
On 21.04.22 13:25, Alain De Vos wrote: How can i force an error to be thrown when doing something "bad" ? Use @safe.

unexpected noreturn behavior

2022-04-21 Thread WebFreak001 via Digitalmars-d-learn
What would you expect for this code? ```d struct Something(Types...) {} enum isSomethingExact(T) = is(T == Something!Types, Types...); enum isSomething(T) = is(T : Something!Types, Types...); pragma(msg, isSomethingExact!noreturn); pragma(msg, isSomething!noreturn); ``` This currently outputs

Re: unexpected noreturn behavior

2022-04-21 Thread rikki cattermole via Digitalmars-d-learn
noreturn is the bottom type which can implicitly convert to any type, including void. A value of type noreturn will never be produced and the compiler can optimize such code accordingly. https://dlang.org/spec/type.html#noreturn

Re: unexpected noreturn behavior

2022-04-21 Thread WebFreak001 via Digitalmars-d-learn
On Thursday, 21 April 2022 at 12:28:37 UTC, rikki cattermole wrote: noreturn is the bottom type which can implicitly convert to any type, including void. A value of type noreturn will never be produced and the compiler can optimize such code accordingly.

Re: unexpected noreturn behavior

2022-04-21 Thread rikki cattermole via Digitalmars-d-learn
Could we add a check for this in DScanner? Otherwise I'm not sure how else we are going to find all of these instances and fix them.

Re: unexpected noreturn behavior

2022-04-21 Thread Dennis via Digitalmars-d-learn
On Thursday, 21 April 2022 at 12:41:08 UTC, WebFreak001 wrote: which I think is a little bug-prone, but at least that would solve my issues. What issue do you have with it returning `true`? Note that this compiles: ```D @safe: import std.sumtype; void main() { SumType!(int, string) s =

Re: unexpected noreturn behavior

2022-04-21 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 21 April 2022 at 12:54:12 UTC, Dennis wrote: On Thursday, 21 April 2022 at 12:41:08 UTC, WebFreak001 wrote: which I think is a little bug-prone, but at least that would solve my issues. What issue do you have with it returning `true`? Presumably the problem is that if you write

Re: stack frame & dangling pointer weirdness

2022-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 21, 2022 at 11:25:29AM +, Alain De Vos via Digitalmars-d-learn wrote: > On Thursday, 21 April 2022 at 06:57:41 UTC, drug wrote: > > On 21.04.2022 08:49, Alain De Vos wrote: > > > Following program: > > > ``` > > > import std.stdio; > > > > > > void main() @trusted > > > { [...] >

Re: Infinite fibonacci sequence, lazy take first 42 values

2022-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 21, 2022 at 02:11:03AM +, Alain De Vos via Digitalmars-d-learn wrote: > Following java program creates an infinite fibonacci sequence (stream) > an takes the first 42 values of it. [...] > How would this program look converted to dlang ? > Maybe there are multiple solutions ?