Forward declaration issue

2015-12-04 Thread Andre via Digitalmars-d-learn
Hi, I have a strange issue with following coding. void baz(); // forward declaration void foo() { void bar() { baz(); // (1) without f.d. syntax error } void baz() { bar(); } baz(); // (2)

Re: Forward declaration issue

2015-12-04 Thread Andre via Digitalmars-d-learn
On Friday, 4 December 2015 at 09:51:30 UTC, Artur Skawina wrote: No, it's how D is designed -- inside functions the order of declarations matters (and forward declarations don't work). Your version wrongly declares another `baz` at module scope, and, as there's no definition, you end up with

Re: Struct initializers as expressions

2015-12-04 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 3 December 2015 at 15:31:49 UTC, Chris Wright wrote: On Thu, 03 Dec 2015 06:38:20 +, Mike Parker wrote: AFAIK, your only option is to use a struct constructor. This is the sort of thing they're used for. Which brings be back to positional arguments, which means that

Re: Struct initializers as expressions

2015-12-04 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 4 December 2015 at 10:42:46 UTC, Marc Schütz wrote: I suggest to make the struct name optional: ... but not forbidden. With templates or "auto" could be useful to force the type.

Re: Struct initializers as expressions

2015-12-04 Thread Mike Parker via Digitalmars-d-learn
On Friday, 4 December 2015 at 10:42:46 UTC, Marc Schütz wrote: ; Then we can add some syntax sugar to leave out the braces, too: void bar(int a, T t) bar(42, a: "bla", b: "xyz"); This effectively gives us strongly typed named arguments, without making the names part of the function

Re: Forward declaration issue

2015-12-04 Thread Artur Skawina via Digitalmars-d-learn
On 12/04/15 09:12, Andre via Digitalmars-d-learn wrote: > Hi, > > I have a strange issue with following coding. > > void baz(); // forward declaration > > void foo() > { > void bar() > { > baz(); // (1) without f.d. syntax error > } > > void baz() > { >

Re: Forward declaration issue

2015-12-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, December 04, 2015 08:12:05 Andre via Digitalmars-d-learn wrote: > Hi, > > I have a strange issue with following coding. > > void baz(); // forward declaration > > void foo() > { > void bar() > { > baz(); // (1) without f.d. syntax error > } > > void baz() > { >

Re: Which type it better to use for array's indices?

2015-12-04 Thread Chris Wright via Digitalmars-d-learn
On Fri, 04 Dec 2015 13:24:16 +, ref2401 wrote: > It seem like `size_t` suites well because 'is large enough to represent > an offset into all addressible memory.' > (http://dlang.org/spec/type.html#size_t) > However sometimes I want index to be less the 0 to represent a > particular case.

Re: Struct initializers as expressions

2015-12-04 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 4 December 2015 at 11:25:12 UTC, Mike Parker wrote: On Friday, 4 December 2015 at 10:42:46 UTC, Marc Schütz wrote: ; Then we can add some syntax sugar to leave out the braces, too: void bar(int a, T t) bar(42, a: "bla", b: "xyz"); This effectively gives us strongly typed

Re: Struct initializers as expressions

2015-12-04 Thread Chris Wright via Digitalmars-d-learn
On Fri, 04 Dec 2015 15:07:01 +0100, Jacob Carlborg wrote: > But I do see a problem, which I'm guessing Walter would point out as > well. It might/will complicate the overloading rules. What if "a" and > "b" in T would be integers instead. I think that would be ambiguous. Right. I would much

Re: Struct initializers as expressions

2015-12-04 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 4 December 2015 at 14:07:01 UTC, Jacob Carlborg wrote: On 2015-12-04 11:42, Marc Schütz wrote: I'd support that, too. I suggest to make the struct name optional: struct S { int a, b; } struct T { string a, b; } void foo(S s); void foo(T t); foo({b: 1, a:

Re: Which type it better to use for array's indices?

2015-12-04 Thread ghjk via Digitalmars-d-learn
On Friday, 4 December 2015 at 13:24:16 UTC, ref2401 wrote: Which type it better to use for array's indices? float[] arr = new float[10]; int i; long j; size_t k; // which one is better arr[i], a[j]or arr[k] ? It seem like `size_t` suites well because 'is large enough to represent an

Re: Which type it better to use for array's indices?

2015-12-04 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 4 December 2015 at 13:24:16 UTC, ref2401 wrote: Which type it better to use for array's indices? float[] arr = new float[10]; int i; long j; size_t k; // which one is better arr[i], a[j]or arr[k] ? It seem like `size_t` suites well because 'is large enough to represent an

benchmark on binary trees

2015-12-04 Thread Alex via Digitalmars-d-learn
Hi everybody, this is going to be a learning by doing a benchmark test - post. Found this "game" on the web http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=binarytrees and wanted to experiment on my self, I tried to reimplement some code in D. This:

Re: __traits and string mixins

2015-12-04 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 3 December 2015 at 13:36:16 UTC, Christian Köstlin wrote: Hi, I started an experiment with the informations that are available for compile time reflection. [...] I think CyberShadow (aka Vladimir Panteleev) has done something similar to this

Re: Which type it better to use for array's indices?

2015-12-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-12-04 14:24, ref2401 wrote: For instance `find(float[] arr, float v)` may return -1 if `v` has not been found. If "find" is returning an index, it could return arr.length to indicate it was not found. -- /Jacob Carlborg

Re: Struct initializers as expressions

2015-12-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-12-04 11:42, Marc Schütz wrote: I'd support that, too. I suggest to make the struct name optional: struct S { int a, b; } struct T { string a, b; } void foo(S s); void foo(T t); foo({b: 1, a: 2}); // foo(S(2, 1)); foo({a: "bla"});// foo(T("bla",

Which type it better to use for array's indices?

2015-12-04 Thread ref2401 via Digitalmars-d-learn
Which type it better to use for array's indices? float[] arr = new float[10]; int i; long j; size_t k; // which one is better arr[i], a[j]or arr[k] ? It seem like `size_t` suites well because 'is large enough to represent an offset into all addressible memory.'

Re: benchmark on binary trees

2015-12-04 Thread anonymous via Digitalmars-d-learn
On 04.12.2015 15:06, Alex wrote: 3. The compilation was done by: dmd -O -release -boundscheck=off [filename.d] Is there anything else to improve performance significantly? You forgot -inline. By the way, I'm not a fan of using -boundscheck=off like a general optimization flag. It undermines

Re: benchmark on binary trees

2015-12-04 Thread anonymous via Digitalmars-d-learn
On 04.12.2015 21:30, Alex wrote: Yes, I missed this, sorry. The main part of the question was probably about the class and struct difference. I thought handling with structs and pointers would be faster then with classes. When you use a struct directly, without going through a pointer, that

Re: benchmark on binary trees

2015-12-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 December 2015 at 19:31:22 UTC, anonymous wrote: Why did you expect the C++ inspired version to be faster? Just because the original was written in C++? From a quick skim the two versions seem to be pretty much identical, aside from names and struct vs class. Names don't make a

Re: Which type it better to use for array's indices?

2015-12-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, December 04, 2015 13:24:16 ref2401 via Digitalmars-d-learn wrote: > Which type it better to use for array's indices? > > float[] arr = new float[10]; > int i; > long j; > size_t k; > // which one is better arr[i], a[j]or arr[k] ? > > It seem like `size_t` suites well because 'is large

Re: benchmark on binary trees

2015-12-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 December 2015 at 23:23:37 UTC, anonymous wrote: Why the parallel version is slower then the sequential? If you set int n = 14 in the main function the parallel version is MUCH slower then the sequential. At my machine 7x slower. Shouldn't it be the other way round? I don't know

Re: __traits and string mixins

2015-12-04 Thread Christian Köstlin via Digitalmars-d-learn
On 04/12/15 21:49, Nicholas Wilson wrote: On Thursday, 3 December 2015 at 13:36:16 UTC, Christian Köstlin wrote: Hi, I started an experiment with the informations that are available for compile time reflection. [...] I think CyberShadow (aka Vladimir Panteleev) has done something similar to

Re: Pixelbuffer to draw on a surface

2015-12-04 Thread TheDGuy via Digitalmars-d-learn
Thanks for your answers. I think Cairo is the right way but i have a hard time to translate any of those C++ or Python tutorials to D, my current code: import gtk.Main; import gtk.MainWindow; import gtk.DrawingArea; import gdk.Cairo; import gtk.Widget; void main(string[] args){

How to add third party libraries to the project. (Xamarin)

2015-12-04 Thread Neomex via Digitalmars-d-learn
How do I add third party libraries to the project? I am using Xamarin. I have built Derelict-SDL2 with dub and got the lib file but I don't know what to do with it. In xamarins references folder theres only option to refresh not to add anything.

Re: How to add third party libraries to the project. (Xamarin)

2015-12-04 Thread ZombineDev via Digitalmars-d-learn
On Friday, 4 December 2015 at 18:15:47 UTC, Neomex wrote: How do I add third party libraries to the project? I am using Xamarin. I have built Derelict-SDL2 with dub and got the lib file but I don't know what to do with it. In xamarins references folder theres only option to refresh not to

Re: Reset all Members of a Aggregate Instance

2015-12-04 Thread Enamex via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote: ... Unless I'm missing something very important: Isn't that essentially what the `out` attribute on a function parameter does?

Re: benchmark on binary trees

2015-12-04 Thread CraigDillabaugh via Digitalmars-d-learn
On Friday, 4 December 2015 at 14:06:26 UTC, Alex wrote: Hi everybody, this is going to be a learning by doing a benchmark test - post. clip 3. The compilation was done by: dmd -O -release -boundscheck=off [filename.d] Is there anything else to improve performance significantly? If you

Re: How to add third party libraries to the project. (Xamarin)

2015-12-04 Thread ZombineDev via Digitalmars-d-learn
On Friday, 4 December 2015 at 19:15:57 UTC, ZombineDev wrote: The myproj/dub.json file contains: { "name": "myproj", "description": "A minimal D application.", "copyright": "Copyright © 2015, ubuntu", "authors": ["ubuntu"], "dependencies": { "derelict-sdl2": "1.9.7"

Re: benchmark on binary trees

2015-12-04 Thread anonymous via Digitalmars-d-learn
On 04.12.2015 15:06, Alex wrote: 1. I wrote the C++ inspired version after the C# inspired, hoping it would be faster. This was not the case. Why? [...] Why did you expect the C++ inspired version to be faster? Just because the original was written in C++? From a quick skim the two versions