Re: UFCS limit

2022-06-16 Thread bauss via Digitalmars-d-learn
On Friday, 17 June 2022 at 05:17:20 UTC, Tejas wrote: On Friday, 17 June 2022 at 01:04:28 UTC, Paul Backus wrote: Nope. The way UFCS works is that allows you to call free functions using member-function syntax, and member-function syntax is always `object.memberName`, so UFCS only works for

Re: UFCS limit

2022-06-16 Thread Paul Backus via Digitalmars-d-learn
On Friday, 17 June 2022 at 05:17:20 UTC, Tejas wrote: On Friday, 17 June 2022 at 01:04:28 UTC, Paul Backus wrote: Nope. The way UFCS works is that allows you to call free functions using member-function syntax, and member-function syntax is always `object.memberName`, so UFCS only works for

Re: UFCS limit

2022-06-16 Thread Tejas via Digitalmars-d-learn
On Friday, 17 June 2022 at 01:04:28 UTC, Paul Backus wrote: Nope. The way UFCS works is that allows you to call free functions using member-function syntax, and member-function syntax is always `object.memberName`, so UFCS only works for functions that have a name, not anonymous functions.

Re: UFCS limit

2022-06-16 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 16 June 2022 at 23:59:06 UTC, Antonio wrote: Is it there any way to apply UFCS on the returned method in the same expression? Nope. The way UFCS works is that allows you to call free functions using member-function syntax, and member-function syntax is always `object.memberName`,

UFCS limit

2022-06-16 Thread Antonio via Digitalmars-d-learn
```d auto doSomething(string text) { return (string text2) { import std.stdio; writeln(text,",",text2); }; } void main() { doSomething("Hello")("X"); "X".doSomething("Hello")(); } ``` Compiler error: ``` ... onlineapp.d(13):expected 1 argument(s), not 2 ``` I tried wit

Re: UI Library

2022-06-16 Thread harakim via Digitalmars-d-learn
On Saturday, 11 June 2022 at 21:50:47 UTC, Adam D Ruppe wrote: On Saturday, 11 June 2022 at 01:20:17 UTC, harakim wrote: The issue I'm having is that I don't understand how to assign bounds in the nested widget. I'm sure there's a very clean solution. I basically want a paintContent method but

Re: Creating DLL

2022-06-16 Thread Sergeant via Digitalmars-d-learn
On Thursday, 16 June 2022 at 16:19:22 UTC, Ali Çehreli wrote: On 6/16/22 09:07, Sergeant wrote: This answer may be relevant: https://forum.dlang.org/post/t8diks$2l79$1...@digitalmars.com Ali, thank you, I'll take a look.

Re: Creating DLL

2022-06-16 Thread Sergeant via Digitalmars-d-learn
Adam, thank you again! Adding Initialize()/Terminate() to code and calling from my application as you suggested didn't help, unfortunately. Maybe the problem is in the scripting language I'm using (AHK) which is not designed to handle situations like these. In any case, appreciate your help!

Re: Comparing Exceptions and Errors

2022-06-16 Thread kdevel via Digitalmars-d-learn
On Thursday, 16 June 2022 at 13:54:52 UTC, Steven Schveighoffer wrote: [scope (success) lowered to finally] [...] Furthermore I always thought of scope guards as a means for cleanup. Cleanup implies in my eyes removing things which have been used in a previous task. This intended use is docu

Re: Creating DLL

2022-06-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 16 June 2022 at 16:37:34 UTC, Ali Çehreli wrote: Agreed but that excludes using the D runtime in 'static this' (and shared) blocks, right? It is runtime.initialize that calls those `static this` blocks. If my explicit call to Initialize is in a 'shared static this' This is back

Re: Creating DLL

2022-06-16 Thread Ali Çehreli via Digitalmars-d-learn
On 6/16/22 09:32, Adam D Ruppe wrote: > This is why an explicit initialization call is the preferred method - > there, the time it is called is well-defined by the user after initial > loading is complete. Agreed but that excludes using the D runtime in 'static this' (and shared) blocks, right?

Re: Creating DLL

2022-06-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 16 June 2022 at 16:19:22 UTC, Ali Çehreli wrote: pragma (crt_constructor) You have to be pretty careful about this since it might not run in the order you expect. If there's two things in the program with a equal-priority crt constructor, they are run in arbitrary order. In a sh

Re: Creating DLL

2022-06-16 Thread Ali Çehreli via Digitalmars-d-learn
On 6/16/22 09:07, Sergeant wrote: > May I ask one more question: why a code like this would work in > D-application but not in D-DLL? D programs generated by D compilers automatically initialize the D runtime. You can do the same with rt_init: pragma (crt_constructor) extern(C) int initialize

Re: Creating DLL

2022-06-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 16 June 2022 at 16:07:41 UTC, Sergeant wrote: May I ask one more question: why a code like this would work in D-application but not in D-DLL? (also I notice some other D functions don't work in DLL): Probably because the runtime not initialized properly. Export an Initialize() an

Re: map! evaluates twice

2022-06-16 Thread Ali Çehreli via Digitalmars-d-learn
On 6/16/22 00:58, Salih Dincer wrote: > I guess the developed cached() and cache() are different things, > right? cache caches only the front element. https://dlang.org/library/std/algorithm/iteration/cache.html > I tried cached() cached() is supposed to cache as many elements as needed as

Re: Creating DLL

2022-06-16 Thread Sergeant via Digitalmars-d-learn
Adam thank you, it works now! May I ask one more question: why a code like this would work in D-application but not in D-DLL? (also I notice some other D functions don't work in DLL): import std.string; export extern(C) string my(string input) { string output

Re: Creating DLL

2022-06-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 16 June 2022 at 13:57:48 UTC, Sergeant wrote: export int my(int a, int b) the name here is going to be mangled, so like "_D5mydll2myiiZi" or something like that. You might want to add `extern(C)` to it so it keeps the simple name "my", that might help.

Re: getSymbolsByUDA in constructor/member functions

2022-06-16 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 16 June 2022 at 13:27:25 UTC, frame wrote: But it looks like a compiler bug since the output of `getSymbolsByUDA` is just an alias sequence and nothing should happen before consuming it? Yes, this is a compiler bug. I've filed a report for it on bugzilla: https://issues.dlang.o

Creating DLL

2022-06-16 Thread Sergeant via Digitalmars-d-learn
Hi, I wonder if anyone knowledgeable can point me in the right direction here. I created DLL in Visual D, but when I try to use it by my application (AHK script), DLL itself is loaded ok, but error is set to "specified function could not be found inside the DLL". (Same DLL that I made in C++ w

Re: Comparing Exceptions and Errors

2022-06-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/16/22 6:07 AM, kdevel wrote: On Wednesday, 15 June 2022 at 20:46:56 UTC, Steven Schveighoffer wrote: [...] It has not harmed my code though. I tried throwing inside a scope guard, and it just works, I'm not sure why you can't throw in those? You can but that is not acceptable for the

Re: getSymbolsByUDA in constructor/member functions

2022-06-16 Thread frame via Digitalmars-d-learn
On Thursday, 16 June 2022 at 09:29:36 UTC, Arafel wrote: Classes can have static members just as structs, so I don't think you always need an instance for a class either. Well, ok. So if you call `getMember` from a member function, it adds the hidden `this` reference, and this has subtle con

Re: Comparing Exceptions and Errors

2022-06-16 Thread bauss via Digitalmars-d-learn
On Thursday, 16 June 2022 at 11:38:40 UTC, kdevel wrote: On Thursday, 16 June 2022 at 11:28:32 UTC, bauss wrote: [...] https://dlang.org/spec/statement.html#scope-guard-statement Quote (again): "A [...] scope(success) statement may not exit with a throw [...]." [...] If the spec forbids it, b

Re: Comparing Exceptions and Errors

2022-06-16 Thread kdevel via Digitalmars-d-learn
On Thursday, 16 June 2022 at 11:28:32 UTC, bauss wrote: [...] https://dlang.org/spec/statement.html#scope-guard-statement Quote (again): "A [...] scope(success) statement may not exit with a throw [...]." [...] If the spec forbids it, but the compiler allows it, wouldn't it then be a bug? W

Re: Comparing Exceptions and Errors

2022-06-16 Thread bauss via Digitalmars-d-learn
On Thursday, 16 June 2022 at 10:07:23 UTC, kdevel wrote: On Wednesday, 15 June 2022 at 20:46:56 UTC, Steven Schveighoffer wrote: [...] It has not harmed my code though. I tried throwing inside a scope guard, and it just works, I'm not sure why you can't throw in those? You can but that i

Re: Bug in dmd?

2022-06-16 Thread Andrey Zherikov via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 16:53:13 UTC, mw wrote: Create a simple test case, file bug at: https://issues.dlang.org/ I tried. No luck.

Re: Comparing Exceptions and Errors

2022-06-16 Thread kdevel via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 20:46:56 UTC, Steven Schveighoffer wrote: [...] It has not harmed my code though. I tried throwing inside a scope guard, and it just works, I'm not sure why you can't throw in those? You can but that is not acceptable for the spec explicitly forbids that:

Re: Can I create a package with friendly modules

2022-06-16 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 13 June 2022 at 06:05:03 UTC, Tejas wrote: Directory structure: ```sh src | |--- main_file.d | |---parent | |--- driver.d | |--- package.d | |--- thing | |--- package.d | |--- first.d

Re: getSymbolsByUDA in constructor/member functions

2022-06-16 Thread Arafel via Digitalmars-d-learn
On 16/6/22 10:55, frame wrote: On Thursday, 16 June 2022 at 08:23:20 UTC, Arafel wrote: This is not true. `getMember` can return the symbol to the instance or the type/alias, depending if you pass `this` or `Def`. The last is static. It makes no sense to use the attribute from a class withou

Re: getSymbolsByUDA in constructor/member functions

2022-06-16 Thread frame via Digitalmars-d-learn
On Thursday, 16 June 2022 at 08:23:20 UTC, Arafel wrote: As you can see, it's `getMember` who is returning a reference to the `this` instance. In my view, this is a bug according the documentation and examples [1]. It might be that classes behave differently, but then it should be documented.

Re: getSymbolsByUDA in constructor/member functions

2022-06-16 Thread Arafel via Digitalmars-d-learn
On 15/6/22 14:26, cc wrote: ```d import std.traits; class XML {} class Def { @XML {     int x;     int y; } int z; this() {     static foreach (sym; getSymbolsByUDA!(Def, XML)) {     } } } void main() { auto def = new Def; } ``` ``` test.d(12):

Re: Convering strings containing number

2022-06-16 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 04:39:21 UTC, Mike Parker wrote: ```d str[3..4].to!int; ``` Thanks, I got the solution based on your answer. I also created different slicing functions. They work just fine without the need for conversion: ```d T solKes(string str, size_t a, size_t l)

Re: map! evaluates twice

2022-06-16 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 10 June 2022 at 22:10:10 UTC, Ali Çehreli wrote: [...] I am trying to finish a .cached range algorithm that caches all elements that are in use. (It must drop old elements so that an infinite range does not require infinite cache.) It is supposed to evaluate elements only once. I

Re: getSymbolsByUDA in constructor/member functions

2022-06-16 Thread frame via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 12:26:40 UTC, cc wrote: Why doesn't this work? There is nothing in the foreach body. ```d alias ALL = getSymbolsByUDA!(Def, XML); pragma(msg, ALL.stringof); ``` reports `tuple(this.x, this.y)`. Why is `this.` added? I can only answer this partially, I guess `th