Re: Pointer to environment.get

2023-08-30 Thread Vino via Digitalmars-d-learn

On Monday, 28 August 2023 at 10:27:07 UTC, Basile B. wrote:

On Monday, 28 August 2023 at 10:20:14 UTC, Basile B. wrote:

[...]


To go further, the correct code for syntax you wanted to use is 
actually


```d
alias Ext_T = string (const char[] a, string b); // define a 
function type

alias Ext_PT = Ext_T*; // define a function **pointer** type
Ext_PT ext = 
```

But as you can see that does not allow to capture the argument. 
Also it only work as AliasDeclaration RHS.


Thank you


Re: Pointer to environment.get

2023-08-28 Thread Basile B. via Digitalmars-d-learn

On Monday, 28 August 2023 at 10:20:14 UTC, Basile B. wrote:

On Monday, 28 August 2023 at 06:38:50 UTC, Vino wrote:

Hi All,

  The the below code is not working, hence requesting your 
help.


Code:
```
import std.stdio;
import std.process: environment;
void main () {
   int* ext(string) = ("PATHEXT");
   writeln(*ext);
}
```


Problems is that "PATHEXT" is a runtime argument. If you really 
want to get a pointer to the function for that runtime argument 
you can use a lambda:


```d
import std.stdio;
import std.process: environment;
void main () {

alias atGet = {return environment.get("PATHEXT");}; // 
really lazy


writeln(atGet); // pointer to the lambda
writeln((*atGet)());// call the lambda
}
```

There might be other ways, but less idiomatic (using a struct + 
opCall, a.k.a  a "functor")


To go further, the correct code for syntax you wanted to use is 
actually


```d
alias Ext_T = string (const char[] a, string b); // define a 
function type

alias Ext_PT = Ext_T*; // define a function **pointer** type
Ext_PT ext = 
```

But as you can see that does not allow to capture the argument. 
Also it only work as AliasDeclaration RHS.


Re: Pointer to environment.get

2023-08-28 Thread Basile B. via Digitalmars-d-learn

On Monday, 28 August 2023 at 06:38:50 UTC, Vino wrote:

Hi All,

  The the below code is not working, hence requesting your help.

Code:
```
import std.stdio;
import std.process: environment;
void main () {
   int* ext(string) = ("PATHEXT");
   writeln(*ext);
}
```


Problems is that "PATHEXT" is a runtime argument. If you really 
want to get a pointer to the function for that runtime argument 
you can use a lambda:


```d
import std.stdio;
import std.process: environment;
void main () {

alias atGet = {return environment.get("PATHEXT");}; // really 
lazy


writeln(atGet); // pointer to the lambda
writeln((*atGet)());// call the lambda
}
```

There might be other ways, but less idiomatic (using a struct + 
opCall, a.k.a  a "functor")


Pointer to environment.get

2023-08-28 Thread Vino via Digitalmars-d-learn

Hi All,

  The the below code is not working, hence requesting your help.

Code:
```
import std.stdio;
import std.process: environment;
void main () {
   int* ext(string) = ("PATHEXT");
   writeln(*ext);
}
```