Re: As many thanks As possible to who crates D and UFCS feature

2017-05-12 Thread k-five via Digitalmars-d-learn
On Friday, 12 May 2017 at 12:56:50 UTC, drug wrote: 12.05.2017 14:58, k-five пишет: On Friday, 12 May 2017 at 11:41:57 UTC, cym13 wrote: On Friday, 12 May 2017 at 11:10:01 UTC, k-five wrote: --- also .each!writeln should be possible

Re: As many thanks As possible to who crates D and UFCS feature

2017-05-12 Thread drug via Digitalmars-d-learn
12.05.2017 14:58, k-five пишет: On Friday, 12 May 2017 at 11:41:57 UTC, cym13 wrote: On Friday, 12 May 2017 at 11:10:01 UTC, k-five wrote: --- Shorter: void main( string[] args ){ dirEntries( ".", SpanMode.depth, false )

Re: As many thanks As possible to who crates D and UFCS feature

2017-05-12 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 12 May 2017 at 11:10:01 UTC, k-five wrote: I was waiting for a stable version of C++17 ( standard library ) to add some features of fileSystem in C++17 to my program that wants to iterate through all files in a directory recursively. I was thinking how could I do for implementing

Re: As many thanks As possible to who crates D and UFCS feature

2017-05-12 Thread cym13 via Digitalmars-d-learn
On Friday, 12 May 2017 at 11:58:23 UTC, k-five wrote: On Friday, 12 May 2017 at 11:41:57 UTC, cym13 wrote: [...] --- [...] - Thanks and the correct syntax for each! is, passing a

Re: As many thanks As possible to who crates D and UFCS feature

2017-05-12 Thread k-five via Digitalmars-d-learn
On Friday, 12 May 2017 at 11:41:57 UTC, cym13 wrote: On Friday, 12 May 2017 at 11:10:01 UTC, k-five wrote: --- Shorter: void main( string[] args ){ dirEntries( ".", SpanMode.depth, false ) .filter!( file =>

Re: As many thanks As possible to who crates D and UFCS feature

2017-05-12 Thread cym13 via Digitalmars-d-learn
On Friday, 12 May 2017 at 11:10:01 UTC, k-five wrote: I was waiting for a stable version of C++17 ( standard library ) to add some features of fileSystem in C++17 to my program that wants to iterate through all files in a directory recursively. I was thinking how could I do for implementing

As many thanks As possible to who crates D and UFCS feature

2017-05-12 Thread k-five via Digitalmars-d-learn
I was waiting for a stable version of C++17 ( standard library ) to add some features of fileSystem in C++17 to my program that wants to iterate through all files in a directory recursively. I was thinking how could I do for implementing that and add it to my program. Now after starting to

Re: alias and UFCS

2017-01-24 Thread ixid via Digitalmars-d-learn
: [...] Submit a bug report then. I will if it turns out the behaviour is wrong, that's what I'm checking at this stage. =) Apologies for the extra post - does the alias function count as declared in the same scope as the content of the function? That would be plausible as UFCS refuses to work

Re: alias and UFCS

2017-01-24 Thread Stefan Koch via Digitalmars-d-learn
the behaviour is wrong, that's what I'm checking at this stage. =) Apologies for the extra post - does the alias function count as declared in the same scope as the content of the function? That would be plausible as UFCS refuses to work on functions declared in the same scope. Is this something

Re: alias and UFCS

2017-01-24 Thread ixid via Digitalmars-d-learn
' for type 'int[]' (or whatever type I use). The alias rules for functions seem to be incompatible with UFCS, F(n) works fine. What are the rewrite steps here? Is this necessary or an oversight? Not very uniform function call syntax. Submit a bug report then. I will if it turns out the behaviour

Re: alias and UFCS

2017-01-24 Thread ixid via Digitalmars-d-learn
for functions seem to be incompatible with UFCS, F(n) works fine. What are the rewrite steps here? Is this necessary or an oversight? Not very uniform function call syntax. Submit a bug report then. I will if it turns out the behaviour is wrong, that's what I'm checking at this stage. =)

Re: alias and UFCS

2017-01-24 Thread Anonymouse via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 13:11:41 UTC, ixid wrote: This code: T tFunc(alias F, T)(T n) { n.F; return n; } Produces this error: Error: no property 'F' for type 'int[]' (or whatever type I use). I believe UFCS is supposed to only work with top-level functions. I don't

Re: alias and UFCS

2017-01-24 Thread Las via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 13:11:41 UTC, ixid wrote: This code: T tFunc(alias F, T)(T n) { n.F; return n; } Produces this error: Error: no property 'F' for type 'int[]' (or whatever type I use). The alias rules for functions seem to be incompatible with UFCS, F(n

Re: UFCS not working with alias

2016-09-08 Thread Andre Pany via Digitalmars-d-learn
arr, string[string] keyPredicate) { ...filter! } This way I can use UFCS. Kind regards André

Re: UFCS not working with alias

2016-09-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/7/16 4:26 AM, Andre Pany wrote: On Wednesday, 7 September 2016 at 08:08:34 UTC, rikki cattermole wrote: On 07/09/2016 8:06 PM, Andre Pany wrote: Should I open an enhancement request? No. It works outside of the function (part of lookup rules). I simplified my example too much. Yes in

Re: UFCS not working with alias

2016-09-07 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 7 September 2016 at 08:35:26 UTC, rikki cattermole wrote: On 07/09/2016 8:26 PM, Andre Pany wrote: [...] People have tried, this is the behavior as designed. The workaround is simple, don't use UFCS. I won't repeat the explanation or reasoning here, plenty of posts

Re: UFCS not working with alias

2016-09-07 Thread rikki cattermole via Digitalmars-d-learn
ior as designed. The workaround is simple, don't use UFCS. I won't repeat the explanation or reasoning here, plenty of posts on it ;)

Re: UFCS not working with alias

2016-09-07 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 7 September 2016 at 08:08:34 UTC, rikki cattermole wrote: On 07/09/2016 8:06 PM, Andre Pany wrote: Should I open an enhancement request? No. It works outside of the function (part of lookup rules). I simplified my example too much. Yes in the example above I can move the

Re: UFCS not working with alias

2016-09-07 Thread rikki cattermole via Digitalmars-d-learn
On 07/09/2016 8:06 PM, Andre Pany wrote: Should I open an enhancement request? No. It works outside of the function (part of lookup rules).

UFCS not working with alias

2016-09-07 Thread Andre Pany via Digitalmars-d-learn
Hi, I just noticed ufcs does not work with alias. Is this limitation needed? void foo(int a) {} void main() { alias bar = foo; 3.foo(); 3.bar(); } Last line fails with "no property 'bar' for type int. Should I open an enhancement request? Kind regards André

Re: UFCS with implicit "this" ?

2016-08-09 Thread cy via Digitalmars-d-learn
On Tuesday, 9 August 2016 at 05:33:09 UTC, Jonathan M Davis wrote: Personally, I think that you should just make it a member function if it's not a generic function, but to each their own, Well, I use generics for when I have like, optional functionality that isn't inherent to the class

Re: UFCS with implicit "this" ?

2016-08-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 09, 2016 05:13:44 cy via Digitalmars-d-learn wrote: > I really like UFCS, which is to say, defining functions outside > the class/struct to operate on it, but you can still say > object.function(...) and it'll get rewritten into > function(object,...). > >

UFCS with implicit "this" ?

2016-08-08 Thread cy via Digitalmars-d-learn
I really like UFCS, which is to say, defining functions outside the class/struct to operate on it, but you can still say object.function(...) and it'll get rewritten into function(object,...). Only sticky point is the convenience of "this". Like I can go struct A {

Re: Operator overloading through UFCS doesn't work

2016-05-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 31, 2016 14:11:58 ixid via Digitalmars-d-learn wrote: > On Sunday, 29 May 2016 at 07:18:10 UTC, Jonathan M Davis wrote: > > And the fact that allowing free functions to overload operators > > via UFCS sends us into that territory just highlights the fact > > th

Re: Operator overloading through UFCS doesn't work

2016-05-31 Thread ixid via Digitalmars-d-learn
On Sunday, 29 May 2016 at 07:18:10 UTC, Jonathan M Davis wrote: And the fact that allowing free functions to overload operators via UFCS sends us into that territory just highlights the fact that they're a horrible idea. - Jonathan M Davis Do you have any examples of UFCS doing bad things

Re: Operator overloading through UFCS doesn't work

2016-05-30 Thread pineapple via Digitalmars-d-learn
Here's one more vote for extending UFCS to operator overloading. Elie wrote that it's "a restriction that seems pointless and arbitrary"... which summarizes my own thoughts rather well, too. There are certainly concerning scenarios that can arise from making this change, but the c

Re: Operator overloading through UFCS doesn't work

2016-05-30 Thread Marc Schütz via Digitalmars-d-learn
g. And the fact that allowing free functions to overload operators via UFCS sends us into that territory just highlights the fact that they're a horrible idea. I'd say the fact that it doesn't work, and can't currently work for the reasons you described, points to an inconsistency in the langu

Re: Operator overloading through UFCS doesn't work

2016-05-29 Thread Jonathan M Davis via Digitalmars-d-learn
the built-in types. They don't need operator overloading. They already have the operators. Operators are supposed to be used as operators, not functions, and if there's any need to use them as functions, then there's something seriously wrong. And the fact that allowing free functions to overload operato

Re: Operator overloading through UFCS doesn't work

2016-05-27 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 26 May 2016 at 06:23:17 UTC, Jonathan M Davis wrote: The difference is that it's impossible to do 10.opBinary!"+"(15), so if you're forced to do foo.opBinary!"+"(bar) to get around a symbol conflict, it won't work with built-in types. Well, that begs the question: Why don't

Re: Operator overloading through UFCS doesn't work

2016-05-26 Thread Timon Gehr via Digitalmars-d-learn
On 25.05.2016 01:19, Elie Morisse wrote: On Saturday, 13 October 2012 at 22:58:56 UTC, Timon Gehr wrote: Afaik free-function operator overloads (but not in the context of UFCS) were considered and turned down because D did not want to get amidst discussions about adding Koenig lookup. UFCS does

Re: Operator overloading through UFCS doesn't work

2016-05-26 Thread Jonathan M Davis via Digitalmars-d-learn
te on a variety of types - including both built-in types and user-defined types. If code is going to use +, then + must work. opBinary!"+" is simply not going to cut it. With UFCS, if there's a potential symbol conflict, then you can work around it - even in generic code. But with an overloade

Re: Operator overloading through UFCS doesn't work

2016-05-26 Thread Elie Morisse via Digitalmars-d-learn
r overloading should be limited to class and struct types, so that's not really relevant. UFCS does not have that problem, because you're dealing with free functions and can choose to not use UFCS and provide the full import path or to alias the function, which you can't do with operators

Re: Operator overloading through UFCS doesn't work

2016-05-26 Thread Jonathan M Davis via Digitalmars-d-learn
rced to do foo.opBinary!"+"(bar) to get around a symbol conflict, it won't work with built-in types. UFCS does not have that problem, because you're dealing with free functions and can choose to not use UFCS and provide the full import path or to alias the function, which you can'

Re: Operator overloading through UFCS doesn't work

2016-05-25 Thread Elie Morisse via Digitalmars-d-learn
On Wednesday, 25 May 2016 at 21:50:06 UTC, Jonathan M Davis wrote: It's not an overloaded operator anymore at that point, and that definitely fails to work for generic code, since not all operators are overloaded operators. Free functions don't have that problem. Sorry to reiterate the

Re: Operator overloading through UFCS doesn't work

2016-05-25 Thread Jonathan M Davis via Digitalmars-d-learn
er 2012 at 22:58:56 UTC, Timon Gehr wrote: > >> > Afaik free-function operator overloads (but not in the > >> > context of UFCS) were considered and turned down because D > >> > did not want to get amidst discussions about adding Koenig > >> > lookup

Re: Operator overloading through UFCS doesn't work

2016-05-25 Thread Elie Morisse via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 23:43:46 UTC, Jonathan M Davis wrote: On Tuesday, May 24, 2016 23:19:32 Elie Morisse via Digitalmars-d-learn wrote: On Saturday, 13 October 2012 at 22:58:56 UTC, Timon Gehr wrote: > Afaik free-function operator overloads (but not in the > context of UFCS

Re: Operator overloading through UFCS doesn't work

2016-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 24, 2016 23:19:32 Elie Morisse via Digitalmars-d-learn wrote: > On Saturday, 13 October 2012 at 22:58:56 UTC, Timon Gehr wrote: > > Afaik free-function operator overloads (but not in the context > > of UFCS) were considered and turned down because D did not want &g

Re: Operator overloading through UFCS doesn't work

2016-05-24 Thread Elie Morisse via Digitalmars-d-learn
On Saturday, 13 October 2012 at 22:58:56 UTC, Timon Gehr wrote: Afaik free-function operator overloads (but not in the context of UFCS) were considered and turned down because D did not want to get amidst discussions about adding Koenig lookup. UFCS does not do Koenig lookup. I don't get

Re: opDispatch and UFCS

2016-05-11 Thread John Colvin via Digitalmars-d-learn
will always be preferred over UFCS, just like any other member access, so if you have an unrestricted opDispatch, you basically disable ufcs on the type. I think I was hoping that the opDispatch wouldn't compile in the second case and it would therefore fail-over to UFCS. std.typecons.Proxy

Re: opDispatch and UFCS

2016-05-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 11 May 2016 at 23:46:48 UTC, John Colvin wrote: Bug? Or am I misunderstanding how these two features are supposed to interact? I'm not sure what you actually expected there, but I'd note that in general, opDispatch will always be preferred over UFCS, just like any other member

opDispatch and UFCS

2016-05-11 Thread John Colvin via Digitalmars-d-learn
struct S { int a; template opDispatch(string s) { template opDispatch(T...) { auto ref opDispatch(Args ...)(auto ref Args args) { return S(mixin(`a.` ~ s ~ (T.length ? `!T` : ``) ~ `(args)`)); } } } }

Re: foreach UFCS

2016-03-31 Thread ixid via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:48:27 UTC, Adam D. Ruppe wrote: It is trying to look up a name i in global scope, and calling writeln on it. This is why the .name syntax exists: so you can bypass local variables with the same name when trying to access a global. It would compile if you put

Re: foreach UFCS

2016-03-31 Thread Q. Schroll via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:39:25 UTC, ixid wrote: What is going on with UFCS and foreach? foreach(i;0..5).writeln; This is not UFCS; it is calling writeln on module scope. See http://dlang.org/spec/module.html#module_scope_operators Your code is semantically identical with foreach

Re: foreach UFCS

2016-03-31 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:39:25 UTC, ixid wrote: What is going on with UFCS and foreach? There's no such thing as UFCS on foreach. UFCS only works on variables, not a foreach statement. foreach(i;0..5).writeln; You can add a line break and optional braces there to see what

Re: foreach UFCS

2016-03-31 Thread Rene Zwanenburg via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:39:25 UTC, ixid wrote: What is going on with UFCS and foreach? foreach(i;0..5).writeln; This prints five line breaks. foreach(i;0..5).i.writeln; This will not compile. foreach(i;0..5).writeln(i); This writes out 1 to 4 on separate lines. Is this supposed

foreach UFCS

2016-03-31 Thread ixid via Digitalmars-d-learn
What is going on with UFCS and foreach? foreach(i;0..5).writeln; This prints five line breaks. foreach(i;0..5).i.writeln; This will not compile. foreach(i;0..5).writeln(i); This writes out 1 to 4 on separate lines. Is this supposed to work? I thought a.b would be rewritten to b

UFCS on Enum in Member Function

2016-02-09 Thread jmh530 via Digitalmars-d-learn
I have been working with some C error codes that are organized in an enum. I noticed that if I tried to write a function that processes these error codes within a struct, then I could not use a UFCS-style call. For instance, in the code below, I could use Baz but not Caz. It seems to work

Re: UFCS on Enum in Member Function

2016-02-09 Thread anonymous via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 21:05:50 UTC, jmh530 wrote: For instance, in the code below, I could use Baz but not Caz. It seems to work when I use the alternate version of Caz calling a non-member function. Bug? No bug; works as intended. UFCS can only be used with free functions

Re: UFCS vs auto-completion support

2016-01-09 Thread cym13 via Digitalmars-d-learn
On Saturday, 9 January 2016 at 15:50:33 UTC, Jay Norwood wrote: I'm reading Jack Stouffer's documentation: http://jackstouffer.com/blog/nd_slice.html considering the UFCS example below and how it would impact auto-completion support. auto slice = sliced(iota(1000), 5, 5, 40); auto slice

Re: UFCS vs auto-completion support

2016-01-09 Thread Jay Norwood via Digitalmars-d-learn
On Saturday, 9 January 2016 at 16:00:51 UTC, cym13 wrote: I may be very naive but how is the second form more complicated than the first? Pretending these were regular function implementations ... 1000. 1000.iota. 1000.iota.sliced( iota( sliced( sliced(iota( I wouldn't be surprised if

UFCS vs auto-completion support

2016-01-09 Thread Jay Norwood via Digitalmars-d-learn
I'm reading Jack Stouffer's documentation: http://jackstouffer.com/blog/nd_slice.html considering the UFCS example below and how it would impact auto-completion support. auto slice = sliced(iota(1000), 5, 5, 40); auto slice = 1000.iota.sliced(5, 5, 40); Seems like auto-complete support

UFCS assignment syntax for templated function

2016-01-01 Thread rcorre via Digitalmars-d-learn
Bar(T) { T x; } auto val(T)(Bar!T bar) { return bar.x; } auto val(T)(ref Bar!T bar, float val) { return bar.x = val; } unittest { auto b = Bar!int(); b.val = 5; assert(b.val == 5); } --- Is there a way to invoke a templated function using the UFCS assignment syntax? That is, can `obj.fun

Re: UFCS assignment syntax for templated function

2016-01-01 Thread rcorre via Digitalmars-d-learn
On Friday, 1 January 2016 at 11:59:39 UTC, rcorre wrote: auto val(T)(ref Bar!T bar, float val) { return bar.x = val; } Uh, never mind. That `float` should have been `T`. Seems to work now.

Re: Calling Syntax (no, not UFCS)

2015-08-04 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 3 August 2015 at 22:42:15 UTC, SirNickolas wrote: Hello! I'm new in D and it is amazing! Can you tell me please if it is discouraged or deprecated to call a function by just putting its name, without brackets? It's quite unusual for me (used C++ and Python before), but I can see

Re: Calling Syntax (no, not UFCS)

2015-08-03 Thread John Colvin via Digitalmars-d-learn
On Monday, 3 August 2015 at 22:42:15 UTC, SirNickolas wrote: Hello! I'm new in D and it is amazing! Can you tell me please if it is discouraged or deprecated to call a function by just putting its name, without brackets? It's quite unusual for me (used C++ and Python before), but I can see

Re: Calling Syntax (no, not UFCS)

2015-08-03 Thread Justin Whear via Digitalmars-d-learn
On Mon, 03 Aug 2015 22:42:14 +, SirNickolas wrote: Hello! I'm new in D and it is amazing! Can you tell me please if it is discouraged or deprecated to call a function by just putting its name, without brackets? It's quite unusual for me (used C++ and Python before), but I can see this

Calling Syntax (no, not UFCS)

2015-08-03 Thread SirNickolas via Digitalmars-d-learn
Hello! I'm new in D and it is amazing! Can you tell me please if it is discouraged or deprecated to call a function by just putting its name, without brackets? It's quite unusual for me (used C++ and Python before), but I can see this practice even in the official Phobos documentation: ```

Re: Calling Syntax (no, not UFCS)

2015-08-03 Thread sigod via Digitalmars-d-learn
On Monday, 3 August 2015 at 22:42:15 UTC, SirNickolas wrote: Hello! I'm new in D and it is amazing! Can you tell me please if it is discouraged or deprecated to call a function by just putting its name, without brackets? It's quite unusual for me (used C++ and Python before), but I can see

Re: @property on free function for UFCS?

2015-06-14 Thread Adam D. Ruppe via Digitalmars-d-learn
You can use @property there, but you don't have to because you can call it with optional parenthesis anyway.

Re: @property on free function for UFCS?

2015-06-14 Thread rcorre via Digitalmars-d-learn
On Sunday, 14 June 2015 at 12:36:43 UTC, Adam D. Ruppe wrote: You can use @property there, but you don't have to because you can call it with optional parenthesis anyway. Thanks. Is there a good reference for the current state of @property? I know it was hotly debated for awhile (and maybe

@property on free function for UFCS?

2015-06-14 Thread rcorre via Digitalmars-d-learn
Suppose I have a function defined like so: void foo(int i) { } intended to be called like: 5.foo Should it be labeled with @property? Or is @property only for true member functions?

Re: @property on free function for UFCS?

2015-06-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 14 June 2015 at 12:53:43 UTC, rcorre wrote: Is there a good reference for the current state of @property? Easy: it does absolutely nothing right now. I'm just never sure when I should be using it (if at all). You should really only use it when you know the function is

Re: @property on free function for UFCS?

2015-06-14 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 14 June 2015 at 12:53:43 UTC, rcorre wrote: Is there a good reference for the current state of @property? I know it was hotly debated for awhile (and maybe still is?). I'm just never sure when I should be using it (if at all). Oh yes:

Re: @property on free function for UFCS?

2015-06-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 12:26:52 +, rcorre wrote: Suppose I have a function defined like so: void foo(int i) { } intended to be called like: 5.foo Should it be labeled with @property? Or is @property only for true member functions? only if you plan to use it like `foo = 5;`. i.e.

Re: @property on free function for UFCS?

2015-06-14 Thread ketmar via Digitalmars-d-learn
(){ S s; s.dg=(){ writeln(!); }; s.dg(); } Now show me the UFCS way. i'm afraid i didn't understood you here. compiler will not complain, but putting `@property` here is stylistically wrong. It's neither wrong nor right. yet i never saw this: struct S { int n; } S s; s.n

Re: @property on free function for UFCS?

2015-06-14 Thread Timon Gehr via Digitalmars-d-learn
to use it like `foo = 5;`. You can use it like that anyway. i.e. exactly like field variable. struct S{ void delegate() dg; } int main(){ S s; s.dg=(){ writeln(!); }; s.dg(); } Now show me the UFCS way. compiler will not complain, but putting `@property` here

Re: UFCS

2015-05-16 Thread Manfred Nowak via Digitalmars-d-learn
Jonathan M Davis wrote: UFCS is only ever used with the . syntax The docs say so. Thx. -manfred

Re: UFCS

2015-05-16 Thread via Digitalmars-d-learn
On Saturday, 16 May 2015 at 05:56:26 UTC, Jonathan M Davis wrote: On Friday, May 15, 2015 21:31:35 Manfred Nowak via Digitalmars-d-learn wrote: The following gives: Error: 'a += b' is not a scalar, it is a C although UFCS should engage. -manfred class C{} int main(){ void opOpAssign( string

Re: UFCS

2015-05-15 Thread Timon Gehr via Digitalmars-d-learn
On 05/15/2015 11:31 PM, Manfred Nowak wrote: class C{} int main(){ void opOpAssign( string op)( C a, C b){ } C a, b; a+= b; } https://issues.dlang.org/show_bug.cgi?id=8062

Re: UFCS

2015-05-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 15, 2015 21:31:35 Manfred Nowak via Digitalmars-d-learn wrote: The following gives: Error: 'a += b' is not a scalar, it is a C although UFCS should engage. -manfred class C{} int main(){ void opOpAssign( string op)( C a, C b){ } C a, b; a+= b; } Overloaded

UFCS

2015-05-15 Thread Manfred Nowak via Digitalmars-d-learn
The following gives: Error: 'a += b' is not a scalar, it is a C although UFCS should engage. -manfred class C{} int main(){ void opOpAssign( string op)( C a, C b){ } C a, b; a+= b; }

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-30 Thread safety0ff via Digitalmars-d-learn
Just for fun: // map, join, text, iota, writeln, tuple import std.algorithm, std.array, std.conv, std.range, std.stdio, std.typecons; void main() { iota(1,100) .map!(a = tuple(a, a % 3 == 0 ? 0 : 4, a % 5 == 0 ? 8 : 4)) .map!(a = a[1] == a[2] ? a[0].text :

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-29 Thread Atila Neves via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote: After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. [1]: http

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread Ivan Kazmenko via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote: After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. [1]: http

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread Idan Arye via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 11:03:09 UTC, bearophile wrote: Gary Willoughby: I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. Is this OK? void main() { import std.stdio, std.algorithm, std.range, std.conv, std.functional

Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread Gary Willoughby via Digitalmars-d-learn
After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. [1]: http://en.wikipedia.org/wiki/Fizz_buzz

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread bearophile via Digitalmars-d-learn
Gary Willoughby: I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. Is this OK? void main() { import std.stdio, std.algorithm, std.range, std.conv, std.functional; 100 .iota .map!(i = ((i + 1) % 15).predSwitch

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread w0rp via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote: After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. [1]: http

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread wobbles via Digitalmars-d-learn
using a UFCS chain? I've tried and failed. [1]: http://en.wikipedia.org/wiki/Fizz_buzz You can do this. import std.range : iota; import std.algorithm : map, each; import std.typecons : Tuple, tuple; import std.stdio : writeln; Tuple!(size_t, string) fizzbuzz(size_t number) { if (number

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread Andrea Fontana via Digitalmars-d-learn
] example using a UFCS chain? I've tried and failed. [1]: http://en.wikipedia.org/wiki/Fizz_buzz Here is another, hopefully readable, version with lambda built on ternary operators: - import std.algorithm, std.conv, std.functional, std.range, std.stdio; void main () { sequence !(q{n

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread John Colvin via Digitalmars-d-learn
...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. [1]: http://en.wikipedia.org/wiki/Fizz_buzz Here is another, hopefully readable, version with lambda built on ternary operators: - import std.algorithm, std.conv

Re: CTFE UFCs?

2015-04-15 Thread bitwise via Digitalmars-d-learn
On Tue, 14 Apr 2015 12:46:40 -0400, ketmar ket...@ketmar.no-ip.org wrote: On Tue, 14 Apr 2015 11:20:38 -0400, bitwise wrote: i believe that you can't do what you want in a way you want, 'cause UFCS is not working for template args. but you can do this: alias base(alias CC) = reflect

Re: CTFE UFCs?

2015-04-15 Thread bitwise via Digitalmars-d-learn
On Tue, 14 Apr 2015 12:52:19 -0400, anonymous anonym...@example.com wrote: abstract class Refl { @property abstract string name() const; immutable(Refl) base() const; } class ClassRefl(T) : Refl { @property override string name() const { return T.stringof; }

Re: CTFE UFCs?

2015-04-15 Thread bitwise via Digitalmars-d-learn
On Tue, 14 Apr 2015 12:52:19 -0400, anonymous anonym...@example.com wrote: Parting thoughts: I don't know where you're heading with this. But so far I don't see what it would buy you over std.traits and TypeInfo/TypeInfo_Class. Forgot to mention support for runtime reflection. See here:

Re: CTFE UFCs?

2015-04-14 Thread ketmar via Digitalmars-d-learn
On Tue, 14 Apr 2015 11:20:38 -0400, bitwise wrote: i believe that you can't do what you want in a way you want, 'cause UFCS is not working for template args. but you can do this: alias base(alias CC) = reflect!(CC.baseName()); ... static const(Refl) baseRefl = base!refl; signature.asc

Re: CTFE UFCs?

2015-04-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 April 2015 at 15:20:37 UTC, bitwise wrote: When I uncomment the nicer syntax, I get the errors below: [1] Error: variable refl cannot be read at compile time [2] Error: CTFE failed because of previous errors in base class Base { double d = 0.4; } class Test : Base {

CTFE UFCs?

2015-04-14 Thread bitwise via Digitalmars-d-learn
Hi. I've been building a reflection library for D, but I've hit a snag. If anyone can help out, it would be much appreciated =D In the example below, the second line of main() retrieves the reflection of a base class. Everything is well and good. Now, I am trying to come up with a more

Re: UFCS and overloading

2015-04-07 Thread cym13 via Digitalmars-d-learn
EDIT: mis-formatted previous snippet import std.algorithm, std.stdio, std.range, std.conv; void main() { stdin .byLine .filter!(s = !s.empty s.front != '#’) // Filter with this lambda function .map!(s = s.to!double) // Map the strings to doubles .array //

Re: UFCS and overloading

2015-04-07 Thread cym13 via Digitalmars-d-learn
On Monday, 6 April 2015 at 18:00:46 UTC, Szymon Gatner wrote: Why is that? The use case is to provide a set of convenience extension methods to a basic interface. Say, given: This is not the only use case, another (maybe even more common) use is to allow pipeline programming. Example from

Re: UFCS and overloading

2015-04-07 Thread Szymon Gatner via Digitalmars-d-learn
!double) // Map the strings to doubles .array // Sorting needs random access .sort!((a, b) = a b) // Another lambda .take(10) // Applyable to any range .writeln; } Yup, I get that, still does not explain why UFCS can't extend overload set. Especially if there would

Re: UFCS and overloading

2015-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
) is not callable using argument types (int) does UFCS now work with method overloading? I know it is not a syntax error because changing the name of int version of bar to bar2 and calling foo.bar2(123) works fine. You can't do this. UFCS cannot add overloads, it can only add whole overload sets

Re: UFCS and overloading

2015-04-06 Thread Szymon Gatner via Digitalmars-d-learn
error: main.d(24): Error: function main.Foo.bar (string _param_0) is not callable using argument types (int) does UFCS now work with method overloading? I know it is not a syntax error because changing the name of int version of bar to bar2 and calling foo.bar2(123) works fine. You can't do

Re: UFCS and overloading

2015-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
(123); // === error causing compilation error: main.d(24): Error: function main.Foo.bar (string _param_0) is not callable using argument types (int) does UFCS now work with method overloading? I know it is not a syntax error because changing the name of int version of bar to bar2 and calling

UFCS and overloading

2015-04-06 Thread Szymon Gatner via Digitalmars-d-learn
) does UFCS now work with method overloading? I know it is not a syntax error because changing the name of int version of bar to bar2 and calling foo.bar2(123) works fine.

Re: How does laziness and UFCS interact?

2015-03-12 Thread Ali Çehreli via Digitalmars-d-learn
On 03/10/2015 08:00 AM, John Colvin wrote: On Tuesday, 10 March 2015 at 14:41:00 UTC, Logan Capaldo wrote: On Monday, 9 March 2015 at 22:15:43 UTC, Ali Çehreli wrote: You are right. I had the same observation at minute 11:27 below, where I warn against UFCS with assumeWontThrow: http

Re: How to use UFCS and std.algorithm.sort?

2015-03-12 Thread Ali Çehreli via Digitalmars-d-learn
On 03/10/2015 01:40 AM, Jonathan M Davis via Digitalmars-d-learn wrote: .sort on an array is going to use the built-in sort property. You need to use parens if you want to use the function in std.algorithm with an array and UFCS, e.g. arr.sort(); Didn't know that. Nice! Another option

Re: How to use UFCS and std.algorithm.sort?

2015-03-10 Thread Andre via Digitalmars-d-learn
with the default less a b without specifying !(a b) .sort on an array is going to use the built-in sort property. You need to use parens if you want to use the function in std.algorithm with an array and UFCS, e.g. arr.sort(); - Jonathan M Davis

Re: How does laziness and UFCS interact?

2015-03-10 Thread Logan Capaldo via Digitalmars-d-learn
On Monday, 9 March 2015 at 22:15:43 UTC, Ali Çehreli wrote: You are right. I had the same observation at minute 11:27 below, where I warn against UFCS with assumeWontThrow: http://www.youtube.com/watch?feature=player_detailpagev=oF8K4-bieaw#t=687 Ali Sorry, which is right? I know ifThrown

Re: How does laziness and UFCS interact?

2015-03-10 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 10 March 2015 at 14:41:00 UTC, Logan Capaldo wrote: On Monday, 9 March 2015 at 22:15:43 UTC, Ali Çehreli wrote: You are right. I had the same observation at minute 11:27 below, where I warn against UFCS with assumeWontThrow: http://www.youtube.com/watch?feature=player_detailpagev

Re: How to use UFCS and std.algorithm.sort?

2015-03-10 Thread Tobias Pankrath via Digitalmars-d-learn
.array .sort buildin arrays have a .sort-property that is called.

<    1   2   3   4   5   >