Re: Scope of temporaries as function arguments

2013-06-28 Thread Nick Sabalausky
On Fri, 28 Jun 2013 07:11:05 +0200 Maxim Fomin ma...@maxim-fomin.ru wrote: On Friday, 28 June 2013 at 04:54:56 UTC, Nick Sabalausky wrote: Probably a silly question, but I wanted to double-check... If you have this: struct Foo {...} bar(Foo()); Then regardless of

Re: Scope of temporaries as function arguments

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 06:15:26 UTC, Nick Sabalausky wrote: On Fri, 28 Jun 2013 07:11:05 +0200 Maxim Fomin ma...@maxim-fomin.ru wrote: On Friday, 28 June 2013 at 04:54:56 UTC, Nick Sabalausky wrote: Probably a silly question, but I wanted to double-check... If you have this:

Re: Opaque structs

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 02:17:06 UTC, Brad Anderson wrote: On Friday, 28 June 2013 at 01:40:44 UTC, Andrej Mitrovic wrote: Note that if we implement Issue 8728[1], we could even create a better error message via: - struct S { @disable(S is an opaque C type and must only be used as a

Get body of a function as string

2013-06-28 Thread John Colvin
Is there any way of getting the body of a function as a string? (Obviously only when the source code is available to the compiler)

Re: Scope of temporaries as function arguments

2013-06-28 Thread Marco Leise
Am Fri, 28 Jun 2013 02:15:19 -0400 schrieb Nick Sabalausky seewebsitetocontac...@semitwist.com: BTW, for anyone else reading, I just searched bugzilla and it looks like the relevant issue is #9704. Reminds me of an issue I reported later: http://d.puremagic.com/issues/show_bug.cgi?id=10409 --

zip vs. lockstep -- problem when setting values

2013-06-28 Thread Joseph Rushton Wakeling
Consider the following equivalent code using zip and lockstep respectively to iterate over the entries in an array and set their values: auto arr1 = new double[10]; foreach(i, ref x; zip(iota(10), arr1)) { x = i; } writeln(arr1); auto arr2 = new double[10];

Re: Get body of a function as string

2013-06-28 Thread bearophile
John Colvin: Is there any way of getting the body of a function as a string? (Obviously only when the source code is available to the compiler) I think that currently there isn't a simple way to do it. What is your use case? Bye, bearophile

Re: Get body of a function as string

2013-06-28 Thread John Colvin
On Friday, 28 June 2013 at 13:18:39 UTC, bearophile wrote: John Colvin: Is there any way of getting the body of a function as a string? (Obviously only when the source code is available to the compiler) I think that currently there isn't a simple way to do it. What is your use case? Bye,

Re: Get body of a function as string

2013-06-28 Thread Namespace
And why don't you call the function from your clone function? Maybe this could help you: http://dpaste.1azy.net/fork/597affd2 I used it to generate my own rvalue functions because of the lack of rvalue references.

sort error

2013-06-28 Thread snow
Hello there, Ive got the following code http://dpaste.dzfl.pl/e391a268 This code throws me a Range Exception in Algorithm.d. If I use a lower number of random vectors, like 100, the code terminates. Also, if I delete the template instruction like this : sort(individuals); I also don't get

Re: Scope of temporaries as function arguments

2013-06-28 Thread Maxim Fomin
On Friday, 28 June 2013 at 08:08:17 UTC, monarch_dodra wrote: Just in case it wasn't clear from the original explanation, this is a bug, it *should* be perfectly safe to pass as many temps as you want, and expect the right amount of destructor called in case of a throw. Original

Re: Scope of temporaries as function arguments

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 14:26:04 UTC, Maxim Fomin wrote: On Friday, 28 June 2013 at 08:08:17 UTC, monarch_dodra wrote: Just in case it wasn't clear from the original explanation, this is a bug, it *should* be perfectly safe to pass as many temps as you want, and expect the right amount of

Re: sort error

2013-06-28 Thread bearophile
snow: http://dpaste.dzfl.pl/e391a268 This code throws me a Range Exception in Algorithm.d. If I use a lower number of random vectors, like 100, the code terminates. Also, if I delete the template instruction like this : sort(individuals); I also don't get an exception. Does anybody know,

Re: Scope of temporaries as function arguments

2013-06-28 Thread Maxim Fomin
On Friday, 28 June 2013 at 15:17:12 UTC, monarch_dodra wrote: Should I have expected a different behavior? import std.stdio; int callme() { throw new Exception(); } struct S { int i = 0; this(int i){this.i = i; writeln(constructing: , i);} this(this){writeln(postbliting: ,

counting words

2013-06-28 Thread Benjamin Thaut
I'm currently making a few tests with std.algorithm, std.range, etc I have a arry of words. Is it possible to count how often each word is contained in the array and then sort the array by the count of the individual words by chaining ranges? (e.g. without using a foreach loop + hashmap)?

Re: Scope of temporaries as function arguments

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 15:33:40 UTC, Maxim Fomin wrote: On Friday, 28 June 2013 at 15:17:12 UTC, monarch_dodra wrote: Should I have expected a different behavior? import std.stdio; int callme() { throw new Exception(); } struct S { int i = 0; this(int i){this.i = i;

Re: counting words

2013-06-28 Thread Brad Anderson
On Friday, 28 June 2013 at 16:04:35 UTC, Benjamin Thaut wrote: I'm currently making a few tests with std.algorithm, std.range, etc I have a arry of words. Is it possible to count how often each word is contained in the array and then sort the array by the count of the individual words by

Re: counting words

2013-06-28 Thread Brad Anderson
On Friday, 28 June 2013 at 16:25:25 UTC, Brad Anderson wrote: On Friday, 28 June 2013 at 16:04:35 UTC, Benjamin Thaut wrote: I'm currently making a few tests with std.algorithm, std.range, etc I have a arry of words. Is it possible to count how often each word is contained in the array and

Re: Scope of temporaries as function arguments

2013-06-28 Thread Ali Çehreli
On 06/28/2013 09:01 AM, monarch_dodra wrote: And I'm 99% sure C++ doesn't have this problem... +1%. :) I just finished checking. No, C++ does not have this problem. But there is the following related issue, which every real C++ programmer should know. ;)

Re: counting words

2013-06-28 Thread Benjamin Thaut
Am 28.06.2013 18:42, schrieb Brad Anderson: On Friday, 28 June 2013 at 16:25:25 UTC, Brad Anderson wrote: On Friday, 28 June 2013 at 16:04:35 UTC, Benjamin Thaut wrote: I'm currently making a few tests with std.algorithm, std.range, etc I have a arry of words. Is it possible to count how

Re: counting words

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 16:25:25 UTC, Brad Anderson wrote: On Friday, 28 June 2013 at 16:04:35 UTC, Benjamin Thaut wrote: I'm currently making a few tests with std.algorithm, std.range, etc I have a arry of words. Is it possible to count how often each word is contained in the array and

Re: Scope of temporaries as function arguments

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 16:50:07 UTC, Maxim Fomin wrote: On Friday, 28 June 2013 at 16:01:05 UTC, monarch_dodra wrote: I thought that was where you were getting to. Couldn't this simply be solved by having the *caller*, destroy the object that was postblitted into foo? Since foo ends up

Re: counting words

2013-06-28 Thread Brad Anderson
On Friday, 28 June 2013 at 16:48:08 UTC, Benjamin Thaut wrote: Am 28.06.2013 18:42, schrieb Brad Anderson: On Friday, 28 June 2013 at 16:25:25 UTC, Brad Anderson wrote: On Friday, 28 June 2013 at 16:04:35 UTC, Benjamin Thaut wrote: I'm currently making a few tests with std.algorithm,

Re: Scope of temporaries as function arguments

2013-06-28 Thread Maxim Fomin
On Friday, 28 June 2013 at 16:01:05 UTC, monarch_dodra wrote: I thought that was where you were getting to. Couldn't this simply be solved by having the *caller*, destroy the object that was postblitted into foo? Since foo ends up not being called (because of the exception), then I see no

Re: sort error

2013-06-28 Thread Ali Çehreli
On 06/28/2013 07:00 AM, snow wrote: Hello there, Ive got the following code http://dpaste.dzfl.pl/e391a268 This code throws me a Range Exception in Algorithm.d. If I use a lower number of random vectors, like 100, the code terminates. Also, if I delete the template instruction like this :

Re: Scope of temporaries as function arguments

2013-06-28 Thread Steven Schveighoffer
On Fri, 28 Jun 2013 12:44:02 -0400, Ali Çehreli acehr...@yahoo.com wrote: I just finished checking. No, C++ does not have this problem. But there is the following related issue, which every real C++ programmer should know. ;)

Re: Scope of temporaries as function arguments

2013-06-28 Thread Maxim Fomin
On Friday, 28 June 2013 at 16:44:03 UTC, Ali Çehreli wrote: Ali P.S. The C++ program that I have just used for testing: Are you sure that the code is exact translation of demonstrated D problem? I see difference in argument passing order and your version uses try-catch block. This code

Re: counting words

2013-06-28 Thread Benjamin Thaut
Am 28.06.2013 19:01, schrieb Brad Anderson: On Friday, 28 June 2013 at 16:48:08 UTC, Benjamin Thaut wrote: Am 28.06.2013 18:42, schrieb Brad Anderson: On Friday, 28 June 2013 at 16:25:25 UTC, Brad Anderson wrote: On Friday, 28 June 2013 at 16:04:35 UTC, Benjamin Thaut wrote: I'm currently

Re: Scope of temporaries as function arguments

2013-06-28 Thread Ali Çehreli
On 06/28/2013 10:11 AM, Steven Schveighoffer wrote: On Fri, 28 Jun 2013 12:44:02 -0400, Ali Çehreli acehr...@yahoo.com wrote: http://www.boost.org/doc/libs/1_53_0/libs/smart_ptr/shared_ptr.htm#BestPractices Thank you, I didn't know this. Even though this issue is covered in Herb

Re: Scope of temporaries as function arguments

2013-06-28 Thread Ali Çehreli
On 06/28/2013 10:17 AM, Maxim Fomin wrote: Are you sure that the code is exact translation of demonstrated D problem? Sorry. I omitted two points. I see difference in argument passing order and your version uses try-catch block. 1) C++ does not specify whether the stack gets unwound when

Re: Scope of temporaries as function arguments

2013-06-28 Thread Maxim Fomin
On Friday, 28 June 2013 at 16:57:29 UTC, monarch_dodra wrote: On Friday, 28 June 2013 at 16:50:07 UTC, Maxim Fomin wrote: On Friday, 28 June 2013 at 16:01:05 UTC, monarch_dodra wrote: I thought that was where you were getting to. Couldn't this simply be solved by having the *caller*, destroy

Re: Scope of temporaries as function arguments

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 17:30:58 UTC, Ali Çehreli wrote: On 06/28/2013 10:17 AM, Maxim Fomin wrote: Are you sure that the code is exact translation of demonstrated D problem? Sorry. I omitted two points. I see difference in argument passing order and your version uses try-catch block.

Re: counting words

2013-06-28 Thread bearophile
monarch_dodra: Well, I've had a PR open for this for about 8 months now... Do you have Phobos commit rights? If the answer is positive then perhaps you can review and commit some Phobos code written by Andrei and he can do the same with yours. Today it seems the major development bottleneck

Re: Scope of temporaries as function arguments

2013-06-28 Thread Ali Çehreli
On 06/28/2013 10:53 AM, monarch_dodra wrote: On Friday, 28 June 2013 at 17:30:58 UTC, Ali Çehreli wrote: 1) C++ does not specify whether the stack gets unwound when the program terminates with an uncaught exception. That's why I caught to ensure that the stack objects would be destroyed.

[Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread MattCoder
Hi, I would like to know if it's possible to pass the return of a function as argument to another function as below: import std.stdio; auto foo(int x, int y){ writeln(x, y); return 3, 4; } void main(){ foo(foo(1,2)); } I would like to print: 1 2 3 4 PS: I tried

Re: Opaque structs

2013-06-28 Thread Andrej Mitrovic
On 6/28/13, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Unfortunately this tends to spawn unreadable error messages: It looks like there's also a blocking bug: http://d.puremagic.com/issues/show_bug.cgi?id=10497 So I'll have to use my new technique instead anyway. :p

Re: counting words

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 17:59:58 UTC, bearophile wrote: monarch_dodra: Well, I've had a PR open for this for about 8 months now... Do you have Phobos commit rights? If the answer is positive then perhaps you can review and commit some Phobos code written by Andrei and he can do the same

Re: counting words

2013-06-28 Thread Brad Anderson
On Friday, 28 June 2013 at 18:53:44 UTC, monarch_dodra wrote: On Friday, 28 June 2013 at 17:59:58 UTC, bearophile wrote: monarch_dodra: Well, I've had a PR open for this for about 8 months now... Do you have Phobos commit rights? If the answer is positive then perhaps you can review and

Re: counting words

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 19:13:28 UTC, Brad Anderson wrote: On Friday, 28 June 2013 at 18:53:44 UTC, monarch_dodra wrote: On Friday, 28 June 2013 at 17:59:58 UTC, bearophile wrote: monarch_dodra: Well, I've had a PR open for this for about 8 months now... Do you have Phobos commit

Re: [Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread Ellery Newcomer
On 06/28/2013 11:07 AM, MattCoder wrote: Hi, I would like to know if it's possible to pass the return of a function as argument to another function as below: import std.stdio; auto foo(int x, int y){ writeln(x, y); return 3, 4; } void main(){ foo(foo(1,2)); } I would like to

Re: [Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread Simen Kjaeraas
On Fri, 28 Jun 2013 20:07:23 +0200, MattCoder mattco...@hotmail.com wrote: Hi, I would like to know if it's possible to pass the return of a function as argument to another function as below: import std.stdio; auto foo(int x, int y){ writeln(x, y); return 3, 4; } void

Re: counting words

2013-06-28 Thread Brad Anderson
On Friday, 28 June 2013 at 19:31:22 UTC, monarch_dodra wrote: On Friday, 28 June 2013 at 19:13:28 UTC, Brad Anderson wrote: 95 merged phobos pull requests (109 total). Long overdue, I'd say. I don't know if there is really a formal process to getting write privileges but if any of the

Local templates and alias parameters

2013-06-28 Thread John Colvin
void main() { template A(alias a) { enum A = a.stringof; } int b; string s = A!b; // Error: template instance A!(b) cannot use local 'b' as parameter to non-global template A(alias a) } Bug or feature?

Re: [Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread MattCoder
On Friday, 28 June 2013 at 19:39:41 UTC, Ellery Newcomer wrote: However, they can return std.typecons.Tuple, so you could do this: auto foo(int i, int j) { writeln(i, , j); return tuple(3,4); } void main() { foo(foo(1,2).field); } Hi Ellery, Thanks for your help, it works

Re: [Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread MattCoder
On Friday, 28 June 2013 at 19:43:37 UTC, Simen Kjaeraas wrote: import std.stdio; import std.typecons : tuple; auto foo(int x, int y){ writeln(x, y); return tuple(3, 4); } void main(){ foo(foo(1,2).tupleof); } Hi Simen, Thanks for your help too, it worked!

Re: Opaque structs

2013-06-28 Thread Johannes Pfau
Am Fri, 28 Jun 2013 03:40:31 +0200 schrieb Andrej Mitrovic andrej.mitrov...@gmail.com: struct S { @disable(S is an opaque C type and must only be used as a pointer) this(); @disable(S is an opaque C type and must only be used as a pointer) this(this); } A naive question: Why

Re: Opaque structs

2013-06-28 Thread Andrej Mitrovic
On 6/28/13, Johannes Pfau nos...@example.com wrote: A naive question: Why isn't struct S {} enough? This should be a struct with size 0 so why do we need to disable the constructor and postblit explicitly? Because the user should never be able to use such a struct by value, in other words a

Re: Get body of a function as string

2013-06-28 Thread John Colvin
On Friday, 28 June 2013 at 13:55:54 UTC, Namespace wrote: And why don't you call the function from your clone function? Because the body of the new function needs to see the parameters as known at compile-time. Maybe this could help you: http://dpaste.1azy.net/fork/597affd2 I used it to

Re: Get body of a function as string

2013-06-28 Thread bearophile
John Colvin: Because the body of the new function needs to see the parameters as known at compile-time. I think to curry a function all you need to know is its signature. And in std.traits probably there is all the functionality to see all kinds of function arguments, their names, tags,

Re: [Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread David
However, they can return std.typecons.Tuple, so you could do this: auto foo(int i, int j) { writeln(i, , j); return tuple(3,4); } void main() { foo(foo(1,2).field); } field is deprecated in favor of expand

Re: Get body of a function as string

2013-06-28 Thread monarch_dodra
On Friday, 28 June 2013 at 20:50:55 UTC, John Colvin wrote: On Friday, 28 June 2013 at 13:55:54 UTC, Namespace wrote: And why don't you call the function from your clone function? Because the body of the new function needs to see the parameters as known at compile-time. Maybe this could

Re: Local templates and alias parameters

2013-06-28 Thread Ali Çehreli
On 06/28/2013 01:04 PM, John Colvin wrote: void main() { template A(alias a) { enum A = a.stringof; } int b; string s = A!b; // Error: template instance A!(b) cannot use local 'b' as parameter to non-global template A(alias a) } Bug or feature? Popular

Re: Local templates and alias parameters

2013-06-28 Thread John Colvin
On Friday, 28 June 2013 at 23:57:30 UTC, Ali Çehreli wrote: On 06/28/2013 01:04 PM, John Colvin wrote: void main() { template A(alias a) { enum A = a.stringof; } int b; string s = A!b; // Error: template instance A!(b) cannot use local 'b' as parameter to