Re: Phobos function to remove all occurances from dynamic array?

2024-05-06 Thread Lance Bachmeier via Digitalmars-d-learn
On Wednesday, 1 May 2024 at 15:18:03 UTC, Steven Schveighoffer wrote: On Wednesday, 1 May 2024 at 01:09:33 UTC, Liam McGillivray wrote: This is presumably such a common task that I'm surprised it isn't easy to find the answer by searching; Is there a standard library function that removes all

Re: Phobos function to remove all occurances from dynamic array?

2024-05-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 1 May 2024 at 01:09:33 UTC, Liam McGillivray wrote: This is presumably such a common task that I'm surprised it isn't easy to find the answer by searching; Is there a standard library function that removes all elements from a dynamic array that matches an input argument

Re: Phobos function to remove all occurances from dynamic array?

2024-05-01 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 1 May 2024 at 01:09:33 UTC, Liam McGillivray wrote: I get compiler errors when using it on other array types. I've tried using it to replace occurrences of a certain object in an array with [] in order to remove all occurrences, but it's not allowed. Can you post a code

Re: Phobos function to remove all occurances from dynamic array?

2024-04-30 Thread Liam McGillivray via Digitalmars-d-learn
On Wednesday, 1 May 2024 at 01:24:55 UTC, Lance Bachmeier wrote: Does filter do what you need? https://dlang.org/phobos/std_algorithm_iteration.html#.filter It seems to do it with the following line: ``` allObjects = allObjects.filter!(element => element !is this).array; ``` So I've found

Re: Phobos function to remove all occurances from dynamic array?

2024-04-30 Thread Lance Bachmeier via Digitalmars-d-learn
On Wednesday, 1 May 2024 at 01:09:33 UTC, Liam McGillivray wrote: This is presumably such a common task that I'm surprised it isn't easy to find the answer by searching; Is there a standard library function that removes all elements from a dynamic array that matches an input argument

Re: Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings

2024-04-19 Thread Liam McGillivray via Digitalmars-d-learn
Member, Enum, m);"); } }; ``` Correction: The code shown above actually *does* work properly without any deprecation warnings. I made a mistake with the enum being set to the CTFE function I was previously using instead of this template. This template actually works. I posted here for visibili

Re: Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings

2024-04-19 Thread Liam McGillivray via Digitalmars-d-learn
Well, someone on the Discord server has been helping me attempt this, but while I managed to get a solution that compiles without errors, I still get the deprecation warning. Here is what I ended up with: ``` template enumMixin(alias Enum) { static foreach(m; __traits(allMembers, Enum))

Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings

2024-04-19 Thread Liam McGillivray via Digitalmars-d-learn
I know that DStep generates CTFE functions to automatically make aliases for enum members so that the can be used without the enum name, as is done in C. DStep does it with a CTFE function, though it should also be possible with a mixin template. Here is my attempt so far, using a mixin

Re: Making one struct work in place of another for function calls.

2024-04-17 Thread cc via Digitalmars-d-learn
` that has the necessary members instead of only accepting `typeB`. But this is only possible if you are free to modify the definition of `someFunction`. Is there a way I can replace "`TypeB`" in the function parameters with another symbol, and then define that symbol to acc

Re: Making one struct work in place of another for function calls.

2024-04-16 Thread Andy Valencia via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 03:13:46 UTC, Liam McGillivray wrote: Is there a way I can replace "`TypeB`" in the function parameters with another symbol, and then define that symbol to accept `TypeB` as an argument, but also accept `TypeA` which would get converted to `Ty

Re: Making one struct work in place of another for function calls.

2024-04-16 Thread Liam McGillivray via Digitalmars-d-learn
`. But this is only possible if you are free to modify the definition of `someFunction`. Is there a way I can replace "`TypeB`" in the function parameters with another symbol, and then define that symbol to accept `TypeB` as an argument, but also accept `TypeA` which would get converted to `Ty

Re: Making one struct work in place of another for function calls.

2024-04-16 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 01:36:59 UTC, Liam McGillivray wrote: To better understand what I mean, take the following example, where I have a function, and two structs. ``` struct typeA { // Some member variables here } struct typeB { // Some similar member variables here

Making one struct work in place of another for function calls.

2024-04-16 Thread Liam McGillivray via Digitalmars-d-learn
I have two structs that serve roughly the same purpose, and I would like one to be accepted when the other is declared as a function parameter. To better understand what I mean, take the following example, where I have a function, and two structs. ``` struct typeA { // Some member

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 15/04/2024 10:36 AM, Liam McGillivray wrote: Well, it did work when I tried it (using a string variable, not a literal of course). It displayed as it is supposed to. But from the information I can find on the web it looks like strings are sometimes but not |always| zero-terminated. Not a

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Steven Schveighoffer via Digitalmars-d-learn
used*. That is, does the function just quickly use the string and never refers to it again? Given that this is raylib, the source is pretty readable, so you should be able to figure this out. I suppose. But if it turns out that the string is used continuously (as I assume to be the case with `InitWindow`

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Liam McGillivray via Digitalmars-d-learn
it is and when it isn't (for string variables)? So there are a few things to consider: 1. Is the string *transiently used*. That is, does the function just quickly use the string and never refers to it again? Given that this is raylib, the source is pretty readable, so you should be able

Re: How can I tell D that function args are @nogc etc.

2024-04-13 Thread Monkyyy via Digitalmars-d-learn
On Friday, 12 April 2024 at 03:57:40 UTC, John Dougan wrote: Not every day you get to blame a compiler bug. D is uniquely: hacky, expressive and buggy. Having more metaprograming then c++ without the raw man power comes at a cost, in d you should distrust the spec and instead see what the

Re: How can I tell D that function args are @nogc etc.

2024-04-12 Thread John Dougan via Digitalmars-d-learn
. It appears to be deliberate and also afflicts var declarations. Since 2014. From my point of view, either it's still a bug and needs to be written up in a best practices list with all the other long term stuff you need to work around until it can be fixed (eg. "in alias and var fun

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
strings as parameters instead of `const(char)*`. For the `InitWindow` function shown above, the overload should be defined like this: ```d void InitWindow(int width, int height, ref string title) { InitWindow(width, height, cast(const(char)*)title); } ``` This is invalid, a string may

Re: How can I tell D that function args are @nogc etc.

2024-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 12 April 2024 at 03:57:40 UTC, John Dougan wrote: What is the procedure for bug reporting? I'm looking at the issues tracker and have no clue how to drive the search to see if this is already there. https://issues.dlang.org While entering the bug title, it does a fuzzy search

Re: How can I tell D that function args are @nogc etc.

2024-04-11 Thread John Dougan via Digitalmars-d-learn
); ``` ``` bool function(int) nothrow @nogc bool function(int) nothrow @nogc @safe ``` That surprises me. `nothrow` and `@nogc` go onto the type, but not `@safe` if put before the declaration? I have no idea why. All I can think of is that it is a bug. `pragma(msg,...)` is very useful. Thanks. My

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-11 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 12:45:55 UTC, Richard (Rikki) Andrew Cattermole wrote: On 09/04/2024 12:48 PM, Liam McGillivray wrote: I suppose this was a good new thing to learn, though I'm still quite far from being able to construct a function from another function using a template. I

Re: How can I tell D that function args are @nogc etc.

2024-04-11 Thread Steven Schveighoffer via Digitalmars-d-learn
on the right hand side of the function, not the left side. Use the left side for attributes/type qualifiers that go on the return type. Just a word of warning, this explanation suggests putting qualifiers on the left side would affect the return type, this is not the case. So in my example, what did

Re: How can I tell D that function args are @nogc etc.

2024-04-10 Thread John Dougan via Digitalmars-d-learn
Interesting. Thank you to both of you. On Wednesday, 10 April 2024 at 17:38:21 UTC, Steven Schveighoffer wrote: On Wednesday, 10 April 2024 at 11:34:06 UTC, Richard (Rikki) Andrew Cattermole wrote: Place your attributes on the right hand side of the function, not the left side. Use the left

Re: Why does Nullable implicitly casts when assigning a variable but not when returning from a function?

2024-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
terprets it as a constructor call without the explicit constructor call. But it only works, because it's explicit that a variable is being declared, and therefore it must be the case that you're constructing it when you use = to give it a value. On the other hand, when you're returning a value fr

Re: Why does Nullable implicitly casts when assigning a variable but not when returning from a function?

2024-04-10 Thread Lettever via Digitalmars-d-learn
unc() Nullable? It just wants to give you an int, right? Making it a function returning an int fixes this. Andy Its an example

Re: Why does Nullable implicitly casts when assigning a variable but not when returning from a function?

2024-04-10 Thread Andy Valencia via Digitalmars-d-learn
ing it a function returning an int fixes this. Andy

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
that function is being used for both, and hence uses GC (appending). Are you sure that string appending was really the problem that caused the "TypeInfo" build error? I forgot about this, but I had already had a working CTFE function with string appending before adding the new one

Re: How can I tell D that function args are @nogc etc.

2024-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 10 April 2024 at 11:34:06 UTC, Richard (Rikki) Andrew Cattermole wrote: Place your attributes on the right hand side of the function, not the left side. Use the left side for attributes/type qualifiers that go on the return type. Just a word of warning, this explanation

Re: How can I tell D that function args are @nogc etc.

2024-04-10 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Place your attributes on the right hand side of the function, not the left side. Use the left side for attributes/type qualifiers that go on the return type. ```d bool[7] stagesToProcess = false; bool shouldDoInStages(int index) @nogc nothrow @safe { return stagesToProcess[index

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-10 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 10/04/2024 2:50 PM, Liam McGillivray wrote: On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew Cattermole wrote: The string mixin triggers CTFE, if ``EnumPrefixes`` wasn't templated, that would cause codegen and hence error. If you called it in a context that wasn't CTFE only,

How can I tell D that function args are @nogc etc.

2024-04-09 Thread John Dougan via Digitalmars-d-learn
Below is a example program that illustrates my issue. When compiled at run.dlang I get: ``` onlineapp.d(18): Error: `@safe` function `onlineapp.processSafely!(1, 4).processSafely` cannot call `@system` function pointer `shouldDo` onlineapp.d(28): Error: template instance

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Liam McGillivray via Digitalmars-d-learn
function with string appending. It's in [`source/raylib/package.d`](https://github.com/LiamM32/raylib-d/blob/49a8f2a2e4285fc85b9db54ae9a49cafe8b1a5ed/source/raylib/package.d) where `mixin(EnumPrefixes!Key("KeyboardKey", "KEY_"));` appears. The definition of `EnumPref

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 10/04/2024 11:21 AM, Liam McGillivray wrote: On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. So that function is being used for both, and hence uses GC (appending). Are you sure

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Liam McGillivray via Digitalmars-d-learn
On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. So that function is being used for both, and hence uses GC (appending). Are you sure that string appending was really the problem

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/04/2024 12:48 PM, Liam McGillivray wrote: On Tuesday, 9 April 2024 at 00:02:02 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d enum Value = (a, b) { return a + b; }(1, 2); ``` This alone should be a CTFE only function. But if we want template parameters, we'd need to wrap

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Kagamin via Digitalmars-d-learn
On Sunday, 7 April 2024 at 06:46:39 UTC, Liam McGillivray wrote: instantiated from here: `front!char` Looks like autodecoding, try to comment `canFind`.

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 00:02:02 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d enum Value = (a, b) { return a + b; }(1, 2); ``` This alone should be a CTFE only function. But if we want template parameters, we'd need to wrap it with the template. ```d template Value(int

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
; just the function I posted above was a major achievement for me. I don't understand how I would use the code you gave in place of the function I have written and posted above. Let's break it down. The expression that initializes the ``func`` variable, this is a closure. The ``a`` and ``b

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Liam McGillivray via Digitalmars-d-learn
the enum a value, that'll be CTFE only, no runtime target. Are you saying that this is a way to guarantee that the code is compile-time only? I still understand very little of this code. I'm not experienced in D metaprogramming; just the function I posted above was a major achievement for me

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 08/04/2024 10:45 AM, Liam McGillivray wrote: On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. :-( Will this ever be changed? A tad unlikely, it would be a rather large change

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-07 Thread Liam McGillivray via Digitalmars-d-learn
On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. :-( Will this ever be changed? ```d template Foo(Args) { enum Foo = () { return Args.init; }(); } ```

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-07 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Unfortunately runtime and CTFE are the same target in the compiler. So that function is being used for both, and hence uses GC (appending). ```d template Foo(Args) { enum Foo = () { return Args.init; }(); } ``` Something like that should work instead.

"Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-07 Thread Liam McGillivray via Digitalmars-d-learn
I'm making a modification to a D binding for a C library. I made a CTFE function which takes a function declaration with one or more `const(char)*` or `char*` parameters and makes an overload that accepts D strings. While this function is only used during compile time, unfortunately, I have

Re: import locality with function parameters

2024-02-01 Thread Carl Sturtivant via Digitalmars-d-learn
On Friday, 2 February 2024 at 01:23:11 UTC, Steven Schveighoffer wrote: Are you thinking of this? https://dlang.org/phobos/object.html#.imported -Steve Yes! Glad it's now part of D. Thank you.

Re: import locality with function parameters

2024-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 2 February 2024 at 00:29:51 UTC, Carl Sturtivant wrote: Hello, I seem to recall that there is surprising template to import a module and get a type from it inside the declaration of the type of a parameter to a function, so that the module need not be imported outside

import locality with function parameters

2024-02-01 Thread Carl Sturtivant via Digitalmars-d-learn
Hello, I seem to recall that there is surprising template to import a module and get a type from it inside the declaration of the type of a parameter to a function, so that the module need not be imported outside of the function definition. I think there was a blog article some years ago

Re: Function Composition

2024-01-31 Thread atzensepp via Digitalmars-d-learn
On Monday, 29 January 2024 at 19:24:51 UTC, Inkrementator wrote: On Thursday, 25 January 2024 at 18:44:26 UTC, atzensepp wrote: However this works: ```d int delegate (int) td = (x) => compose!(f,g,g,f,g,g,f,g,g,f)(x); ``` While not a real function pointer, this might already fit y

Re: Function Composition

2024-01-29 Thread Inkrementator via Digitalmars-d-learn
On Thursday, 25 January 2024 at 18:44:26 UTC, atzensepp wrote: However this works: ```d int delegate (int) td = (x) => compose!(f,g,g,f,g,g,f,g,g,f)(x); ``` While not a real function pointer, this might already fit your needs. ```d alias td = compose!(f,g); ```

Re: Function Composition

2024-01-25 Thread atzensepp via Digitalmars-d-learn
On Thursday, 25 January 2024 at 12:19:47 UTC, Paul Backus wrote: On Thursday, 25 January 2024 at 08:25:02 UTC, atzensepp wrote: ```d int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); ``` This leads to: ``` gdc lambda4.d lambda4.d:28:25: error: template compose(E)(E a) has no value int

Re: Function Composition

2024-01-25 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 25 January 2024 at 08:25:02 UTC, atzensepp wrote: ```d int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); ``` This leads to: ``` gdc lambda4.d lambda4.d:28:25: error: template compose(E)(E a) has no value int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); ``` Try using

Re: Error "Outer Function Context is Needed" when class declared in unittest

2024-01-25 Thread Kagamin via Digitalmars-d-learn
Looks like the context is currently passed for nested functions, not for nested classes.

Re: Function Composition

2024-01-25 Thread atzensepp via Digitalmars-d-learn
a pointer to composed function. ```d int main() { writeln(compose!(map!(to!(int)), split)("1 2 3").equal([1, 2, 3])); writeln( compose!(f,g,g,f,g,g,f,g,g,f)(8)); int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); writeln(t(3)); // auto cf = curry!f; // auto cf1 = cf(1); //

Re: Function Composition

2024-01-24 Thread user1234 via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 21:30:23 UTC, user1234 wrote: On Wednesday, 24 January 2024 at 21:12:20 UTC, atzensepp wrote: [...] what a bummer! Have you tried https://dlang.org/phobos/std_functional.html#compose ? Well this violates the second requirement: the composition itself

Re: Function Composition

2024-01-24 Thread user1234 via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 21:12:20 UTC, atzensepp wrote: [...] what a bummer! Have you tried https://dlang.org/phobos/std_functional.html#compose ?

Re: Function Composition

2024-01-24 Thread atzensepp via Digitalmars-d-learn
Some progress: compose function needs to know type but templates help to create for different types. ```d import std.stdio; import std.container.array; // Function composition: int f(int x) { return x*2;} ; int g(int x) { return x+2;} ; double ff(double x) { return x*x;} ; double gg(double

Function Composition

2024-01-24 Thread atzensepp via Digitalmars-d-learn
How is it possible to compose functions? I came up with following solution that is not satisfactory for two reasons: 1. the compose function should be argument agnostic here it is explicitly coded for (int) -> (int) 2. the composition itself requires additional lam

Re: Error "Outer Function Context is Needed" when class declared in unittest

2024-01-21 Thread Jim Balter via Digitalmars-d-learn
On Thursday, 5 January 2023 at 13:47:24 UTC, Adam D Ruppe wrote: On Thursday, 5 January 2023 at 13:27:23 UTC, Vijay Nayar wrote: Why is this error only found when declaring a class in the unittest? A unittest is just a special function, it can run code and have local variables. classes

Re: Partial function application (Currying)

2024-01-20 Thread atzensepp via Digitalmars-d-learn
On Saturday, 20 January 2024 at 20:58:49 UTC, Richard (Rikki) Andrew Cattermole wrote: On 21/01/2024 9:55 AM, atzensepp wrote: import std.stdio; // Overloads are resolved when the partially applied function is called // with the remaining arguments. struct S { static char fun(int i, string s

Re: Partial function application (Currying)

2024-01-20 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 21/01/2024 9:55 AM, atzensepp wrote: import std.stdio; // Overloads are resolved when the partially applied function is called // with the remaining arguments. struct S { static char fun(int i, string s) { return s[i]; } static int fun(int a, int b) { return a * b; } } void main() { alias

Re: Partial function application (Currying)

2024-01-20 Thread atzensepp via Digitalmars-d-learn
On Saturday, 20 January 2024 at 17:47:29 UTC, Richard (Rikki) Andrew Cattermole wrote: Not really any other way to do it, create context (i.e. struct, or stack) and have a delegate point to both it and a patch function. It'll be how partial is implemented. https://dlang.org/phobos

Re: Partial function application (Currying)

2024-01-20 Thread atzensepp via Digitalmars-d-learn
On Saturday, 20 January 2024 at 17:45:36 UTC, Christian Köstlin wrote: Would https://dlang.org/library/std/functional/curry.html help you? kind regards, Christian Hello Christian, thank for the link. I looks good however in my installation (gdc 8.4.0) it says: ```d curry.d:1:8: error:

Re: Partial function application (Currying)

2024-01-20 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Not really any other way to do it, create context (i.e. struct, or stack) and have a delegate point to both it and a patch function. It'll be how partial is implemented. https://dlang.org/phobos/std_functional.html#.partial

Re: Partial function application (Currying)

2024-01-20 Thread Christian Köstlin via Digitalmars-d-learn
Would https://dlang.org/library/std/functional/curry.html help you? kind regards, Christian

Partial function application (Currying)

2024-01-20 Thread atzensepp via Digitalmars-d-learn
Hello, D-Language allows for anonymous functions. Is there a way of elegant partial function application such as in other (functional) languages? A function "doemar" accepts a function with one parameter, Another function g defined within mail accepts two parameters and should

Re: `static` function ... cannot access variable in frame of ...

2024-01-16 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 15 January 2024 at 23:06:00 UTC, Steven Schveighoffer wrote: As a workaround, you can alias the outer function in the struct: ```d struct S { alias foo = S_foo; } ``` This might be less than ideal, but at least it works. It does! And it's good enough for me. Thanks a lot

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 15 January 2024 at 22:23:27 UTC, Bastiaan Veelo wrote: On Monday, 15 January 2024 at 18:43:43 UTC, user1234 wrote: The two calls are not equivalent. so what is passed as alias need to be static too. Thanks all. I thought a static member function just isn't able to access

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread user1234 via Digitalmars-d-learn
foo(alias len)() [...] The trouble is with the `static` here. A context pointer is necessary in order to have access to the context of main() from the body of this function; but `static` precludes this possibility. T I dont agree, problem is S_foo that get automagically monomorphized

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 15 January 2024 at 18:43:43 UTC, user1234 wrote: The two calls are not equivalent. so what is passed as alias need to be static too. Thanks all. I thought a static member function just isn't able to access the instance of the struct, but as I understand now it is static all

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread user1234 via Digitalmars-d-learn
On Monday, 15 January 2024 at 18:16:44 UTC, Bastiaan Veelo wrote: [...] It seems to me this should just work. Thanks! --Bastiaan. The two calls are not equivalent. To be equivalent you need to set `S_foo` static too, otherwise `S_Foo` is instanciated in `main` scope, proof: ```d import

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread H. S. Teoh via Digitalmars-d-learn
s len)() [...] The trouble is with the `static` here. A context pointer is necessary in order to have access to the context of main() from the body of this function; but `static` precludes this possibility. T -- It is of the new things that men tire --- of fashions and proposals and improvements and c

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread Dukc via Digitalmars-d-learn
)() { writeln(len); } void main() { const five = 5; S_foo!five; // Fine S.foo!five; // Error } ``` The error is ``` onlineapp.d(7): Error: `static` function `onlineapp.main.foo!(5).foo` cannot access variable `five` in frame of function `D main` onlineapp.d(19):`five` declared here

`static` function ... cannot access variable in frame of ...

2024-01-15 Thread Bastiaan Veelo via Digitalmars-d-learn
; // Fine S.foo!five; // Error } ``` The error is ``` onlineapp.d(7): Error: `static` function `onlineapp.main.foo!(5).foo` cannot access variable `five` in frame of function `D main` onlineapp.d(19):`five` declared here onlineapp.d(21): Error: template instance `onlineapp.main.foo!(5

Anonymous function scope issue?

2023-12-06 Thread DLearner via Digitalmars-d-learn
ure added. assert(XPtr.Fld1 == 3); // Shows new datastructure holds original data item. assert(XPtr.Fld2 == 4); // Shows new datastructure holds original data item. } ``` Are identical, except that, in the second demo, one variable name in the mixin function was changed to be the sam

Re: D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread Julian Fondren via Digitalmars-d-learn
On Thursday, 23 November 2023 at 20:13:59 UTC, BoQsc wrote: Nothing wrong. It would be just a more concise compact way to do the same. Also I mostly wanted to know if something like that is already possible in D language. It's not a huge loss if it is not possible. This is possible in Go:

Re: D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread BoQsc via Digitalmars-d-learn
On Thursday, 23 November 2023 at 20:00:31 UTC, H. S. Teoh wrote: On Thu, Nov 23, 2023 at 07:22:22PM +, BoQsc via Digitalmars-d-learn wrote: Is it possible to declare empty pointer variable inside function calls and pass its address to the function? These are sometimes required while using

Re: D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 23, 2023 at 07:22:22PM +, BoQsc via Digitalmars-d-learn wrote: > Is it possible to declare empty pointer variable inside function calls > and pass its address to the function? > > These are sometimes required while using Win32 - Windows Operating > System API. >

D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread BoQsc via Digitalmars-d-learn
Is it possible to declare empty pointer variable inside function calls and pass its address to the function? These are sometimes required while using Win32 - Windows Operating System API. * Empty pointer variables are used by functions to return information after the function is done. My

Re: D: How to check if a function is chained? a().b().c();

2023-11-18 Thread Julian Fondren via Digitalmars-d-learn
On Saturday, 18 November 2023 at 07:47:19 UTC, BoQsc wrote: `program("someProgramName").pipe("someOtherProgramName");` Executes and pipes output to another program. `program();` - Only executes the program. Serious answer: have a function handle this, instead of the semic

Re: D: How to check if a function is chained? a().b().c();

2023-11-18 Thread Steven Schveighoffer via Digitalmars-d-learn
chain this function!");` A function that executes a program For me syntactically it is important. One real world application would be: `program("someProgramName").pipe("someOtherProgramName");` Executes and pipes output to another program. `program();` - Only executes

Re: D: How to check if a function is chained? a().b().c();

2023-11-18 Thread Imperatorn via Digitalmars-d-learn
chain this function!");` A function that executes a program For me syntactically it is important. One real world application would be: `program("someProgramName").pipe("someOtherProgramName");` Executes and pipes output to another program. `program();` - Only executes t

D: How to check if a function is chained? a().b().c();

2023-11-17 Thread BoQsc via Digitalmars-d-learn
Let's say we have a chain of functions. ``` a().b().c(); ``` I would like to have a behaviour in `a()` that would check if there is `b()` or `c()` chained to it. If `a();`is not chained: do a `writeln("You forgot to chain this function!");` A function that executes a progr

Re: "is not an lvalue" when passing template function to spawn function

2023-11-09 Thread Bienlein via Digitalmars-d-learn
can't take the address of a template without instantiating it first. To make your example work, replace `` with `!int`, like this: spawn(!int, biz); All right. It seems I cannot pass on an object. So I store the object in a global and access it from the callback function passed

Re: "is not an lvalue" when passing template function to spawn function

2023-11-09 Thread Bienlein via Digitalmars-d-learn
!int(123);" out of the main function. Compiler complains about static this. Okay, then the code outside the main function now looks this way: class Biz(T) { private T value; this(T value) { this.value = value; } } static void addToBiz(T)(Biz!T biz) { // ... }

Re: "is not an lvalue" when passing template function to spawn function

2023-11-09 Thread Bienlein via Digitalmars-d-learn
or I found this in the Internet: https://stackoverflow.com/questions/14395018/aliases-to-mutable-thread-local-data-not-allowed But this change, did not help: spawn(!int, cast(shared) biz); Then I moved "Biz!int biz = new Biz!int(123);" out of the main function. Compiler complains abo

Re: "is not an lvalue" when passing template function to spawn function

2023-11-08 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 8 November 2023 at 16:30:49 UTC, Bienlein wrote: Hello, I get the error "`addToBiz(T)(Biz!T biz)` is not an lvalue and cannot be modified" when compiling the code below. Can't find a way how to do it right. Am a D newbie and would appreciate some help. [...] static void

"is not an lvalue" when passing template function to spawn function

2023-11-08 Thread Bienlein via Digitalmars-d-learn
Hello, I get the error "`addToBiz(T)(Biz!T biz)` is not an lvalue and cannot be modified" when compiling the code below. Can't find a way how to do it right. Am a D newbie and would appreciate some help. Thank you, Bienlein class Biz(T) { private T value; this(T value)

Re: performance issues with SIMD function

2023-11-04 Thread Guillaume Piolat via Digitalmars-d-learn
On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote: Can anyone help me to understand what I am missing? Your loop is likely dominated by sin() calls, And the rest of the loop isn't complicated enough to outperform the compiler. What you could do is use the intrinsics to implement a

Re: performance issues with SIMD function

2023-11-04 Thread Bogdan via Digitalmars-d-learn
On Friday, 3 November 2023 at 15:32:08 UTC, Sergey wrote: On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote: Hi everyone, I was playing around with the intel-intrinsics library, trying to improve the speed of a simple area function. I could not see any performance improvements from

Re: performance issues with SIMD function

2023-11-03 Thread Sergey via Digitalmars-d-learn
On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote: Hi everyone, I was playing around with the intel-intrinsics library, trying to improve the speed of a simple area function. I could not see any performance improvements from the non-SIMD implementation. The SIMD version is a little

Re: Function Overloading

2023-11-03 Thread Gaurav Negi via Digitalmars-d-learn
c.add(2);    c.writeln; // x + 2 +        // with constructor:    c = Calculate("x"); c.add(2);    c.writeln; // x + 2 + } ``` There is a simple struct like the one above that is not related to reality. There can be more than 2 function overloading in it, but in our example there

Re: performance issues with SIMD function

2023-11-03 Thread Imperatorn via Digitalmars-d-learn
On Friday, 3 November 2023 at 15:17:43 UTC, Imperatorn wrote: On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote: Hi everyone, I was playing around with the intel-intrinsics library, trying to improve the speed of a simple area function. I could not see any performance improvements

Re: performance issues with SIMD function

2023-11-03 Thread Imperatorn via Digitalmars-d-learn
On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote: Hi everyone, I was playing around with the intel-intrinsics library, trying to improve the speed of a simple area function. I could not see any performance improvements from the non-SIMD implementation. The SIMD version is a little

performance issues with SIMD function

2023-11-03 Thread Bogdan via Digitalmars-d-learn
Hi everyone, I was playing around with the intel-intrinsics library, trying to improve the speed of a simple area function. I could not see any performance improvements from the non-SIMD implementation. The SIMD version is a little bit slower even with LDC2 and --o3. Can anyone help me

Re: Function Overloading

2023-11-02 Thread Basile B. via Digitalmars-d-learn
On Thursday, 2 November 2023 at 11:17:42 UTC, Salih Dincer wrote: On Wednesday, 1 November 2023 at 20:04:52 UTC, Basile B. wrote: Yes. D constructors are not named but the current implementation adds a name that is `__ctor`, so add ```d alias add = __ctor; ``` to you struct. Yeah, it

Re: Function Overloading

2023-11-02 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 1 November 2023 at 20:04:52 UTC, Basile B. wrote: Yes. D constructors are not named but the current implementation adds a name that is `__ctor`, so add ```d alias add = __ctor; ``` to you struct. Yeah, it works! Thanks...:) SDB@79

Re: Function Overloading

2023-11-01 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 31 October 2023 at 20:09:44 UTC, Salih Dincer wrote: [...] is it possible to do something like `alias add = this;`? ```d struct Calculate {   int memory; string result;    auto toString() => result;    // alias add = this;     import std.string : format;    

Function Overloading

2023-10-31 Thread Salih Dincer via Digitalmars-d-learn
 c = Calculate("x"); c.add(2);    c.writeln; // x + 2 + } ``` There is a simple struct like the one above that is not related to reality. There can be more than 2 function overloading in it, but in our example there are only 2. Without implementing a similar function again for each c

Re: Meaning of the dot-function syntax

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:24:39 UTC, evilrat wrote: On Sunday, 1 October 2023 at 08:22:48 UTC, dhs wrote: Hi, What's the meaning of the dot in the call to writeln() below? ```d .writeln("Hello there!"); ``` I haven't found this in the spec or anywhere else. This is used very often

Re: Meaning of the dot-function syntax

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:20:32 UTC, Anonymouse wrote: On Sunday, 1 October 2023 at 08:22:48 UTC, dhs wrote: Hi, What's the meaning of the dot in the call to writeln() below? ```d .writeln("Hello there!"); ``` I haven't found this in the spec or anywhere else. This is used very

  1   2   3   4   5   6   7   8   9   10   >