Re: Idiomatic D?

2014-01-30 Thread Stanislav Blinov
On Friday, 31 January 2014 at 04:53:48 UTC, Matt Soucy wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared ); // Sorry but that was going to cause a slight er

Re: Idiomatic D?

2014-01-30 Thread Kelet
On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote: I hear it thrown around a lot but what does it actually mean? What does the ideal D code look like? What kind of things should some one think about if they are trying to do idiomatic D? Here is one of the few previous threads on

Re: mixin template

2014-01-30 Thread Dan Killebrew
On Friday, 31 January 2014 at 06:24:27 UTC, Dan Killebrew wrote: mixin template Foo(alias a){ alias Foo=a; } pragma(msg, Foo!2); // error template Bar(alias a){ alias Bar=a; } pragma(msg, Bar!2); // ok As far as I can tell, 'mixin template' does nothing new; (besides fail to compile in Timon

Re: mixin template

2014-01-30 Thread Dan Killebrew
mixin template Foo(alias a){ alias Foo=a; } pragma(msg, Foo!2); // error template Bar(alias a){ alias Bar=a; } pragma(msg, Bar!2); // ok Perhaps I was unclear. What I meant: What does 'mixin template' do that 'template' does not? Where would I use 'mixin template'? As far as I can tell, 'mixin

Re: Idiomatic D?

2014-01-30 Thread Matt Soucy
On 01/30/2014 07:17 PM, Stanislav Blinov wrote: On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared ); // S

Re: I don't even..

2014-01-30 Thread Meta
On Friday, 31 January 2014 at 02:37:02 UTC, Mineko wrote: On Friday, 31 January 2014 at 02:26:51 UTC, Adam D. Ruppe wrote: On Friday, 31 January 2014 at 02:15:08 UTC, Mineko wrote: I'm completely lost on this one, here's the error message: I think it is because "shared" is a keyword in D, so

Re: I don't even..

2014-01-30 Thread Mineko
On Friday, 31 January 2014 at 02:26:51 UTC, Adam D. Ruppe wrote: On Friday, 31 January 2014 at 02:15:08 UTC, Mineko wrote: I'm completely lost on this one, here's the error message: I think it is because "shared" is a keyword in D, so your module name module whatever.shared.shared; is trig

Re: I don't even..

2014-01-30 Thread Adam D. Ruppe
On Friday, 31 January 2014 at 02:15:08 UTC, Mineko wrote: I'm completely lost on this one, here's the error message: I think it is because "shared" is a keyword in D, so your module name module whatever.shared.shared; is triggering the problem. If you rename the package and modules from sh

Re: Idiomatic D?

2014-01-30 Thread Meta
On Friday, 31 January 2014 at 00:17:47 UTC, Stanislav Blinov wrote: On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnW

I don't even..

2014-01-30 Thread Mineko
I'm completely lost on this one, here's the error message: Core plugin failed to compile: res/plugins/shared/shared.d(31): Error: Identifier expected following package res/plugins/shared/api.d(31): Error: Identifier expected following package res/plugins/core/settings.d(57): Error: identifier e

Re: How to call opCall as template?

2014-01-30 Thread Stanislav Blinov
Ask yourself this: in regards to overload resolution, when should template instantiation occur?

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
Gah! G'Kar moment... http://dpaste.dzfl.pl/203d237d7413

Re: How to call opCall as template?

2014-01-30 Thread Namespace
On Thursday, 30 January 2014 at 22:34:52 UTC, Frustrated wrote: On Thursday, 30 January 2014 at 21:33:09 UTC, Namespace wrote: I think for your example, the first case works fine using deduction. Sure but this is not always possible. ;) It seems that the problem occurs also with opIndex and s

Re: Idiomatic D?

2014-01-30 Thread Stanislav Blinov
On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared

Re: Idiomatic D?

2014-01-30 Thread Meta
On Friday, 31 January 2014 at 00:09:34 UTC, Stanislav Blinov wrote: On Friday, 31 January 2014 at 00:08:02 UTC, Meta wrote: On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote: Got any tips? Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range

Re: Idiomatic D?

2014-01-30 Thread Meta
On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote: On Thursday, 30 January 2014 at 20:10:01 UTC, Dicebot wrote: On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote: I hear it thrown around a lot but what does it actually mean? What does the ideal D code look like? What k

Re: Idiomatic D?

2014-01-30 Thread Stanislav Blinov
On Friday, 31 January 2014 at 00:08:02 UTC, Meta wrote: On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote: Got any tips? Ranges, templates and structs. ~= CTFE ~ UFCS

Re: Magic infinite loop inside foreach

2014-01-30 Thread Joseph Rushton Wakeling
On 31/01/14 00:08, MrSmith wrote: Somehow if i comment out //matrix = solveTemp(temp); it works, but this method works fine, and after it done1 is printed. Strange. That does rather suggest that it's that method that is causing things to get stuck. Can you share what's inside it? And when yo

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 22:45:45 UTC, bearophile wrote: Since my post someone has added a Fortran version based on the algorithm used in the C++11 code. It's a little faster than the C++11 code and it's much nicer looking: Yup, I saw it. They're cheating, they almost don't have to exp

Re: Magic infinite loop inside foreach

2014-01-30 Thread Ali Çehreli
On 01/30/2014 03:08 PM, MrSmith wrote: > On Thursday, 30 January 2014 at 22:56:46 UTC, MrSmith wrote: >> I have some function which does some matrix calculations and prints >> them. It is actually calculationg determinant of the matrix and i need >> to call those functions several times in the lo

Re: Magic infinite loop inside foreach

2014-01-30 Thread MrSmith
On Thursday, 30 January 2014 at 22:56:46 UTC, MrSmith wrote: I have some function which does some matrix calculations and prints them. It is actually calculationg determinant of the matrix and i need to call those functions several times in the loop, until i get the final result. Here is the co

Magic infinite loop inside foreach

2014-01-30 Thread MrSmith
I have some function which does some matrix calculations and prints them. It is actually calculationg determinant of the matrix and i need to call those functions several times in the loop, until i get the final result. Here is the code. void solveAndPrint(T : CoeffMatrix!(ElementType, Element

Re: N-body bench

2014-01-30 Thread bearophile
Since my post someone has added a Fortran version based on the algorithm used in the C++11 code. It's a little faster than the C++11 code and it's much nicer looking: http://benchmarksgame.alioth.debian.org/u32/program.php?test=nbody&lang=ifc&id=5 pure subroutine advance(tstep, x, v, mass) r

Re: Idiomatic D?

2014-01-30 Thread Tofu Ninja
On Thursday, 30 January 2014 at 20:10:01 UTC, Dicebot wrote: On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote: I hear it thrown around a lot but what does it actually mean? What does the ideal D code look like? What kind of things should some one think about if they are trying to

Re: Interfaces allow member definitions?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 21:42:39 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 16:23:55 -0500, Frustrated wrote: Again, you have to get off of what has been defined. You have the mentality exactly the same as those that thought the earth was flat, imaginary numbers were nonsen

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: An aging i3? My CPU is older, it doesn't support AVX2 and AVX. This is getting a bit silly now. I must have some compile switches for g++ wrong: g++ -Ofast -fkeep-inline-functions -fomit-frame-pointer -march=native -mfpmath=sse -mavx -mssse3 -flto --std=c++11 -fopenmp

Re: How to call opCall as template?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 21:33:09 UTC, Namespace wrote: I think for your example, the first case works fine using deduction. Sure but this is not always possible. ;) It seems that the problem occurs also with opIndex and so probably with all op* methods. See: http://forum.dlang.org/th

Re: Symbol undefined

2014-01-30 Thread Andrej Mitrovic
On 1/30/14, Andrej Mitrovic wrote: > On 1/30/14, Martijn Pot wrote: >> Indeed, making them public solved the problem. Is there more >> stuff in the book that isn't working? > > Check the errata page[1], which coincidentally seems to be down. I'll CC > Andrei. > > [1]: http://erdani.com/tdpl/errat

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 21:54:17 UTC, bearophile wrote: You seem to have a quite recent CPU, An aging i3? as the G++ code contains instructions like vmovsd. So you can try to do the same with ldc2, and use AVX or AVX2. Hmm... This is getting a bit silly now. I must have some comp

Re: Symbol undefined

2014-01-30 Thread Andrej Mitrovic
On 1/30/14, Martijn Pot wrote: > Indeed, making them public solved the problem. Is there more > stuff in the book that isn't working? Check the errata page[1], which coincidentally seems to be down. I'll CC Andrei. [1]: http://erdani.com/tdpl/errata/index.php?title=Main_Page Another more-recent

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: G++: http://codepad.org/oOZQw1VQ LDC: http://codepad.org/5nHoZL1k You seem to have a quite recent CPU, as the G++ code contains instructions like vmovsd. So you can try to do the same with ldc2, and use AVX or AVX2. There are the switches: -march=- Architect

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 21:33:38 UTC, bearophile wrote: If a function takes no time to run, and you tweak it, your program is not supposed to go faster. Right. I was going to compare the asm listings, but C++ seems to have unrolled and inlined the outer loop right inside main(), and

Re: Symbol undefined

2014-01-30 Thread Martijn Pot
On Thursday, 30 January 2014 at 21:33:05 UTC, Andrej Mitrovic wrote: On Thursday, 30 January 2014 at 21:28:08 UTC, Martijn Pot wrote: Error 42: Symbol Undefined _D1a14Transmogrifier12transmogrifyMFZv (void a.Transmogrifier.transmogrify()) Typically that means the function isn't implemented, e

Re: Interfaces allow member definitions?

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 16:23:55 -0500, Frustrated wrote: Again, you have to get off of what has been defined. You have the mentality exactly the same as those that thought the earth was flat, imaginary numbers were nonsense/useless, man couldn't go to the moon. OK, then. With that, I shall retir

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: I meant that if I unroll it, it's not irrelevant anymore :) If a function takes no time to run, and you tweak it, your program is not supposed to go faster. I was going to compare the asm listings, but C++ seems to have unrolled and inlined the outer loop right inside ma

Re: Symbol undefined

2014-01-30 Thread Andrej Mitrovic
On Thursday, 30 January 2014 at 21:28:08 UTC, Martijn Pot wrote: Error 42: Symbol Undefined _D1a14Transmogrifier12transmogrifyMFZv (void a.Transmogrifier.transmogrify()) Typically that means the function isn't implemented, e.g. this: void transmogrify(); instead of this: void transmogrify(

Re: How to call opCall as template?

2014-01-30 Thread Namespace
I think for your example, the first case works fine using deduction. Sure but this is not always possible. ;) It seems that the problem occurs also with opIndex and so probably with all op* methods. See: http://forum.dlang.org/thread/bug-1204...@https.d.puremagic.com%2Fissues%2F#post-lcegar:2

Re: Symbol undefined

2014-01-30 Thread Ali Çehreli
On 01/30/2014 01:28 PM, Martijn Pot wrote: I'm starting to use D out of curiousity. I've used both Eclipse + DDT and Visual Studio + visualD and both give the same error in my second test program (second to Hello World of course...) using the Transmogrifier/CardboardBox example from TDPL : Err

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 21:04:06 UTC, bearophile wrote: Stanislav Blinov: Unrolling everything except the loop in energy() seems to have squeezed the bits neede to outperform c++, at least on my machine :) That should be impossible, as I remember from my old profilings that energy()

Re: Interfaces allow member definitions?

2014-01-30 Thread Frustrated
Simple question. What are the difference between an interface and a class? I'm not talking about what the compiler does with them. I'm talking about what they were created to do, how they came about etc. If you have to explain to someone what a class is and what an interface is, then you diff t

Symbol undefined

2014-01-30 Thread Martijn Pot
I'm starting to use D out of curiousity. I've used both Eclipse + DDT and Visual Studio + visualD and both give the same error in my second test program (second to Hello World of course...) using the Transmogrifier/CardboardBox example from TDPL : Error 42: Symbol Undefined _D1a14Transmogrif

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Jesse Phillips
On Wednesday, 29 January 2014 at 10:55:57 UTC, Cooler wrote: Consider 3 functions taking array as an argument: void fun1(in int[] x){...} void fun2(ref int[] x){...} void fun3(int[] x){...} auto a = new int[10]; fun1(a); // Guaranteed that "a" will not be changed fun2(a); // Guaranteed th

Re: Interfaces allow member definitions?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 21:16:05 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 15:57:06 -0500, Frustrated wrote: On Thursday, 30 January 2014 at 20:17:23 UTC, Steven Schveighoffer wrote: But it's important to note that A does not define an instance of A_vtbl, just the layout!

Re: Interfaces allow member definitions?

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 15:57:06 -0500, Frustrated wrote: On Thursday, 30 January 2014 at 20:17:23 UTC, Steven Schveighoffer wrote: But it's important to note that A does not define an instance of A_vtbl, just the layout! You still need a concrete class to get a vtable instance to point at. B

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: ldc2 -release -O3 -disable-boundscheck -vectorize -vectorize-loops All my versions of ldc2 don't even accept -vectorize :-) ldc2: Unknown command line argument '-vectorize'. Try: 'ldc2 -help' ldc2: Did you mean '-vectorize-slp'? And -vectorize-loops should be active on d

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: Unrolling everything except the loop in energy() seems to have squeezed the bits neede to outperform c++, at least on my machine :) That should be impossible, as I remember from my old profilings that energy() should use only an irrelevant amount of run time. http://dpa

Re: Interfaces allow member definitions?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 20:17:23 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 14:58:42 -0500, Frustrated wrote: On Thursday, 30 January 2014 at 17:11:24 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 11:58:15 -0500, Frustrated wrote: Essentially what it boils down

Re: How to call opCall as template?

2014-01-30 Thread Frustrated
import std.stdio; struct B { template opCall(T) { void opCall(T x) { writeln(x); } } } template a(T) { } void main() { B a; a(3); // works because template parameter can be

Re: Interfaces allow member definitions?

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 14:58:42 -0500, Frustrated wrote: On Thursday, 30 January 2014 at 17:11:24 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 11:58:15 -0500, Frustrated wrote: Essentially what it boils down to is treating interfaces like classes that have no fields). To avoid the d

Re: Is continuously seeding a random number generator performance intensive?

2014-01-30 Thread monarch_dodra
On Tuesday, 21 January 2014 at 19:00:32 UTC, Jeroen Bollen wrote: On Tuesday, 21 January 2014 at 17:51:44 UTC, monarch_dodra Is that your actual code? "MersenneTwisterEngine(seed)" is not valid code, you have to provide the template arguments. I meant to answer to this by the way, sorry. (in n

Idiomatic D?

2014-01-30 Thread Tofu Ninja
I hear it thrown around a lot but what does it actually mean? What does the ideal D code look like? What kind of things should some one think about if they are trying to do idiomatic D?

Re: Idiomatic D?

2014-01-30 Thread Dicebot
On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote: I hear it thrown around a lot but what does it actually mean? What does the ideal D code look like? What kind of things should some one think about if they are trying to do idiomatic D? There is no "official" idiomatic style like

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 18:43:02 UTC, bearophile wrote: It's a very silly problem for a statically typed language. The D type system knows the static length of those arrays, but it doesn't use such information. I agree. Unrolling everything except the loop in energy() seems to have

Re: Interfaces allow member definitions?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 17:11:24 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 11:58:15 -0500, Frustrated wrote: Essentially what it boils down to is treating interfaces like classes that have no fields). To avoid the diamond problem simply always choose the method that is no

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 13:58:55 -0500, Cooler wrote: The D principle - "The program compile and runs as expected, or not compile at all". This is a fantasy. The compiler cannot know what you expect. The language is needed to express your intentions to the compiler. Anything that the compiler

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: Looks like both dmd and ldc don't optimize slice operations yet, had to revert to loops It's a very silly problem for a statically typed language. The D type system knows the static length of those arrays, but it doesn't use such information. (Similarly several algorithms i

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 18:29:42 UTC, bearophile wrote: I see you're compiling with ldmd2 -wi -O -release -inline -noboundscheck nbody.d Try ldc2 -release -O3 -disable-boundscheck -vectorize -vectorize-loops

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: That won't compile with dmd (at least, with 2.064.2): it expects constants as initializers for vectors. :( That's why I rolled up that toDouble2() function. Few more changes, but this version still lacks the toDouble2: http://codepad.org/SpMprWym Bye, bearophile

Re: Interfaces allow member definitions?

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 13:16:21 -0500, Steven Schveighoffer wrote: http://dlang.org/phobos/std_typecons.html#.BlackHole Sorry, black hole just does nothing. it's white hole you want: http://dlang.org/phobos/std_typecons.html#.WhiteHole -Steve

Re: Interfaces allow member definitions?

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 13:06:30 -0500, Frustrated wrote: On Thursday, 30 January 2014 at 17:38:26 UTC, Steven Schveighoffer wrote: This is a misunderstanding, you still need to declare a class, because an interface is not a concrete type. But if there are default implementations for all the in

Re: How to call opCall as template?

2014-01-30 Thread Namespace
On Thursday, 30 January 2014 at 18:11:49 UTC, Frustrated wrote: BTW, a() is replaced with a.opCall() and you can use opDispatch on it. an opCall is a member. Either approach should work if you can get that archive example to compile. I am sure that the error is thrown before. But please sho

Re: How to call opCall as template?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 18:02:05 UTC, Namespace wrote: On Thursday, 30 January 2014 at 17:46:19 UTC, Frustrated wrote: Also, http://dlang.org/operatoroverloading.html#Dispatch and possible solution to your problem: http://www.digitalmars.com/d/archives/digitalmars/D/opDispatch_and_tem

Re: Interfaces allow member definitions?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 17:38:26 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 12:30:04 -0500, Frustrated wrote: On Thursday, 30 January 2014 at 17:11:24 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 11:58:15 -0500, Frustrated wrote: Essentially what it boils down

Re: How to call opCall as template?

2014-01-30 Thread Frustrated
BTW, a() is replaced with a.opCall() and you can use opDispatch on it. an opCall is a member. Either approach should work if you can get that archive example to compile.

Re: How to call opCall as template?

2014-01-30 Thread Namespace
On Thursday, 30 January 2014 at 17:46:19 UTC, Frustrated wrote: Also, http://dlang.org/operatoroverloading.html#Dispatch and possible solution to your problem: http://www.digitalmars.com/d/archives/digitalmars/D/opDispatch_and_template_parameters_117095.html Couldn't get code to compile thoug

Re: How to call opCall as template?

2014-01-30 Thread Namespace
On Thursday, 30 January 2014 at 16:55:01 UTC, Meta wrote: On Thursday, 30 January 2014 at 15:59:28 UTC, Namespace wrote: Here: http://dlang.org/operatoroverloading.html#FunctionCall is this example: import std.stdio; struct F { int opCall() { return 0; }

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 12:38:57 -0500, Cooler wrote: The D principle - "The program compile and runs as expected, or not compile at all". This is a fantasy. The compiler cannot know what you expect. The language is needed to express your intentions to the compiler. Anything that the compile

Re: How to call opCall as template?

2014-01-30 Thread Frustrated
Also, http://dlang.org/operatoroverloading.html#Dispatch and possible solution to your problem: http://www.digitalmars.com/d/archives/digitalmars/D/opDispatch_and_template_parameters_117095.html Couldn't get code to compile though... but if it did, it should solve your problem.

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: That won't compile with dmd (at least, with 2.064.2): it expects constants as initializers for vectors. :( That's why I rolled up that toDouble2() function. I see. Then probably I will have to put it back... With N = 5_000_000 my timings on an old CPU are 2.23 seconds for

Re: Interfaces allow member definitions?

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 12:30:04 -0500, Frustrated wrote: On Thursday, 30 January 2014 at 17:11:24 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 11:58:15 -0500, Frustrated wrote: Essentially what it boils down to is treating interfaces like classes that have no fields). To avoid the d

Re: How to call opCall as template?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 16:53:33 UTC, Namespace wrote: On Thursday, 30 January 2014 at 16:47:46 UTC, Frustrated wrote: On Thursday, 30 January 2014 at 16:28:42 UTC, Namespace wrote: On Thursday, 30 January 2014 at 16:24:00 UTC, Stanislav Blinov wrote: void main() { F f;

Re: Interfaces allow member definitions?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 17:11:24 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 11:58:15 -0500, Frustrated wrote: Essentially what it boils down to is treating interfaces like classes that have no fields). To avoid the diamond problem simply always choose the method that is no

Re: core.stdc.config

2014-01-30 Thread Gary Willoughby
On Thursday, 30 January 2014 at 14:10:37 UTC, Craig Dillabaugh wrote: I did as you suggested and had a look through what was on my system. Having done so I now think that the documentation at: http://dlang.org/phobos/index.html is out of date. If you look at the section under "Imports", this

Re: Interfaces allow member definitions?

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 11:58:15 -0500, Frustrated wrote: Essentially what it boils down to is treating interfaces like classes that have no fields). To avoid the diamond problem simply always choose the method that is not from the interface(since it is "default"), which is done naturally with the

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Maxim Fomin
On Thursday, 30 January 2014 at 16:48:51 UTC, Cooler wrote: On Thursday, 30 January 2014 at 16:18:33 UTC, Steven Schveighoffer wrote: void foo(int x) { x = 5; } "hey, why doesn't that work! Setting a parameter to another value should be illegal!" -Steve Please understand - I am not again

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 12:07:07 -0500, Cooler wrote: On Thursday, 30 January 2014 at 16:18:33 UTC, Steven Schveighoffer wrote: void foo(int x) { x = 5; } "hey, why doesn't that work! Setting a parameter to another value should be illegal!" Difference is here. "void foo(int x){}" - the c

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 11:48:50 -0500, Cooler wrote: Please understand - I am not against void foo(int[] x){} From an earlier post by you: May be just prohibit at language level the case of fun3() function, to do not allow unpredictable behavior? I thought that this meant you were against

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 16:53:22 UTC, bearophile wrote: Yes. The older version of LDC2 doesn't even compile the code. I need to use 0.13.0-alpha1. Hmm. Your D code with small changes: http://codepad.org/xqqScd42 That won't compile with dmd (at least, with 2.064.2): it expects cons

Re: How to call opCall as template?

2014-01-30 Thread Meta
On Thursday, 30 January 2014 at 15:59:28 UTC, Namespace wrote: Here: http://dlang.org/operatoroverloading.html#FunctionCall is this example: import std.stdio; struct F { int opCall() { return 0; } int opCall(int x, int y, int z) {

Re: Interfaces allow member definitions?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 15:28:24 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 09:31:05 -0500, Frustrated wrote: I'm not asking about a work around but if what I am talking about can actually be done(does the vtable support this or can made to support it?) Yes. Interfaces

Re: How to call opCall as template?

2014-01-30 Thread Namespace
On Thursday, 30 January 2014 at 16:47:46 UTC, Frustrated wrote: On Thursday, 30 January 2014 at 16:28:42 UTC, Namespace wrote: On Thursday, 30 January 2014 at 16:24:00 UTC, Stanislav Blinov wrote: void main() { F f; int i = f(3,4,5); float f_ = f!float(6, 7, 8); }

Re: How to call opCall as template?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 16:28:42 UTC, Namespace wrote: On Thursday, 30 January 2014 at 16:24:00 UTC, Stanislav Blinov wrote: void main() { F f; int i = f(3,4,5); float f_ = f!float(6, 7, 8); } Does not work, it fails with: Error: template instance f!float f

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: You mean with your current version of ldc? Yes. The older version of LDC2 doesn't even compile the code. I need to use 0.13.0-alpha1. Your D code with small changes: http://codepad.org/xqqScd42 Asm generated by G++ for the advance function (that is the one that uses most

Re: Interfaces allow member definitions?

2014-01-30 Thread Frustrated
On Thursday, 30 January 2014 at 15:18:12 UTC, John Chapman wrote: On Thursday, 30 January 2014 at 14:31:05 UTC, Frustrated wrote: I'm not asking about a work around but if what I am talking about can actually be done(does the vtable support this or can made to support it?) It would work if y

Re: How to call opCall as template?

2014-01-30 Thread Namespace
On Thursday, 30 January 2014 at 16:24:00 UTC, Stanislav Blinov wrote: void main() { F f; int i = f(3,4,5); float f_ = f!float(6, 7, 8); } Does not work, it fails with: Error: template instance f!float f is not a template declaration, it is a variable f.opCall!floa

Re: N-body bench

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 15:37:24 UTC, bearophile wrote: Stanislav Blinov: Forgot one slice assignment in toDobule2(). Now the results are more interesting: Is the latest link shown the last version? No. In toDouble2() on line 13: replace result.array = args[0] with result.array[0]

Re: How to call opCall as template?

2014-01-30 Thread Stanislav Blinov
void main() { F f; int i = f(3,4,5); float f_ = f!float(6, 7, 8); } Does not work, it fails with: Error: template instance f!float f is not a template declaration, it is a variable f.opCall!float(6, 7, 8);

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 11:04:44 -0500, Cooler wrote: On Thursday, 30 January 2014 at 16:01:32 UTC, Cooler wrote: On Thursday, 30 January 2014 at 15:59:48 UTC, Cooler wrote: On Thursday, 30 January 2014 at 15:51:44 UTC, Tobias Pankrath wrote: On Thursday, 30 January 2014 at 15:49:35 UTC, Cooler

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 10:49:34 -0500, Cooler wrote: On Thursday, 30 January 2014 at 15:29:50 UTC, Steven Schveighoffer wrote: On Thu, 30 Jan 2014 10:24:14 -0500, Cooler wrote: On Thursday, 30 January 2014 at 14:40:36 UTC, Dicebot wrote: I agree. I just want that the case can be expressed in

import expression with paths

2014-01-30 Thread Lemonfiend
This does not compile on Windows, but does compile on Mac: --- module main; void main() { import std.path; enum bar = import(`dir` ~ dirSeparator ~ `bar.txt`); } --- The docs say: http://dlang.org/expression.html#ImportExpression "Implementations may restrict the file name in or

How to call opCall as template?

2014-01-30 Thread Namespace
Here: http://dlang.org/operatoroverloading.html#FunctionCall is this example: import std.stdio; struct F { int opCall() { return 0; } int opCall(int x, int y, int z) { return x * y * z; } } void main() { F f;

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Tobias Pankrath
On Thursday, 30 January 2014 at 15:49:35 UTC, Cooler wrote: I agree. I just want that the case can be expressed in language syntax more obvious - something like "fun(int[] const x){}" to emphasize that I understand that fun() can change content of array, and cannot change the {pointer,size} pa

Re: N-body bench

2014-01-30 Thread bearophile
Stanislav Blinov: Forgot one slice assignment in toDobule2(). Now the results are more interesting: Is the latest link shown the last version? I need the 0.13.0-alpha1 to compile the code. I am seeing a significant performance difference between C++ and D-ldc2. Bye, bearophile

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 10:24:14 -0500, Cooler wrote: On Thursday, 30 January 2014 at 14:40:36 UTC, Dicebot wrote: On Thursday, 30 January 2014 at 13:42:53 UTC, Cooler wrote: If I use fun2() I expect that fun2() will change the content of my array, and all changes I will see. If I don't want any

Re: Interfaces allow member definitions?

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 09:31:05 -0500, Frustrated wrote: I'm not asking about a work around but if what I am talking about can actually be done(does the vtable support this or can made to support it?) Yes. Interfaces have no concrete vtable. Only classes do. A concrete class can decide what t

Re: Interfaces allow member definitions?

2014-01-30 Thread John Chapman
On Thursday, 30 January 2014 at 14:31:05 UTC, Frustrated wrote: I'm not asking about a work around but if what I am talking about can actually be done(does the vtable support this or can made to support it?) It would work if you changed the interface to an abstract class.

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 09:07:14 -0500, Cooler wrote: If I don't want that fun() will change my array, i have to use fun1() variant. If I want fun() will change my array, i have to use fun2() variant. What fun2() do with it's argument inside it's body - not my business. No. You can use fun3 va

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Steven Schveighoffer
On Thu, 30 Jan 2014 09:18:40 -0500, Cooler wrote: Forgot to mention :) I read the rest of the discussion. Arrays are hard to understand in D, especially if you have preconceived notions from other languages. But I would point out that fun2 does not "guarantee" anything more than fun3:

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Dicebot
On Thursday, 30 January 2014 at 14:18:41 UTC, Cooler wrote: "But I would point out that fun2 does not guarantee anything more than fun3:" - fun2() cannot guarantee anything because it calls fun3() which in turn cannot guarantee anything. Unrelated. void foo2(ref int[] arr) { /* do nothing */

Re: Array as an argument, ambiguous behaviour.

2014-01-30 Thread Stanislav Blinov
On Thursday, 30 January 2014 at 14:40:36 UTC, Dicebot wrote: On Thursday, 30 January 2014 at 13:42:53 UTC, Cooler wrote: What should I want to use fun3()? For changes to content of array but not array itself. For zillion+nth time :)

  1   2   >