Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-21 Thread WhatMeWorry via Digitalmars-d-learn
On Friday, 21 March 2025 at 13:41:18 UTC, Dennis wrote: On Thursday, 20 March 2025 at 16:18:32 UTC, WhatMeWorry wrote: Yup. That was the problem. Thank you. You guys are a sharp. From dmd version 2.111, there will be a better error message in this case. https://github.com/dlang/dmd/pull/210

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-21 Thread Dennis via Digitalmars-d-learn
On Thursday, 20 March 2025 at 16:18:32 UTC, WhatMeWorry wrote: Yup. That was the problem. Thank you. You guys are a sharp. From dmd version 2.111, there will be a better error message in this case. https://github.com/dlang/dmd/pull/21046

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-20 Thread WhatMeWorry via Digitalmars-d-learn
Yup. That was the problem. Thank you. You guys are a sharp.

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-19 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 20 March 2025 at 02:01:25 UTC, Jonathan M Davis wrote: On Wednesday, March 19, 2025 5:48:37 PM MDT H. S. Teoh via Digitalmars-d-learn wrote: I thought it was always a miss. :-D At least, it's never worked for me every time I tried it. I always have to move the UFCS functi

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 19, 2025 5:48:37 PM MDT H. S. Teoh via Digitalmars-d-learn wrote: > On Wed, Mar 19, 2025 at 11:21:15PM +, monkyyy via Digitalmars-d-learn > wrote: > [...] > > ufcs on local functions is hit or miss; > [...] > > I thought it was always a miss. :

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-19 Thread H. S. Teoh via Digitalmars-d-learn
returned if no point b is found in the > range > ``` Where is wasFound declared? If you want UFCS syntax to work, wasFound must be declared in global (module) scope. Otherwise, it will not be considered for UFCS when resolving identifiers. T -- The cat owns the house; that's why the word "homeowner" has "meow" in it.

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 19, 2025 at 11:21:15PM +, monkyyy via Digitalmars-d-learn wrote: [...] > ufcs on local functions is hit or miss; [...] I thought it was always a miss. :-D At least, it's never worked for me every time I tried it. I always have to move the UFCS function to module scope,

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-19 Thread monkyyy via Digitalmars-d-learn
); } bool existPoint(Point b, int cost) { auto i = closed.countUntil(b); // Note: closed if(i.wasFound()) // -1 is returned if no point b is found in the range ``` ufcs on local functions is hit or miss; theres a old limitation that d1 wanted or something; ussally

simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-19 Thread WhatMeWorry via Digitalmars-d-learn
``` bool wasFound(I)(I result) { return(result != -1); } bool existPoint(Point b, int cost) { auto i = closed.countUntil(b); if(wasFound(i)) // -1 is returned if no point b is found in the range ``` The above compiles and executes successfully. But

Re: Is there a way to enforce UFCS?

2023-01-06 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 6 January 2023 at 15:31:09 UTC, Salih Dincer wrote: If you don't want to get the above output you should use the previous example. But don't forget to connect alias and opCall. For example, you can use @property in version 2.0.83 without all the fanfare. I forgot one thing: if yo

Re: Is there a way to enforce UFCS?

2023-01-06 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 5 January 2023 at 23:05:17 UTC, thebluepandabear wrote: them or remove them. I agree, forbidding function call syntax would be a great usecase for `@property`. It will probably never get implemented though. In older versions, it worked when printing values ​​with writeln. But

Re: Is there a way to enforce UFCS?

2023-01-05 Thread thebluepandabear via Digitalmars-d-learn
them or remove them. I agree, forbidding function call syntax would be a great usecase for `@property`. It will probably never get implemented though.

Re: Is there a way to enforce UFCS?

2023-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 05, 2023 at 02:32:17PM +, Dom DiSc via Digitalmars-d-learn wrote: [...] > I think this is really another usecase for @property: we should forbid the > function call syntax for them (so one needs to use them like a variable). [...] > Properties are not functions. If you want a funct

Re: Is there a way to enforce UFCS?

2023-01-05 Thread Dom DiSc via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 14:21:46 UTC, bauss wrote: ```d class Foo { int bar; void setBar(Foo foo, int value) { foo.bar = value; } } void main() { foo.setBar(100); // Not UFCS - just method call to the class foo.setBar = 100; // Not UFCS - simply a setter function call

Re: Is there a way to enforce UFCS?

2023-01-04 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 14:21:46 UTC, bauss wrote: On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo

Re: Is there a way to enforce UFCS?

2023-01-04 Thread bauss via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo, int value) { foo.bar = value; } void main

Re: Is there a way to enforce UFCS?

2023-01-03 Thread Ali Çehreli via Digitalmars-d-learn
gt; d.name = "Poodle"; > In the code we can see that we have utilized UFCS (universal function > call syntax) UFCS is for calling free-standing functions as if they are member functions. Since your example already uses member functions, this feature is not UFCS. And I don't

Is there a way to enforce UFCS?

2023-01-03 Thread thebluepandabear via Digitalmars-d-learn
` object: ```D void main() { Dog d = new Dog(); d.name = "Poodle"; writeln(d.name); } ``` In the code we can see that we have utilized UFCS (universal function call syntax) to set the properties for the object. This feature is great. We have also used D's `@prope

Re: UFCS limit

2022-06-17 Thread Antonio via Digitalmars-d-learn
On Friday, 17 June 2022 at 12:26:05 UTC, Antonio wrote: UFCS vs Functional curring... nice battle :-) **UFCS & CFTE** vs **Functional currying**... nice battle :-)

Re: UFCS limit

2022-06-17 Thread Antonio via Digitalmars-d-learn
On Friday, 17 June 2022 at 01:04:28 UTC, Paul Backus wrote: 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

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
expected 1 argument(s), not 2 ``` I tried with some syntax change: ```d void main() { doSomething("Hello")("X"); (doSomething("Hello"))("X"); // it works "X".(doSomething("Hello"))(); // fails!!! } ``` ```onlineapp.d(14): Erro

Re: Singleton Object, calling member functions using UFCS (an "ugly?" example) ... better way?

2021-09-01 Thread james.p.leblanc via Digitalmars-d-learn
On Wednesday, 1 September 2021 at 22:11:29 UTC, user1234 wrote: On Wednesday, 1 September 2021 at 22:01:12 UTC, user1234 wrote: ``` ProcessPipes gnuplot () { __gshared ProcessPipes pipe; return pipe.pid ? pipe : (pipe = pipeProcess("/usr/local/bin/gnuplot")); } ``` user1234, Thank

Re: Singleton Object, calling member functions using UFCS (an "ugly?" example) ... better way?

2021-09-01 Thread user1234 via Digitalmars-d-learn
On Wednesday, 1 September 2021 at 22:01:12 UTC, user1234 wrote: On Wednesday, 1 September 2021 at 20:59:15 UTC, james.p.leblanc wrote: [...] The question is if there is a way to enable UFCS without such wrapper sorry my attention got stuck on the singleton. So my suggestion is rather to

Re: Singleton Object, calling member functions using UFCS (an "ugly?" example) ... better way?

2021-09-01 Thread user1234 via Digitalmars-d-learn
On Wednesday, 1 September 2021 at 20:59:15 UTC, james.p.leblanc wrote: [...] The question is if there is a way to enable UFCS without such wrapper sorry my attention got stuck on the singleton. So my suggestion is rather to only enable the ufcs style. This highlights the fact that the class

Re: Singleton Object, calling member functions using UFCS (an "ugly?" example) ... better way?

2021-09-01 Thread james.p.leblanc via Digitalmars-d-learn
e use of the UFCS in main() (without prefixing with instantiated object's name **gp** ). The gp prefix only needs to be in these wrappers that exist in the module, not in the main(). The question is if there is a way to enable UFCS without such wrapper (see example in main() in origin

Re: Singleton Object, calling member functions using UFCS (an "ugly?" example) ... better way?

2021-09-01 Thread user1234 via Digitalmars-d-learn
On Wednesday, 1 September 2021 at 16:02:47 UTC, james.p.leblanc wrote: Dear D-ers, For simple plotting using a gnuplot process, I have created a singleton object (a stripped down minimal working example is below.) [...] **However, those wrapper functions in the gnuplot_mod module looks a bi

Singleton Object, calling member functions using UFCS (an "ugly?" example) ... better way?

2021-09-01 Thread james.p.leblanc via Digitalmars-d-learn
ond uses a wrapper to allow use of the UFCS (uniform function call syntax) The ability to use the UFCS has the usual UFCS advantages, additionally the coder doesn't need to care about the actual name of the object's instantiation. **However, those wrapper functions in the gnuplot_mod

Re: UFCS doubt

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 23:31:57 UTC, Antonio wrote: "It works as described in the manual, not as expected" (from MySQL haters club :-p) . Yeah, 50/285 people answering the question "What language features do you miss?" chose "UFCS for local symbols" in

Re: UFCS doubt

2021-07-08 Thread Antonio via Digitalmars-d-learn
On Thursday, 8 July 2021 at 22:31:49 UTC, Dennis wrote: On Thursday, 8 July 2021 at 22:24:26 UTC, Antonio wrote: I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because UFCS in second example, but it is not... why? UFCS does not work for nested functions. Functions

Re: UFCS doubt

2021-07-08 Thread jfondren via Digitalmars-d-learn
On Thursday, 8 July 2021 at 22:24:26 UTC, Antonio wrote: onlineapp.d(9): Error: no property `mfp` for type `onlineapp.C` I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because UFCS in second example, but it is not... why? https://dlang.org/spec/function.html#pseudo

Re: UFCS doubt

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 22:24:26 UTC, Antonio wrote: I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because UFCS in second example, but it is not... why? UFCS does not work for nested functions. Functions declared in a local scope are not found when searching

Re: UFCS doubt

2021-07-08 Thread Adam Ruppe via Digitalmars-d-learn
On Thursday, 8 July 2021 at 22:24:26 UTC, Antonio wrote: I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because UFCS in second example, but it is not... why? UFCS only works with functions defined at top level, not nested inside other functions. That's just h

UFCS doubt

2021-07-08 Thread Antonio via Digitalmars-d-learn
t a; int foo(int i) { return i + a; } } void main(){ auto mfp = (C self, int i)=>self.foo(i); auto c = new C; assert( c.mfp(20)==20); } ``` onlineapp.d(9): Error: no property `mfp` for type `onlineapp.C` I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because U

Re: How can I use UFCS for a loop

2021-01-25 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 26 January 2021 at 02:19:10 UTC, Tim wrote: On Tuesday, 26 January 2021 at 01:38:45 UTC, Q. Schroll wrote: On Tuesday, 26 January 2021 at 00:47:09 UTC, Tim wrote: Hi all, How can I change the following to a more D-like approach by using UFCS? double[3] result; Unless you

Re: How can I use UFCS for a loop

2021-01-25 Thread Tim via Digitalmars-d-learn
On Tuesday, 26 January 2021 at 01:38:45 UTC, Q. Schroll wrote: On Tuesday, 26 January 2021 at 00:47:09 UTC, Tim wrote: Hi all, How can I change the following to a more D-like approach by using UFCS? double[3] result; Unless you have a good reason, use a slice and not a static array

Re: How can I use UFCS for a loop

2021-01-25 Thread Q. Schroll via Digitalmars-d-learn
On Tuesday, 26 January 2021 at 00:47:09 UTC, Tim wrote: Hi all, How can I change the following to a more D-like approach by using UFCS? double[3] result; Unless you have a good reason, use a slice and not a static array: double[] result; The result of std.array.array will be a slice

Re: How can I use UFCS for a loop

2021-01-25 Thread Q. Schroll via Digitalmars-d-learn
On Tuesday, 26 January 2021 at 00:47:09 UTC, Tim wrote: Hi all, How can I change the following to a more D-like approach by using UFCS? double[3] result; Json json = res.readJson; for(int i = 0; i < json.length; i++){ result[i] = json[i].to!double; } I'd prefer to do someth

How can I use UFCS for a loop

2021-01-25 Thread Tim via Digitalmars-d-learn
Hi all, How can I change the following to a more D-like approach by using UFCS? double[3] result; Json json = res.readJson; for(int i = 0; i < json.length; i++){ result[i] = json[i].to!double; } I'd prefer to do something like: result = res.readJson[].map!(to!double);

Re: UFCS functions with both pointers and refs

2020-12-18 Thread Marcone via Digitalmars-d-learn
Two differents types; Foo type and pointer type. Need function overload foe each or just use ref and avoid pointer.

Re: UFCS functions with both pointers and refs

2020-12-17 Thread Q. Schroll via Digitalmars-d-learn
On Tuesday, 15 December 2020 at 20:38:04 UTC, Dave P. wrote: The use case would be to define extension methods on a struct outside of where the struct is defined. The extension method mutates the state of the struct, so I want to ensure I am modifying the original struct and not a copy. If it’s

Re: UFCS functions with both pointers and refs

2020-12-15 Thread Dave P. via Digitalmars-d-learn
:). I am porting an application I had written in C to D in betterC mode piece by piece and there’s a good number of functions where it’d be convenient to call them via UFCs. Thanks for answering my questions!

Re: UFCS functions with both pointers and refs

2020-12-15 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 13 December 2020 at 19:02:34 UTC, Dave P. wrote: On Sunday, 13 December 2020 at 18:44:20 UTC, Mike Parker wrote: On Sunday, 13 December 2020 at 18:31:54 UTC, Dave P. wrote: Do I have to write both and have one forward to the other for more complicated functions? For free functions

Re: UFCS functions with both pointers and refs

2020-12-15 Thread Dave P. via Digitalmars-d-learn
On Tuesday, 15 December 2020 at 19:45:50 UTC, Q. Schroll wrote: On Sunday, 13 December 2020 at 19:02:34 UTC, Dave P. wrote: On Sunday, 13 December 2020 at 18:44:20 UTC, Mike Parker wrote: On Sunday, 13 December 2020 at 18:31:54 UTC, Dave P. wrote: Do I have to write both and have one forward to

Re: UFCS functions with both pointers and refs

2020-12-15 Thread Q. Schroll via Digitalmars-d-learn
On Sunday, 13 December 2020 at 19:02:34 UTC, Dave P. wrote: On Sunday, 13 December 2020 at 18:44:20 UTC, Mike Parker wrote: On Sunday, 13 December 2020 at 18:31:54 UTC, Dave P. wrote: Do I have to write both and have one forward to the other for more complicated functions? For free functions

Re: UFCS functions with both pointers and refs

2020-12-13 Thread Dave P. via Digitalmars-d-learn
On Sunday, 13 December 2020 at 18:44:20 UTC, Mike Parker wrote: On Sunday, 13 December 2020 at 18:31:54 UTC, Dave P. wrote: Do I have to write both and have one forward to the other for more complicated functions? For free functions, yes. Is there any way to write the function as a template

Re: UFCS functions with both pointers and refs

2020-12-13 Thread Mike Parker via Digitalmars-d-learn
(){ printf("%d\n", x); } } int main(){ Foo f; f.fooey; Foo* pf = &f; pf.fooey; f.report; // prints 2 return 0; } However, if I define it as a free function and try to invoke it via UFCS, it seems like I have to define it twice. struct Foo { int x;

UFCS functions with both pointers and refs

2020-12-13 Thread Dave P. via Digitalmars-d-learn
f.fooey; Foo* pf = &f; pf.fooey; f.report; // prints 2 return 0; } However, if I define it as a free function and try to invoke it via UFCS, it seems like I have to define it twice. struct Foo { int x; void report(){ printf("%d\n", x); } } voi

Re: How Performance down slow it is using UFCS friendly function?

2020-11-20 Thread Paul Backus via Digitalmars-d-learn
buffer[0..rq]; } catch(Throwable){return null;} } s = new Socket(AddressFamily.INET, SocketType.STREAM); writeln(s.receive(8192)); // How slow is using as friendly function? Calling a function with or without UFCS makes absolutely no difference to performance. The compiler will generate

How Performance down slow it is using UFCS friendly function?

2020-11-20 Thread Marcone via Digitalmars-d-learn
// Função receive() char[] receive(Socket socket, int size = 8192) nothrow { try { char[] buffer; buffer.length = size; int rq = socket.receive(buffer); return buffer[0..rq]; } catch(Throwable){return null;} } s = ne

Function Templates with Only Template Parameters and UFCS

2020-05-10 Thread Seven Seas via Digitalmars-d-learn
Given the code: ``` auto foo(alias A, string str)() { // do stuff } struct Bar { // members } Bar bar; bar.foo!"hello"; // This is an error. Would have to do foo!(bar, "hello") ``` Assuming that I haven't misunderstood or borked something, having UFCS for

Re: Can’t use UFCS to create InputRange?

2020-04-29 Thread Paul Backus via Digitalmars-d-learn
suddenly UFCS ranges are possible! (I am as of yet not convinced that we should, though) -- Simen This is basically what C++ calls "argument-dependent lookup." Discussion about adding this sort of thing to D has come up before on the forums [1], and iirc Walter has generally bee

Re: Can’t use UFCS to create InputRange?

2020-04-29 Thread Simen Kjærås via Digitalmars-d-learn
the module) with __traits(parent), and import that: mixin("import "~__traits(parent, R).stringof["module ".length..$]~";"); However, doing that in isInputRange doesn't help much. First, all other range functions would have to do it, and second, just impo

Re: Can’t use UFCS to create InputRange?

2020-04-29 Thread user1234 via Digitalmars-d-learn
On Wednesday, 29 April 2020 at 08:34:53 UTC, Ogi wrote: struct R {} int front(R r) { return 42; } void popFront(R r) {} bool empty(R r) { return false; } void main() { import std.range.primitives : isInputRange; static assert(isInputRange!R); } Error: static assert: `isInputRange!(R)`

Re: Can’t use UFCS to create InputRange?

2020-04-29 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 29 April 2020 at 08:34:53 UTC, Ogi wrote: struct R {} int front(R r) { return 42; } void popFront(R r) {} bool empty(R r) { return false; } void main() { import std.range.primitives : isInputRange; static assert(isInputRange!R); } Error: static assert: `isInputRange!(R)`

Can’t use UFCS to create InputRange?

2020-04-29 Thread Ogi via Digitalmars-d-learn
struct R {} int front(R r) { return 42; } void popFront(R r) {} bool empty(R r) { return false; } void main() { import std.range.primitives : isInputRange; static assert(isInputRange!R); } Error: static assert: `isInputRange!(R)` is false Whats really weird is that if I replace isInp

Re: No UFCS with nested functions?

2019-11-05 Thread Jonathan M Davis via Digitalmars-d-learn
owing not work? It works, if I move the > >> 'prop' out of 'foo'. > > > > UFCS is only supported for module-level functions, as far as I > > know. > > > >> --- > >> struct S { > >> > >>ubyte[12] bar; &

Re: No UFCS with nested functions?

2019-11-05 Thread ixid via Digitalmars-d-learn
On Monday, 4 November 2019 at 20:46:41 UTC, H. S. Teoh wrote: On Mon, Nov 04, 2019 at 07:51:26PM +, Tobias Pankrath via Digitalmars-d-learn wrote: Why does the following not work? It works, if I move the 'prop' out of 'foo'. UFCS is only supported for module-level fu

Re: No UFCS with nested functions?

2019-11-04 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 5 November 2019 at 00:34:33 UTC, Nicholas Wilson wrote: https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/ struct S { ubyte[12] bar; } alias I(alias f) = f; bool foo (ref S s) { static bool prop(const(ubyte)[] f) { return f.length >

Re: No UFCS with nested functions?

2019-11-04 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 4 November 2019 at 19:51:26 UTC, Tobias Pankrath wrote: Why does the following not work? It works, if I move the 'prop' out of 'foo'. --- struct S { ubyte[12] bar; } bool foo (ref S s) { static bool prop(const(ubyte)[] f) { return f.length > 1; } return s

Re: No UFCS with nested functions?

2019-11-04 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 04, 2019 at 07:51:26PM +, Tobias Pankrath via Digitalmars-d-learn wrote: > Why does the following not work? It works, if I move the 'prop' out of > 'foo'. UFCS is only supported for module-level functions, as far as I know. > --- >

No UFCS with nested functions?

2019-11-04 Thread Tobias Pankrath via Digitalmars-d-learn
Why does the following not work? It works, if I move the 'prop' out of 'foo'. --- struct S { ubyte[12] bar; } bool foo (ref S s) { static bool prop(const(ubyte)[] f) { return f.length > 1; } return s.bar[].prop; } --- Thanks!

Re: Cannot use UFCS in lambda?

2018-09-16 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 16 September 2018 at 10:55:43 UTC, berni wrote: The problem is more general: you can only use top-level symbols in UFCS. You can use an identity alias template to bypass this: https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/ (search for UFCS in the

Re: Cannot use UFCS in lambda?

2018-09-16 Thread berni via Digitalmars-d-learn
The problem is more general: you can only use top-level symbols in UFCS. You can use an identity alias template to bypass this: https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/ (search for UFCS in the page). Good to know. :-)

Re: Cannot use UFCS in lambda?

2018-09-16 Thread Vladimir Panteleev via Digitalmars-d-learn
On Sunday, 16 September 2018 at 09:46:15 UTC, berni wrote: Where is my mistake? Lambdas are not the issue here. The problem is more general: you can only use top-level symbols in UFCS. You can use an identity alias template to bypass this: https://blog.thecybershadow.net/2015/04/28/the

Cannot use UFCS in lambda?

2018-09-16 Thread berni via Digitalmars-d-learn
property foo for type S /usr/include/dmd/phobos/std/algorithm/iteration.d(1108): instantiated from here: >FilterResult!(__lambda1, S[]) test.d(18):instantiated from here: filter!(S[]) When I replace the UFCS-Syntax in the lambda by a function call it works: [S(1),S(2),S(3),S(4),

Re: Why does not UFCS work for method defined inside unittest block?

2018-08-01 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 31 July 2018 at 08:42:28 UTC, Simen Kjærås wrote: From https://dlang.org/spec/function.html#pseudo-member: "A free function can be called with a syntax that looks as if the function were a member function of its first parameter type." [...] Thanks a lot Simen :)

Re: Why does not UFCS work for method defined inside unittest block?

2018-07-31 Thread Simen Kjærås via Digitalmars-d-learn
can be called with a syntax that looks as if the function were a member function of its first parameter type." A function defined in a function scope (which a unittest block is), is not a free function, and so does not benefit from UFCS. There is an explanation for why at the bot

Re: Why does not UFCS work for method defined inside unittest block?

2018-07-31 Thread Ky-Anh Huynh via Digitalmars-d-learn
dmd version that I'm using: $ dmd --version DMD64 D Compiler v2.081.1-dirty Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved written by Walter Bright

Why does not UFCS work for method defined inside unittest block?

2018-07-31 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, Can I define a new quick function to use inside a unittest block? I have the following code: [code] auto foo(string[] sta) { return sta; } auto bar(string[] sta) { return sta; } auto h(string[] sta) { return sta.foo.bar; } unittest { import std.format; auto f = (string[] sta)

Re: UFCS confusion

2018-07-16 Thread vit via Digitalmars-d-learn
to call member functions? UFCS only works with free functions, meaning declared at module level. https://dlang.org/spec/function.html#pseudo-member I'm not intentionally trying to call member functions, no. The functions are all static functions of a class, but the chaining of them

Re: UFCS confusion

2018-07-13 Thread Michael via Digitalmars-d-learn
On Friday, 13 July 2018 at 11:17:32 UTC, Radu wrote: On Friday, 13 July 2018 at 11:12:47 UTC, Michael wrote: On Friday, 13 July 2018 at 10:52:54 UTC, Radu wrote: On Friday, 13 July 2018 at 10:21:54 UTC, Michael wrote: [...] Do you try to call member functions? UFCS only works with free

Re: UFCS confusion

2018-07-13 Thread Radu via Digitalmars-d-learn
On Friday, 13 July 2018 at 11:12:47 UTC, Michael wrote: On Friday, 13 July 2018 at 10:52:54 UTC, Radu wrote: On Friday, 13 July 2018 at 10:21:54 UTC, Michael wrote: [...] Do you try to call member functions? UFCS only works with free functions, meaning declared at module level. https

Re: UFCS confusion

2018-07-13 Thread Michael via Digitalmars-d-learn
What am I missing here? I'm sure it's stupidly obvious but it expects one argument, so I'm just calling it without parentheses. Do you try to call member functions? UFCS only works with free functions, meaning declared at module level. https://dlang.org/spec/function.html#pseu

Re: UFCS confusion

2018-07-13 Thread Radu via Digitalmars-d-learn
tupidly obvious but it expects one argument, so I'm just calling it without parentheses. Do you try to call member functions? UFCS only works with free functions, meaning declared at module level. https://dlang.org/spec/function.html#pseudo-member

UFCS confusion

2018-07-13 Thread Michael via Digitalmars-d-learn
Hello, I am nesting some function calls, and I'm pretty used to making use of D's Uniform Function Call Syntax, but I'm getting an error if I try to convert this line: createSet(createVector(langSize, index)).length; which works, into this line: createVector(langSize, index).createSet.le

Re: UFCS syntax I never saw before.

2018-05-24 Thread aliak via Digitalmars-d-learn
On Thursday, 24 May 2018 at 22:03:38 UTC, aliak wrote: It feels like the only difference between a no-arg function that is @property and one that is not is that the former could be invoked with optional parentheses and the latter should be illegal with parentheses. Edit: err... other way arou

Re: UFCS syntax I never saw before.

2018-05-24 Thread aliak via Digitalmars-d-learn
On Tuesday, 22 May 2018 at 14:33:20 UTC, Jonathan M Davis wrote: A free function with a single argument works just fine as a setter property. e.g. you could do something like void env(Tuple!(string, string)[] str) { // set environment variables } env = [tuple("foo", "bar")]; is perfectly

Re: UFCS syntax I never saw before.

2018-05-24 Thread aliak via Digitalmars-d-learn
On Tuesday, 22 May 2018 at 13:59:16 UTC, Steven Schveighoffer wrote: The derailed plan was to leave alone the ability to call no-arg functions without parentheses, but to REQUIRE @property to call an argument-taking function with the assignment style. See the DIP here: https://wiki.dlang.org/D

Re: UFCS syntax I never saw before.

2018-05-22 Thread Jonathan M Davis via Digitalmars-d-learn
a big wart so we don't have to fix all of @property at > least, but that should be fixed if fixing it does not crap on > UFCS and @property free functions. A free function with a single argument works just fine as a setter property. e.g. you could do something like void env(Tuple!(st

Re: UFCS syntax I never saw before.

2018-05-22 Thread Steven Schveighoffer via Digitalmars-d-learn
where fixing that will cause problems for @property free functions because they all must take more that one parameter i assume. It's quite a big wart so we don't have to fix all of @property at least, but that should be fixed if fixing it does not crap on UFCS and @property free functions.

Re: UFCS syntax I never saw before.

2018-05-22 Thread aliak via Digitalmars-d-learn
for @property free functions because they all must take more that one parameter i assume. It's quite a big wart so we don't have to fix all of @property at least, but that should be fixed if fixing it does not crap on UFCS and @property free functions.

Re: UFCS syntax I never saw before.

2018-05-22 Thread aliak via Digitalmars-d-learn
On Monday, 21 May 2018 at 14:19:35 UTC, Steven Schveighoffer wrote: On 5/21/18 8:15 AM, SrMordred wrote: Right, so this should´n be working I think. struct SomeStruct {     void foo(int); } SomeStruct s; s.foo = 10; I thought that only with @property this will work. That was the plan, bu

Re: UFCS syntax I never saw before.

2018-05-22 Thread ANtlord via Digitalmars-d-learn
es of @property actually ever meaning anything like it was originally intended to mean are pretty much zero. UFCS killed that. - Jonathan M Davis First of all thanks a lot for the response. It cleans something for me. I need a few time to think.

Re: UFCS syntax I never saw before.

2018-05-21 Thread Jonathan M Davis via Digitalmars-d-learn
t it only partially enforced it, and of course code continued to be written without using it. So, actually moving to enforcing everything with @property was slow. And then UFCS happened, and that pretty much killed the whole thing. The problem was twofold: 1. A number of folks just got in the

Re: UFCS syntax I never saw before.

2018-05-21 Thread SrMordred via Digitalmars-d-learn
"%s %s".writefln = ("foo".tuple = "bar").expand; lol

Re: UFCS syntax I never saw before.

2018-05-21 Thread Dennis via Digitalmars-d-learn
On Monday, 21 May 2018 at 11:38:12 UTC, SrMordred wrote: what?? Here's another weird example: ``` void funWithUfcsAndPropertySyntax() { import std.typecons : tuple; "%s %s".writefln = ("foo".tuple = "bar").expand; } ``` source: https://github.com/Hackerpilot/Idiotmatic-D/blob/

Re: UFCS syntax I never saw before.

2018-05-21 Thread Chris M. via Digitalmars-d-learn
On Monday, 21 May 2018 at 11:38:12 UTC, SrMordred wrote: After all this time I saw this: writeln = iota = 5; what?? I never saw that before! This is interesting, there is something useful that i can do with this kind of call? That's pretty cool, but at the same time this should be wiped of

Re: UFCS syntax I never saw before.

2018-05-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/21/18 8:15 AM, SrMordred wrote: Right, so this should´n be working I think. struct SomeStruct {     void foo(int); } SomeStruct s; s.foo = 10; I thought that only with @property this will work. That was the plan, but it got derailed. Whoever wrote that original line of code, they ne

Re: UFCS syntax I never saw before.

2018-05-21 Thread ANtlord via Digitalmars-d-learn
of code.". But something like this make doubt about what happens in a piece of code. There is static typing so I know that type a variable has, but I look at a method calling and I ask: "Is it data field? No. Is it property? No. Is it method? No. It's UFCS! Okay." And now I see that UFCS can works the same way as a property!

Re: UFCS syntax I never saw before.

2018-05-21 Thread SrMordred via Digitalmars-d-learn
Right, so this should´n be working I think. struct SomeStruct { void foo(int); } SomeStruct s; s.foo = 10; I thought that only with @property this will work.

Re: UFCS syntax I never saw before.

2018-05-21 Thread Rubn via Digitalmars-d-learn
s intended for and it's not really UFCS. It's was meant for properties that are defined as functions. struct SomeStruct { void foo(int); } SomeStruct s; s.foo = 10; It's kind of horrible syntax for what it is doing, where it isn't obvious what is happening. Writeln and

UFCS syntax I never saw before.

2018-05-21 Thread SrMordred via Digitalmars-d-learn
After all this time I saw this: writeln = iota = 5; what?? I never saw that before! This is interesting, there is something useful that i can do with this kind of call?

Re: UFCS in generic libraries, silent hijacking, and compile errors.

2018-03-13 Thread aliak via Digitalmars-d-learn
t saying it's common, just something to be aware of that is non-obvious (well it was not to me at least when I started getting in to D). It's _probably_ not going to be a problem, but if it ever is then it's going to be a very hard to detect one. And sure, the solution is to j

Re: UFCS in generic libraries, silent hijacking, and compile errors.

2018-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
tion, and proper testing would catch the rare case where there would be a problem. If you're really worried about it, then just don't use UFCS, but for better or worse, it seems to be the case that the vast majority of D programmers use UFCS all the time and don't run into problems

Re: UFCS in generic libraries, silent hijacking, and compile errors.

2018-03-11 Thread aliak via Digitalmars-d-learn
. That's actually the only technical reason why UFCS is superior to the normal function call syntax. I think this may have hit the nail on the spot. So basically my thinking is that if you're going to use UFCS inside a generic function where you can't know what kind of metho

Re: UFCS in generic libraries, silent hijacking, and compile errors.

2018-03-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 10, 2018 21:50:42 aliak via Digitalmars-d-learn wrote: > What are the recommended guidelines for using/not using UFCS in > writing generic libraries? > > I ask because if you have an internal generic free function that > you use on types in a generic algorithm

  1   2   3   4   5   >