Create an associative array with function pointers as the value

2022-04-20 Thread rempas via Digitalmars-d-learn
I'm trying to create an associative array where the keys will be a "string" type and the values will be function pointers. I'm using a custom type is called "file_struct" and for anyone that wants to try specifically with this type, the definition is the following: ```d struct file_struct {

Re: Create an associative array with function pointers as the value

2022-04-20 Thread rempas via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 11:10:18 UTC, vit wrote: You need shared static this for initializing immutable AA: ```d immutable void function(ref file_struct)[string] common_identifiers; shared static this(){ common_identifiers = [ "let" : _let, // "macro" :

Re: Lambda Tuple with Map Reduce

2022-04-20 Thread JG via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 08:04:42 UTC, Salih Dincer wrote: ```d alias type = real; alias func = type function(type a); [...] I think technically you should have save after range in that loop.

Re: Create an associative array with function pointers as the value

2022-04-20 Thread rempas via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 14:29:33 UTC, rikki cattermole wrote: On 21/04/2022 2:15 AM, rempas wrote: Unfortunately, this will not work for me as it uses "TypeInfo" and it is not available with "-betterC". Thank you for trying to help regardless! You can't use AA's in -betterC. The

Re: Create an associative array with function pointers as the value

2022-04-20 Thread rikki cattermole via Digitalmars-d-learn
On 21/04/2022 2:15 AM, rempas wrote: Unfortunately, this will not work for me as it uses "TypeInfo" and it is not available with "-betterC". Thank you for trying to help regardless! You can't use AA's in -betterC. The implementation is not templated and is in druntime.

Re: Lambda Tuple with Map Reduce

2022-04-20 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 08:37:09 UTC, Salih Dincer wrote: On Wednesday, 20 April 2022 at 08:04:42 UTC, Salih Dincer wrote: I get an unexpected result inside the second foreach() loop. Anyone know your reason? It's my fault, here is the solution: ```d foreach(fun; funs) {

Lambda Tuple with Map Reduce

2022-04-20 Thread Salih Dincer via Digitalmars-d-learn
```d alias type = real; alias func = type function(type a); void main() { import std.range; auto range = 10.iota!type(14, .5); alias fun1 = (type a) => a * a; alias fun2 = (type a) => a * 2; alias fun3 = (type a) => a + 1; alias fun4 = (type a) => a - 1; alias fun5 = (type a) => a

Re: Lambda Tuple with Map Reduce

2022-04-20 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 08:04:42 UTC, Salih Dincer wrote: I get an unexpected result inside the second foreach() loop. Anyone know your reason? It's my fault, here is the solution: ```d foreach(fun; funs) { range.map!(a => fun(a)) .reduce!sum

Re: Create an associative array with function pointers as the value

2022-04-20 Thread vit via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 10:42:59 UTC, rempas wrote: I'm trying to create an associative array where the keys will be a "string" type and the values will be function pointers. I'm using a custom type is called "file_struct" and for anyone that wants to try specifically with this type,

Re: ldc2 error , Error: declaration . . is already defined

2022-04-20 Thread Alain De Vos via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 18:04:13 UTC, Alain De Vos wrote: When compiling a .d file i don't see line numbers on which the error occurs which is quite annoying. The line i use to compile is : ldc2 --gcc=cc --vcolumns --oq --dip1000 --dip25 --safe-stack-layout --boundscheck=on --D --g --w

ldc2 error , Error: declaration . . is already defined

2022-04-20 Thread Alain De Vos via Digitalmars-d-learn
When compiling a .d file i don't see line numbers on which the error occurs which is quite annoying. The line i use to compile is : ldc2 --gcc=cc --vcolumns --oq --dip1000 --dip25 --safe-stack-layout --boundscheck=on --D --g --w --de --d-debug `find . -name \*.d -print` Even: lcd2 test.d

Re: Infinite fibonacci sequence, lazy take first 42 values

2022-04-20 Thread Ali Çehreli via Digitalmars-d-learn
On 4/20/22 19:11, Alain De Vos wrote: > Maybe there are multiple solutions ? Indeed. :) I have a Range struct here: http://ddili.org/ders/d.en/ranges.html#ix_ranges.infinite%20range Another one with fibers here: http://ddili.org/ders/d.en/fibers.html The same chapter uses Generator:

Re: dub import local D package

2022-04-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/20/22 7:39 PM, data pulverizer wrote: Hi all, I'm trying to import a local dub package into a dub project (`json` format). I have added the package I'm trying to import with `dub add-local` and `dub add-path` and including it within the json file, but I get the error ``` $ dub build

Re: dub import local D package

2022-04-20 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 21 April 2022 at 00:14:16 UTC, Steven Schveighoffer wrote: Did you substitute something real with `...` to hide it from your post? Because that's not a real path. I used it to hide my actual paths.

Infinite fibonacci sequence, lazy take first 42 values

2022-04-20 Thread Alain De Vos via Digitalmars-d-learn
Following java program creates an infinite fibonacci sequence (stream) an takes the first 42 values of it. import java.util.function.UnaryOperator; import java.util.stream.IntStream; import java.util.stream.Stream; public class test3 { public static void main(String[] args) { int

Re: dub import local D package

2022-04-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/20/22 9:53 PM, data pulverizer wrote: On Thursday, 21 April 2022 at 00:14:16 UTC, Steven Schveighoffer wrote: Did you substitute something real with `...` to hide it from your post? Because that's not a real path. I used it to hide my actual paths. OK, so reviewing with that in mind,

dub import local D package

2022-04-20 Thread data pulverizer via Digitalmars-d-learn
Hi all, I'm trying to import a local dub package into a dub project (`json` format). I have added the package I'm trying to import with `dub add-local` and `dub add-path` and including it within the json file, but I get the error ``` $ dub build Performing "debug" build using

Re: Infinite fibonacci sequence, lazy take first 42 values

2022-04-20 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 21 April 2022 at 03:41:24 UTC, Ali Çehreli wrote: On 4/20/22 19:11, Alain De Vos wrote: > Maybe there are multiple solutions ? Indeed. :) I have a Range struct here: http://ddili.org/ders/d.en/ranges.html#ix_ranges.infinite%20range My favorite is the struct range.

stack frame & dangling pointer weirdness

2022-04-20 Thread Alain De Vos via Digitalmars-d-learn
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 : 7FFFDFAC 2 7FFFDFAC 32767 I don't understand why. Would it be

Re: Infinite fibonacci sequence, lazy take first 42 values

2022-04-20 Thread Alain De Vos via Digitalmars-d-learn
On Thursday, 21 April 2022 at 04:36:13 UTC, Salih Dincer wrote: On Thursday, 21 April 2022 at 03:41:24 UTC, Ali Çehreli wrote: On 4/20/22 19:11, Alain De Vos wrote: > Maybe there are multiple solutions ? Indeed. :) I have a Range struct here: