How to use UFCS and std.algorithm.sort?

2015-03-10 Thread Andre via Digitalmars-d-learn
Hi, with the new beta I get the warning I should use std.algorithm.sort instead the .sort property. I thought the std.algorithm.sort method is used in this example? void main() { import std.algorithm: sort, uniq, map; import std.array: array; string[]

Re: How does laziness and UFCS interact?

2015-03-10 Thread via Digitalmars-d-learn
On Tuesday, 10 March 2015 at 17:42:37 UTC, Ali Çehreli wrote: You are right again. :) However, putting the lazy-taking function outside the whole expression makes it visible right away, making easy for me to realize that the execution order may be different from common chains. lazy aka named

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

2015-03-10 Thread Jonathan M Davis via Digitalmars-d-learn
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

How does laziness and UFCS interact?

2015-03-09 Thread Logan Capaldo via Digitalmars-d-learn
I just became aware of http://dlang.org/phobos/std_exception.html#.ifThrown . It's neat, but it seems non-obvious to me how lazy + UFCS should work in general. consider void lazily(T)(lazy T expression) { expression(); } It's clear when saying lazily(a.b().c()); that the whole of a.b

Re: How does laziness and UFCS interact?

2015-03-09 Thread Ali Çehreli via Digitalmars-d-learn
On 03/09/2015 03:03 PM, Logan Capaldo wrote: I just became aware of http://dlang.org/phobos/std_exception.html#.ifThrown . It's neat, but it seems non-obvious to me how lazy + UFCS should work in general. consider void lazily(T)(lazy T expression) { expression(); } It's clear when saying

UFCS on template alias ?

2015-02-21 Thread Baz via Digitalmars-d-learn
Is this a normal behaviour ? --- void main() { import std.algorithm; auto list = [0,1,2,3]; alias poly = map; list.poly!(a = a + a); } --- outputs: Error: no property 'poly' for type 'int[]'

Re: UFCS on template alias ?

2015-02-21 Thread bearophile via Digitalmars-d-learn
Baz: Is this a normal behaviour ? Try to move the definition of poly to module-level scope. This is a design decision to avoid other troubles. Bye, bearophile

Re: Constructor protection: package ctors, UFCS, static methods?

2014-12-27 Thread aldanor via Digitalmars-d-learn
On Friday, 26 December 2014 at 15:58:18 UTC, aldanor wrote: Please ignore the missing new keywords in the code and other minor typos :) Any opinions please?.. Would be much appreciated. Thanks!

Re: Constructor protection: package ctors, UFCS, static methods?

2014-12-27 Thread ketmar via Digitalmars-d-learn
On Sat, 27 Dec 2014 23:34:06 + aldanor via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 26 December 2014 at 15:58:18 UTC, aldanor wrote: Please ignore the missing new keywords in the code and other minor typos :) Any opinions please?.. Would be much

Constructor protection: package ctors, UFCS, static methods?

2014-12-26 Thread aldanor via Digitalmars-d-learn
) { super(id); } // -- package public this(...) { // high-level public ctor } Group group() const { int group_id = get_group(this.id); return Group(group_id); } } -- Solution 2: use UFCS and swap the group() / dataset(name) functions between

Re: Constructor protection: package ctors, UFCS, static methods?

2014-12-26 Thread aldanor via Digitalmars-d-learn
Please ignore the missing new keywords in the code and other minor typos :)

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Suliman via Digitalmars-d-learn
I can't understand how to use UFCS with instance of class: void main() { string name = Suliman; userName username = new userName(name); /// How to use UFCS here? userName.name.sayHello(); /// } class userName { string name; this(string name) { this.name = name

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread ketmar via Digitalmars-d-learn
On Mon, 10 Nov 2014 19:07:38 + Suliman via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: /// How to use UFCS here? userName.name.sayHello(); /// you can't. a little explanation: UFCS substitutes only the first argument. and for class methods first argument is hidden

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Justin Whear via Digitalmars-d-learn
On Mon, 10 Nov 2014 19:07:38 +, Suliman wrote: I can't understand how to use UFCS with instance of class: void main() { string name = Suliman; userName username = new userName(name); /// How to use UFCS here? userName.name.sayHello(); /// } class userName { string name

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Ali Çehreli via Digitalmars-d-learn
On 11/10/2014 11:07 AM, Suliman wrote: I can't understand how to use UFCS with instance of class: void main() { string name = Suliman; userName username = new userName(name); /// How to use UFCS here? userName.name.sayHello(); /// } class userName { string name; this(string name

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Suliman via Digitalmars-d-learn
Thanks! Ali Çehreli, could you add this mention and possible the example to your book?

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Ali Çehreli via Digitalmars-d-learn
On 11/10/2014 12:04 PM, Suliman wrote: Thanks! Ali Çehreli, could you add this mention and possible the example to your book? Of course. Perhaps I should rephrase some of the descriptions here? http://ddili.org/ders/d.en/ufcs.html Please email me at acehr...@yahoo.com if you have specific

Re: is there any reason UFCS can't be used with 'new'?

2014-09-30 Thread Nordlöw
On Sunday, 28 September 2014 at 20:28:11 UTC, Jay wrote: fwiw here's what i wrote: template New(T) if (is(T == class)) { T New(Args...) (Args args) { return new T(args); } } My try template New(T) if (is(T == class)) { T New(Args...) (Args args) { return new

Re: is there any reason UFCS can't be used with 'new'?

2014-09-30 Thread Ali Çehreli via Digitalmars-d-learn
On 09/30/2014 10:35 AM, Nordlöw wrote: On Sunday, 28 September 2014 at 20:28:11 UTC, Jay wrote: fwiw here's what i wrote: template New(T) if (is(T == class)) { T New(Args...) (Args args) { return new T(args); } } My try template New(T) if (is(T == class)) { T

Re: is there any reason UFCS can't be used with 'new'?

2014-09-30 Thread Ali Çehreli via Digitalmars-d-learn
On 09/30/2014 11:07 AM, Ali Çehreli wrote: To make a nested class unnested, declare it as static, which seems to work in your case as well: class C { int x, y; } auto x = New!C(); Copy+paste cannot read my mind. :( Of course there should be 'static' keyword there. :p

Re: is there any reason UFCS can't be used with 'new'?

2014-09-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/30/14 2:07 PM, Ali Çehreli wrote: Apparently, a class definition even inside a unittest blocks are considered to be nested classes. Normally, objects of nested classes are created by the 'this.new' syntax, 'this' meaning the object that wraps the nested class. I think unit test blocks

Re: is there any reason UFCS can't be used with 'new'?

2014-09-29 Thread Jay via Digitalmars-d-learn
On Sunday, 28 September 2014 at 22:17:03 UTC, Meta wrote: I'm not sure. Maybe it's on the same level as the Lambda Abstraction (14.5), but you'll probably have to do some testing to figure it out exactly. precedence levels seem to be defined in `src/parse.h` (the `PREC` enum) and assigned to

is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Jay via Digitalmars-d-learn
i want to chain 'new' with method calls on the created object. i found this on the internet: window.mainWidget = (new Button()).text(Hello worldd).textColor(0xFF); it would look much nicer with UFCS: window.mainWidget = Button.new().text(Hello worldd).textColor(0xFF); well, it's

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Foo via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:11:23 UTC, Jay wrote: i want to chain 'new' with method calls on the created object. i found this on the internet: window.mainWidget = (new Button()).text(Hello worldd).textColor(0xFF); it would look much nicer with UFCS: window.mainWidget

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Jay via Digitalmars-d-learn
thanks! but i'm still interested *why* you can't have this with 'new'. if there's no good reason i will file a bug report. On Sunday, 28 September 2014 at 19:19:56 UTC, Foo wrote: mixin template New(T) if (is(T == class)) { static T New(Args...)(Args args) { return new

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Idan Arye via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:32:11 UTC, Jay wrote: thanks! but i'm still interested *why* you can't have this with 'new'. if there's no good reason i will file a bug report. Because `new` is not a function - it's an operator.

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Jay via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:41:29 UTC, Idan Arye wrote: Because `new` is not a function - it's an operator. do you think the function call syntax has any chance to be implemented? is it just me who needs it?

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Jay via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:19:56 UTC, Foo wrote: mixin template New(T) if (is(T == class)) { static T New(Args...)(Args args) { return new T(args); } } fwiw here's what i wrote: template New(T) if (is(T == class)) { T New(Args...) (Args args) {

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Meta via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:11:23 UTC, Jay wrote: i want to chain 'new' with method calls on the created object. i found this on the internet: window.mainWidget = (new Button()).text(Hello worldd).textColor(0xFF); it would look much nicer with UFCS: window.mainWidget

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Jay via Digitalmars-d-learn
On Sunday, 28 September 2014 at 20:30:42 UTC, Meta wrote: class Button { typeof(this) text(string t) { return this; } typeof(this) textColour(int c) { return this; } } void main() { auto b = new

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Meta via Digitalmars-d-learn
On Sunday, 28 September 2014 at 20:50:07 UTC, Jay wrote: On Sunday, 28 September 2014 at 20:30:42 UTC, Meta wrote: class Button { typeof(this) text(string t) { return this; } typeof(this) textColour(int c) { return

Re: UFCS doesn't work in some cases

2014-09-10 Thread Danyal Zia via Digitalmars-d-learn
On Tuesday, 9 September 2014 at 18:46:31 UTC, ketmar via Digitalmars-d-learn wrote: UFCS is not working for nested functions. this is not a bug, it was designed this way. the same for 'with', i believe. Apparently it is a bug that UFCS doesn't work with 'with' statement. https

Re: UFCS doesn't work in some cases

2014-09-10 Thread ketmar via Digitalmars-d-learn
On Wed, 10 Sep 2014 13:58:18 + Danyal Zia via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Apparently it is a bug that UFCS doesn't work with 'with' statement. my fault, i thought that it shouldn't. i'm still not Guru. too bad, will work. ;-) signature.asc Description

UFCS doesn't work in some cases

2014-09-09 Thread Danyal Zia via Digitalmars-d-learn
Hi, I don't know if this has been mentioned before, but I found two strange cases where UFCS doesn't work. Case # 1: When the functions for UFCS are defined inside main scope class Rect { int x = 20; int y = 20; } void main() { import std.stdio : writeln; int area

Re: UFCS doesn't work in some cases

2014-09-09 Thread ketmar via Digitalmars-d-learn
On Tue, 09 Sep 2014 17:58:14 + Danyal Zia via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Case # 1: When the functions for UFCS are defined inside main scope UFCS is not working for nested functions. this is not a bug, it was designed this way. the same for 'with', i

Re: UFCS doesn't work in some cases

2014-09-09 Thread Mathias LANG via Digitalmars-d-learn
On Tuesday, 9 September 2014 at 17:58:16 UTC, Danyal Zia wrote: As far as I know, UFCS are designed to make it easy to extend the class for specific applications, however, without the ability to use UFCS for those cases, it limits its usefulness. Are these oversights/bugs? Or is their any

Re: struct, ref in, and UFCS

2014-07-01 Thread bearophile via Digitalmars-d-learn
Puming: is this a good practice to use `ref in` with structs instead of traditional pointer syntax (which does not play well with UFCS though) ? Is there any perfomance implications with `ref in`? I tried that it does not seem to copy the parameter value, A ref is equivalent to a pointer

Re: struct, ref in, and UFCS

2014-07-01 Thread Puming via Digitalmars-d-learn
On Tuesday, 1 July 2014 at 07:53:27 UTC, bearophile wrote: Puming: is this a good practice to use `ref in` with structs instead of traditional pointer syntax (which does not play well with UFCS though) ? Is there any perfomance implications with `ref in`? I tried that it does not seem

Re: struct, ref in, and UFCS

2014-07-01 Thread Ali Çehreli via Digitalmars-d-learn
On 07/01/2014 03:21 AM, Puming wrote: I can safely assume ref is better than pointer here I agree. because it plays nicely with UFCS. I don't understand that part. :) The following is the same program with just two differences: prompt() takes a pointer and 'server' is a pointer. import

Re: struct, ref in, and UFCS

2014-07-01 Thread Puming via Digitalmars-d-learn
On Tuesday, 1 July 2014 at 13:53:12 UTC, Ali Çehreli wrote: On 07/01/2014 03:21 AM, Puming wrote: I can safely assume ref is better than pointer here I agree. because it plays nicely with UFCS. I don't understand that part. :) The following is the same program with just two differences

struct, ref in, and UFCS

2014-06-30 Thread Puming via Digitalmars-d-learn
: ```d string p = server.prompt; ``` is this the correct way to use struct and UFCS? it does not seem to copy there.

Re: struct, ref in, and UFCS

2014-06-30 Thread Puming via Digitalmars-d-learn
~ @ ~ server.ip ~ : ~ server.port; } ``` should be `server.port.to!int`; and call it with UFSC: ```d string p = server.prompt; ``` is this the correct way to use struct and UFCS? it does not seem to copy there.

Re: struct, ref in, and UFCS

2014-06-30 Thread Ali Çehreli via Digitalmars-d-learn
(ref in Server server) { return server.user ~ @ ~ server.ip ~ : ~ server.port; } ``` should be `server.port.to!int`; I think it should actually be server.port.to!string; is this the correct way to use struct and UFCS? it does not seem to copy there. I don't understand your question but I

Re: struct, ref in, and UFCS

2014-06-30 Thread Puming via Digitalmars-d-learn
user; } ``` extension method here: ```d string prompt(ref in Server server) { return server.user ~ @ ~ server.ip ~ : ~ server.port; } ``` should be `server.port.to!int`; I think it should actually be server.port.to!string; is this the correct way to use struct and UFCS? it does

Re: UFCS with constructors

2013-11-07 Thread bearophile
qznc: Operator precedence of . is higher than unary minus. You are right, I didn't know it, so Typedef and constructors are not to blame: double foo(in double x) { assert (x = 0); return x; } void main() { assert(-1.foo == -1); } Is this a good design of the operator

UFCS with constructors

2013-11-06 Thread bearophile
import std.typecons: Typedef; alias Foo = Typedef!double; void main() { auto a1 = Foo(1); pragma(msg, typeof(a1)); auto a2 = 1.Foo; pragma(msg, typeof(a2)); auto a3 = Foo(-1); pragma(msg, typeof(a3)); auto a4 = -1.Foo; pragma(msg, typeof(a4)); } It prints:

Re: UFCS with constructors

2013-11-06 Thread qznc
On Wednesday, 6 November 2013 at 11:04:05 UTC, bearophile wrote: import std.typecons: Typedef; alias Foo = Typedef!double; void main() { auto a1 = Foo(1); pragma(msg, typeof(a1)); auto a2 = 1.Foo; pragma(msg, typeof(a2)); auto a3 = Foo(-1); pragma(msg, typeof(a3));

Re: UFCS with constructors

2013-11-06 Thread bearophile
qznc: Operator precedence of . is higher than unary minus. Is this good? However, what is Typedef for? It's to create a differently named type, useful for stronger static typing, to increase code clarity and avoid some bugs. If you have a function like this: double foo(in double x,

Re: UFCS with constructors

2013-11-06 Thread Ali Çehreli
On 11/06/2013 03:04 AM, bearophile wrote: import std.typecons: Typedef; alias Foo = Typedef!double; void main() { auto a1 = Foo(1); pragma(msg, typeof(a1)); auto a2 = 1.Foo; pragma(msg, typeof(a2)); auto a3 = Foo(-1); pragma(msg, typeof(a3)); auto a4 = -1.Foo;

Re: UFCS with constructors

2013-11-06 Thread Maxim Fomin
On Wednesday, 6 November 2013 at 17:10:34 UTC, Ali Çehreli wrote: I would be very surprised if unary - produced a different type from the operand: Ali Operator does not produce type, it produces value of expression, and type of expression happens not to be the type you expected. But such

Re: UFCS with constructors

2013-11-06 Thread Ali Çehreli
On 11/06/2013 09:46 AM, Maxim Fomin wrote: On Wednesday, 6 November 2013 at 17:10:34 UTC, Ali Çehreli wrote: I would be very surprised if unary - produced a different type from the operand: Ali Operator does not produce type, it produces value of expression, and type of expression

Re: UFCS with constructors

2013-11-06 Thread Maxim Fomin
On Wednesday, 6 November 2013 at 18:02:32 UTC, Ali Çehreli wrote: But such expectations need not correspond to language rules (try to think from from language laywer perspective). I still argue that the expression -expr must have the same type as expr. In bearophile case, I guess

Re: UFCS with constructors

2013-11-06 Thread Dicebot
On Wednesday, 6 November 2013 at 18:16:04 UTC, Maxim Fomin wrote: I think that reason for such behavior is the way used defined operator overloading functions are implemented, not the language per se, so programmers confuse themselves. What about other possible reason - Typedef implementation

Re: UFCS with constructors

2013-11-06 Thread bearophile
Dicebot: Typedef implementation sucks? ;) So do you suggest to open some enhancement request/bug report on Typedef? Bye, bearophile

Re: UFCS with constructors

2013-11-06 Thread Dicebot
On Wednesday, 6 November 2013 at 21:57:47 UTC, bearophile wrote: Dicebot: Typedef implementation sucks? ;) So do you suggest to open some enhancement request/bug report on Typedef? Bye, bearophile Sure. get enough such reports and we may even get it back as language feature :) (I think

UFCS and error messages

2013-10-31 Thread Andrea Fontana
Check this simple code: import std.stdio; import std.conv; bool is_zero(T)(T i) { return to!int(i) == 0; } void main() { 0.is_zero.writeln; } This code print true of course. If you replace to!int(i) == 0 with i == 0 compiler gives this error: Error: no property 'is_zero' for type 'string'

Re: UFCS and error messages

2013-10-31 Thread bearophile
Andrea Fontana: Shoudn't 0.is_zero give this error too? Possibly yes. I put this enhancement request in Bugzilla few months ago, but I don't remember its number now. Bye, bearophile

Re: UFCS and error messages

2013-10-31 Thread Marco Leise
Am Thu, 31 Oct 2013 11:58:18 +0100 schrieb Andrea Fontana nos...@example.com: Check this simple code: import std.stdio; import std.conv; bool is_zero(T)(T i) { return to!int(i) == 0; } void main() { 0.is_zero.writeln; } This code print true of course. If you replace to!int(i) ==

Re: UFCS from within classes

2013-09-10 Thread Jacob Carlborg
On 2013-09-09 19:15, H. S. Teoh wrote: I don't think UFCS works with qualified names right now. This is a known issue. As far as I know it's a design decision. -- /Jacob Carlborg

Re: UFCS from within classes

2013-09-09 Thread H. S. Teoh
On Mon, Sep 09, 2013 at 07:07:58PM +0200, Gyron wrote: Hey there, I've experimented a little with UFCS today and ran into a problem. My first question, which is kinda off-topic: Why does D use the int type if you give it a number started with 0x(hex), shouldn't it use uint for that ? Good

UFCS from within classes

2013-09-09 Thread Gyron
Hey there, I've experimented a little with UFCS today and ran into a problem. My first question, which is kinda off-topic: Why does D use the int type if you give it a number started with 0x(hex), shouldn't it use uint for that ? Here comes the real question: I've extended the int by one

Re: UFCS from within classes

2013-09-09 Thread Gyron
On Monday, 9 September 2013 at 17:17:07 UTC, H. S. Teoh wrote: On Mon, Sep 09, 2013 at 07:07:58PM +0200, Gyron wrote: Hey there, I've experimented a little with UFCS today and ran into a problem. My first question, which is kinda off-topic: Why does D use the int type if you give it a number

Re: UFCS from within classes

2013-09-09 Thread Maxim Fomin
On Monday, 9 September 2013 at 17:07:59 UTC, Gyron wrote: Hey there, I've experimented a little with UFCS today and ran into a problem. My first question, which is kinda off-topic: Why does D use the int type if you give it a number started with 0x(hex), shouldn't it use uint

Re: UFCS in template function

2013-08-30 Thread Jacob Carlborg
On 2013-08-29 22:02, Andrej Mitrovic wrote: However it does work for local imports (I think this was new in 2.063): void main() { import std.range; assert([].empty); // ok } empty is declared at module scope. -- /Jacob Carlborg

Re: Checking if UFCS function exists for a specific type

2013-08-30 Thread Rory McGuire
On Thursday, 29 August 2013 at 21:10:41 UTC, Rory McGuire wrote: On Thursday, 29 August 2013 at 21:06:04 UTC, Rory McGuire wrote: Hi all, I've got this little ctfe template function that checks if a function called member with first argument T exists. Its for checking if a type has a custom

Re: UFCS in template function

2013-08-29 Thread Jacob Carlborg
On 2013-08-28 23:28, ixid wrote: UFCS does not work in this template where the normal function call syntax will work: template test(alias fun) { auto test(T)(T n) { return n.fun; } } Is this the same as the inability to use UFCS with functions declared in the same scope

Re: UFCS in template function

2013-08-29 Thread ixid
On Thursday, 29 August 2013 at 06:23:32 UTC, Jacob Carlborg wrote: UFCS only works for module level functions. What is the reason for this limitation?

Re: UFCS in template function

2013-08-29 Thread Andrej Mitrovic
On 8/29/13, Jacob Carlborg d...@me.com wrote: UFCS only works for module level functions. However it does work for local imports (I think this was new in 2.063): void main() { import std.range; assert([].empty); // ok }

Checking if UFCS function exists for a specific type

2013-08-29 Thread Rory McGuire
Hi all, I've got this little ctfe template function that checks if a function called member with first argument T exists. Its for checking if a type has a custom encoder. bool hasUFCSmember(T, string member)() { T v; // would be nice if we could use ParameterTypeTuple to get the

Re: Checking if UFCS function exists for a specific type

2013-08-29 Thread Rory McGuire
On Thursday, 29 August 2013 at 21:06:04 UTC, Rory McGuire wrote: Hi all, I've got this little ctfe template function that checks if a function called member with first argument T exists. Its for checking if a type has a custom encoder. bool hasUFCSmember(T, string member)() { T v;

UFCS in template function

2013-08-28 Thread ixid
UFCS does not work in this template where the normal function call syntax will work: template test(alias fun) { auto test(T)(T n) { return n.fun; } } Is this the same as the inability to use UFCS with functions declared in the same scope as the call

UFCS and function scope

2013-08-15 Thread ixid
Why does UFCS seem to require that functions be defined in a higher (global being the highest) scope than themselves while the normal function syntax works fine? This is OK: int fun1(int n) { return n + 1; } int fun2(int n) { return n.fun1; } This is also OK: int fun3(int n

Re: UFCS and function scope

2013-08-15 Thread bearophile
ixid: This is not OK: int fun5(int n) { int fun6(int n) { return n + 1; } return n.fun6; } Unfortunately this is by design, and at the moment it's unlikely to change. And I think it's done this way to avoid troubles with code in class methods. Bye,

Re: opDispatch and UFCS

2013-07-02 Thread Artur Skawina
a template } Should the constraint on opDispatch allow the UFCS to call on S? To avoid this kind of issues: struct S { template opDispatch(string s) if (s.startsWith(foo)) { void opDispatch(T...)(T t) { writeln(s); } } } And, yes, the compiler

Re: opDispatch and UFCS

2013-07-02 Thread cal
On Tuesday, 2 July 2013 at 11:04:20 UTC, Artur Skawina wrote: To avoid this kind of issues: struct S { template opDispatch(string s) if (s.startsWith(foo)) { void opDispatch(T...)(T t) { writeln(s); } } } That's a handy workaround,

Re: opDispatch and UFCS

2013-07-02 Thread Kenji Hara
!(to) isn't a template } Should the constraint on opDispatch allow the UFCS to call on S? That's a compiler bug. http://d.puremagic.com/issues/show_bug.cgi?id=10526 Kenji Hara

opDispatch and UFCS

2013-07-01 Thread cal
on opDispatch allow the UFCS to call on S?

UFCS and with statement

2013-06-12 Thread Rob T
struct S { } void f(S) { } void main() { S s; with (s) { f(); // compiler error } } Rather disappointing that this fails. Anyone know if this is an expected limitation of UFCS or a bug? --rt

Re: UFCS and with statement

2013-06-12 Thread bearophile
Rob T: Rather disappointing that this fails. Anyone know if this is an expected limitation of UFCS or a bug? Probably no one thought on this case. Why do you think it's useful? Bye, bearophile

Re: UFCS and with statement

2013-06-12 Thread Rob T
On Wednesday, 12 June 2013 at 11:05:22 UTC, bearophile wrote: Rob T: Rather disappointing that this fails. Anyone know if this is an expected limitation of UFCS or a bug? Probably no one thought on this case. Why do you think it's useful? Bye, bearophile If we're to use UFCS as a means

Re: best way to handle UFCS with ambiguous names: using std.typetuple.Alias!

2013-06-11 Thread timotheecour
On Monday, 10 June 2013 at 08:13:42 UTC, John Colvin wrote: On Monday, 10 June 2013 at 02:02:09 UTC, Timothee Cour wrote: UFCS chains are problematic when a symbol is ambiguous (eg after import std.stdio:write;import std.file:write); I previously suggested to add the syntax 'arg1

Re: best way to handle UFCS with ambiguous names: using std.typetuple.Alias!

2013-06-11 Thread Jakob Ovrum
. * systematic way to handle the such cases, whereas renamed local imports require to 'guess' a good name, eg import std.file:write2=write; Do you guess identifier names when you introduce other symbols, too? * renamed local imports require 1 import declaration syntax per ambiguous UFCS

Re: best way to handle UFCS with ambiguous names: using std.typetuple.Alias!

2013-06-11 Thread John Colvin
On Tuesday, 11 June 2013 at 18:47:08 UTC, timotheecour wrote: On Monday, 10 June 2013 at 08:13:42 UTC, John Colvin wrote: On Monday, 10 June 2013 at 02:02:09 UTC, Timothee Cour wrote: UFCS chains are problematic when a symbol is ambiguous (eg after import std.stdio:write;import std.file:write

Re: best way to handle UFCS with ambiguous names: using std.typetuple.Alias!

2013-06-11 Thread ixid
On Monday, 10 June 2013 at 02:02:09 UTC, Timothee Cour wrote: UFCS chains are problematic when a symbol is ambiguous (eg after import std.stdio:write;import std.file:write); I previously suggested to add the syntax 'arg1.(std.file.write)(arg2)' (see 'support UFCS with fully qualified function

best way to handle UFCS with ambiguous names: using std.typetuple.Alias!

2013-06-09 Thread Timothee Cour
UFCS chains are problematic when a symbol is ambiguous (eg after import std.stdio:write;import std.file:write); I previously suggested to add the syntax 'arg1.(std.file.write)(arg2)' (see 'support UFCS with fully qualified function names (was in digitalmars.D.learn)' to avoid breaking UFCS

Re: UFCS for classes with opCall( ... )

2013-06-05 Thread ParticlePeter
http://dpaste.dzfl.pl/79c29c19 (What you want to do does not work, but the issue is not that UFCS does not work with opCall. It does.) Thanks for the insights, undfortunatelly you're right. Is this behaviour on purpose, or considered a bug ? Couldn't read that much out of the original

Re: UFCS for classes with opCall( ... )

2013-06-05 Thread Timon Gehr
On 06/05/2013 05:11 PM, ParticlePeter wrote: http://dpaste.dzfl.pl/79c29c19 (What you want to do does not work, but the issue is not that UFCS does not work with opCall. It does.) Thanks for the insights, undfortunatelly you're right. Is this behaviour on purpose, or considered a bug

Re: UFCS for classes with opCall( ... )

2013-06-03 Thread ParticlePeter
UFCS is working with opCall already. The reason your code does not work is that UFCS only works with module-level symbols (and with the latest release also for locally imported symbols IIRC.) What do you mean with locally import symbols, isn't that the normal import statement ? Could you

Re: UFCS for classes with opCall( ... )

2013-06-03 Thread Timon Gehr
On 06/03/2013 06:25 PM, ParticlePeter wrote: UFCS is working with opCall already. The reason your code does not work is that UFCS only works with module-level symbols (and with the latest release also for locally imported symbols IIRC.) What do you mean with locally import symbols, isn't

Re: UFCS for classes with opCall( ... )

2013-06-02 Thread Ali Çehreli
On 06/01/2013 05:22 AM, ParticlePeter wrote: 3. If not 1. Would this be a valid feature requst ? Looks like this request: http://d.puremagic.com/issues/show_bug.cgi?id=9857 Ali

UFCS for classes with opCall( ... )

2013-06-01 Thread ParticlePeter
Hello, after watching Walters Talk about Component Programming ( link Bellow ) I was quite fond of his pipelining approach. I tried the following and had to realize that this way using UFCS isn't working ( or I do something wrong ). // I want to write On Canvas1 | draw Shape1 | draw Shape2

support UFCS with fully qualified function names

2013-05-20 Thread Timothee Cour
I'd like to be able to use UFCS with fully qualified function names. A typical use case is to disambiguate , as in the following case: import std.path; import std.string; void main(){ //Error: std.path.join()(const(char)[] p1, const(char)[] p2, const(char[ ])[] more...) at ... conflicts

Re: support UFCS with fully qualified function names

2013-05-20 Thread bearophile
Timothee Cour: I'd like to be able to use UFCS with fully qualified function names. auto a=.(std.path.join)(\n); It seems an acceptably-looking syntax. But maybe D.learn is not the best place to discuss new D syntax. Regarding new UFCS-related syntax, I sometimes wish for: alias T

Re: support UFCS with fully qualified function names

2013-05-20 Thread bearophile
Timothee Cour: auto a=.(std.path.join)(\n); I suggest to present it in the main D newsgroup. And if people don't hate it, to later write an enhancement request in bugzilla. Bye, bearophile

Re: writeln, UFCS and flip

2013-04-26 Thread bearophile
Timon Gehr: I think what you call flip2 should be called flip. Why? Bye, bearophile

Re: writeln, UFCS and flip

2013-04-26 Thread ixid
On Friday, 26 April 2013 at 10:52:09 UTC, bearophile wrote: Timon Gehr: I think what you call flip2 should be called flip. Why? Bye, bearophile flip2 is the more general and useful function with new functionality so there's no need for what was flip and we should call the new function

Re: writeln, UFCS and flip

2013-04-26 Thread bearophile
ixid: flip2 is the more general and useful function with new functionality so there's no need for what was flip and we should call the new function 'flip'. I don't agree. Maybe you are missing something. I expect a function named flip to do: flip!foo(a, b, c) === foo(c, b, a) flip!foo(a,

Re: writeln, UFCS and flip

2013-04-26 Thread Tyro[17]
On 4/26/13 8:59 AM, bearophile wrote: ixid: flip2 is the more general and useful function with new functionality so there's no need for what was flip and we should call the new function 'flip'. I don't agree. Maybe you are missing something. I expect a function named flip to do:

Re: writeln, UFCS and flip

2013-04-26 Thread bearophile
Tyro[17]: While flip2 does: flip2!foo(a, b, c) === foo(b, a, c) flip2!foo(a, b, c, d) === foo(b, a, c, d) and this rotate Really? Just swapping the first two arguments and leaving the others at their place is for a rotate? Why flip in the first place? I don't know, it's the

Re: writeln, UFCS and flip

2013-04-26 Thread Timon Gehr
On 04/26/2013 10:15 PM, bearophile wrote: Tyro[17]: While flip2 does: flip2!foo(a, b, c) === foo(b, a, c) flip2!foo(a, b, c, d) === foo(b, a, c, d) and this rotate Really? Just swapping the first two arguments and leaving the others at their place is for a rotate? Why flip in the

<    1   2   3   4   5   >