Why is this pure?

2014-08-25 Thread Shachar via Digitalmars-d-learn
The following program compiles, and does what you'd expect: struct A { int a; } pure int func( ref A a ) { return a.a += 3; } As far as I can tell, however, it shouldn't. I don't see how or why func can possibly be considered pure, as it changes a state external to the function.

Re: Why is this pure?

2014-08-25 Thread Alex Rønne Petersen via Digitalmars-d-learn
On Monday, 25 August 2014 at 06:27:00 UTC, Shachar wrote: The following program compiles, and does what you'd expect: struct A { int a; } pure int func( ref A a ) { return a.a += 3; } As far as I can tell, however, it shouldn't. I don't see how or why func can possibly be considered

Re: Why no multiple-dispatch?

2014-08-25 Thread Idan Arye via Digitalmars-d-learn
On Monday, 25 August 2014 at 02:04:43 UTC, Aerolite wrote: On Monday, 25 August 2014 at 01:34:14 UTC, Idan Arye wrote: On Monday, 25 August 2014 at 01:10:32 UTC, Aerolite wrote: -- No syntax modification (unless you want the feature to be optional) If this ever gets into the core language,

Re: Why no multiple-dispatch?

2014-08-25 Thread via Digitalmars-d-learn
On Monday, 25 August 2014 at 07:36:22 UTC, Idan Arye wrote: Are you suggesting the compiler will try to resolve the polymorphism at compile-time, looking at all possible paths that lead to a function call to check all possible runtime values it's object arguments can get? I've argued for

Re: how to tell if a thing is a template

2014-08-25 Thread John Colvin via Digitalmars-d-learn
On Sunday, 24 August 2014 at 00:41:36 UTC, Ellery Newcomer wrote: Can't think off the top of my head how you do this template IsTemplate(alias t) { ?? } static assert(IsTemplate!IsTemplate) __traits(compiles, is(t!X, X...)) should do it, or something similar.

Re: Why no multiple-dispatch?

2014-08-25 Thread Aerolite via Digitalmars-d-learn
On Monday, 25 August 2014 at 07:36:22 UTC, Idan Arye wrote: If multi-dispatching is done at compile-time, it can't rely on the object's runtime type - only on the static type of the reference that holds it. This is no different than regular function overloading that we already have. Well any

Re: Why no multiple-dispatch?

2014-08-25 Thread Aerolite via Digitalmars-d-learn
On Monday, 25 August 2014 at 08:45:15 UTC, Ola Fosheim Grøstad wrote: However, why do you want multiple dispatch? I cannot think of any application level use scenario where you have two class hierarchies that you have no control over. So I don't really see the value of multiple dispatch in a

unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn
[code] void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { } struct vec(size_t N, T, string AS) { T[N] data; } void main() { doSome( vec!(3,float,xyz)([1,2,3]) ); } [/code] compile with new dmd v2.066.0 and get error: Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, AS) v)

Re: unclear compile error for struct with string template

2014-08-25 Thread bearophile via Digitalmars-d-learn
Oleg B: [code] void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { } struct vec(size_t N, T, string AS) { T[N] data; } void main() { doSome( vec!(3,float,xyz)([1,2,3]) ); } [/code] compile with new dmd v2.066.0 and get error: Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T,

Re: unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn
On Monday, 25 August 2014 at 11:41:28 UTC, bearophile wrote: Oleg B: [code] void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { } struct vec(size_t N, T, string AS) { T[N] data; } void main() { doSome( vec!(3,float,xyz)([1,2,3]) ); } [/code] compile with new dmd v2.066.0 and get error:

Re: unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn
and when I minimal fix my libs with this issue compiler fails without any output... =( % gdb dmd (gdb) run -unittest matrix.d vector.d Starting program: /usr/bin/dmd -unittest matrix.d vector.d [Thread debugging using libthread_db enabled] Using host libthread_db library

Re: Why no multiple-dispatch?

2014-08-25 Thread via Digitalmars-d-learn
On Monday, 25 August 2014 at 10:16:29 UTC, Aerolite wrote: Well there are a few go-to use-cases, the handling of collisions between objects in a game-engine being the most well-known (which requires Double-Dispatch). I think a game engine is better off using a simple table or a more

Compiling dll issue.

2014-08-25 Thread Taylor Hillegeist via Digitalmars-d-learn
So i have been trying to follow the instructions on: http://wiki.dlang.org/Win32_DLLs_in_D but when i get to the step where i compile the dll dmd -ofmydll.dll -L/IMPLIB mydll.d dll.d mydll.def I get this output: OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All

Re: Compiling dll issue.

2014-08-25 Thread Taylor Hillegeist via Digitalmars-d-learn
On Monday, 25 August 2014 at 15:09:59 UTC, Taylor Hillegeist wrote: So i have been trying to follow the instructions on: http://wiki.dlang.org/Win32_DLLs_in_D but when i get to the step where i compile the dll dmd -ofmydll.dll -L/IMPLIB mydll.d dll.d mydll.def I get this output: OPTLINK (R)

Re: Compiling dll issue.

2014-08-25 Thread fenom via Digitalmars-d-learn
On Monday, 25 August 2014 at 15:09:59 UTC, Taylor Hillegeist wrote: So i have been trying to follow the instructions on: http://wiki.dlang.org/Win32_DLLs_in_D but when i get to the step where i compile the dll dmd -ofmydll.dll -L/IMPLIB mydll.d dll.d mydll.def I get this output: OPTLINK (R)

Error with constraints on a templated fuction

2014-08-25 Thread Jeremy DeHaan via Digitalmars-d-learn
I've done things like this before with traits and I figured that this way should work as well, but it gives me errors instead. Perhaps someone can point out my flaws. immutable(T)[] toString(T)(const(T)* str) if(typeof(T) is dchar)//this is where the error is { return

Re: Error with constraints on a templated fuction

2014-08-25 Thread bearophile via Digitalmars-d-learn
Jeremy DeHaan: It compiles if I remove the 'if(typeof(T) is dchar)' section. Any thoughts? Try: if (is(T == dchar)) Bye, bearophile

Re: Error with constraints on a templated fuction

2014-08-25 Thread ketmar via Digitalmars-d-learn
On Mon, 25 Aug 2014 15:48:10 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: It compiles if I remove the 'if(typeof(T) is dchar)' section. Any thoughts? is should be used as function. here. i.e.: `if (is(T == dchar))` signature.asc Description: PGP

Re: Error with constraints on a templated fuction

2014-08-25 Thread Jeremy DeHaan via Digitalmars-d-learn
On Monday, 25 August 2014 at 15:59:38 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 25 Aug 2014 15:48:10 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: It compiles if I remove the 'if(typeof(T) is dchar)' section. Any thoughts? is should be used as

Re: Error with constraints on a templated fuction

2014-08-25 Thread Jeremy DeHaan via Digitalmars-d-learn
On Monday, 25 August 2014 at 15:52:20 UTC, bearophile wrote: Jeremy DeHaan: It compiles if I remove the 'if(typeof(T) is dchar)' section. Any thoughts? Try: if (is(T == dchar)) Bye, bearophile That one compiles, and I'm assuming it works. I didn't know you could use is this way. I've

Re: Error with constraints on a templated fuction

2014-08-25 Thread ketmar via Digitalmars-d-learn
On Mon, 25 Aug 2014 16:11:27 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is its ability to be used as a function like this documented anywhere? I looked and could not find it. http://dlang.org/concepts.html template constraints is a special case. is not

Re: Error with constraints on a templated fuction

2014-08-25 Thread Jeremy DeHaan via Digitalmars-d-learn
On Monday, 25 August 2014 at 16:20:24 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 25 Aug 2014 16:11:27 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is its ability to be used as a function like this documented anywhere? I looked and could not find

Learning D

2014-08-25 Thread Ryan via Digitalmars-d-learn
Me: Software developer for 30 years. So perhaps this is old fashion, but I wanted to start using D by whipping together nice little personal utilities. I tried installing MonoDevelop and Mono-D. I can't even figure out the basics, such as adding references to a project. There are no

Re: Error with constraints on a templated fuction

2014-08-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 25 Aug 2014 15:48:10 + Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I've done things like this before with traits and I figured that this way should work as well, but it gives me errors instead. Perhaps someone can point out my flaws.

Re: Learning D

2014-08-25 Thread John Colvin via Digitalmars-d-learn
On Monday, 25 August 2014 at 16:46:11 UTC, Ryan wrote: Me: Software developer for 30 years. So perhaps this is old fashion, but I wanted to start using D by whipping together nice little personal utilities. I tried installing MonoDevelop and Mono-D. I can't even figure out the basics, such

Re: Error with constraints on a templated fuction

2014-08-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 25, 2014 at 03:48:10PM +, Jeremy DeHaan via Digitalmars-d-learn wrote: I've done things like this before with traits and I figured that this way should work as well, but it gives me errors instead. Perhaps someone can point out my flaws. immutable(T)[] toString(T)(const(T)*

Re: Learning D

2014-08-25 Thread Kiith-Sa via Digitalmars-d-learn
On Monday, 25 August 2014 at 16:46:11 UTC, Ryan wrote: Me: Software developer for 30 years. So perhaps this is old fashion, but I wanted to start using D by whipping together nice little personal utilities. I tried installing MonoDevelop and Mono-D. I can't even figure out the basics, such

Re: Error with constraints on a templated fuction

2014-08-25 Thread via Digitalmars-d-learn
On Monday, 25 August 2014 at 17:05:48 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Mon, Aug 25, 2014 at 03:48:10PM +, Jeremy DeHaan via Digitalmars-d-learn wrote: I've done things like this before with traits and I figured that this way should work as well, but it gives me errors

Using the delete Keyword /w GC

2014-08-25 Thread Etienne via Digitalmars-d-learn
People have been saying for quite a long time not to use the `delete` keyword on GC-allocated pointers. I've looked extensively through the code inside the engine and even made a few modifications on it/benchmarked it for weeks and I still can't see why it would be wrong. Wouldn't it help

Re: Why no multiple-dispatch?

2014-08-25 Thread Idan Arye via Digitalmars-d-learn
On Monday, 25 August 2014 at 10:02:41 UTC, Aerolite wrote: On Monday, 25 August 2014 at 07:36:22 UTC, Idan Arye wrote: If multi-dispatching is done at compile-time, it can't rely on the object's runtime type - only on the static type of the reference that holds it. This is no different than

Re: Using the delete Keyword /w GC

2014-08-25 Thread Brad Anderson via Digitalmars-d-learn
On Monday, 25 August 2014 at 17:10:11 UTC, Etienne wrote: People have been saying for quite a long time not to use the `delete` keyword on GC-allocated pointers. I've looked extensively through the code inside the engine and even made a few modifications on it/benchmarked it for weeks and I

Re: Why no multiple-dispatch?

2014-08-25 Thread via Digitalmars-d-learn
On Monday, 25 August 2014 at 17:16:10 UTC, Idan Arye wrote: * Alternative implementations need to implement them(even though the frontend is shared, there can always be some complications(plus I think mutli-methods might need some backend modifications as well, thhoguh I'm no expert on that

Re: Why no multiple-dispatch?

2014-08-25 Thread via Digitalmars-d-learn
On Monday, 25 August 2014 at 17:28:45 UTC, Ola Fosheim Grøstad wrote: Then extend the typeinfo of classes in the first param with a minimal typeid and 2D table that lists all combinations that the custom linker can find based on the mangling? Maybe it would be better to put in the restriction

Re: Error with constraints on a templated fuction

2014-08-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 25, 2014 at 05:10:18PM +, via Digitalmars-d-learn wrote: On Monday, 25 August 2014 at 17:05:48 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Mon, Aug 25, 2014 at 03:48:10PM +, Jeremy DeHaan via Digitalmars-d-learn wrote: I've done things like this before with traits

Re: Error with constraints on a templated fuction

2014-08-25 Thread Artur Skawina via Digitalmars-d-learn
On 08/25/14 18:52, Jonathan M Davis via Digitalmars-d-learn wrote: Another commonly used one is is(typeof(foo)). typeof(foo) gets the type of foo and will result in void if foo doesn't exist, and is(void) is false, whereas D is not quite that simple. ;) static assert(is(void)==true); (a)

Re: Learning D

2014-08-25 Thread Ryan via Digitalmars-d-learn
Thanks for both responses. This is the information I was looking for. I have DMD, GTK# (For MonoDevelop), MonoDevelop, MonoD, dubs, and GTKD installed. I've got some things to compile... So the crux of my issue is that I can't figure out how to link lib files in MonoDevelop. I wonder if

Re: Learning D

2014-08-25 Thread Ryan via Digitalmars-d-learn
Anyone know MonoDevelop? Why is the Edit References context menu item missing. I have it at the top (Project-Edit References...) but when I click it nothing happens. Grrr.

Is this a bug when creating proxies in classes?

2014-08-25 Thread Gary Willoughby via Digitalmars-d-learn
Compiling the following code: import std.typecons; class Foo { private int foo; mixin Proxy!(foo); this(int x) { this.foo = x; } } void main()

Re: Learning D

2014-08-25 Thread Colin via Digitalmars-d-learn
On Monday, 25 August 2014 at 17:57:54 UTC, Ryan wrote: Anyone know MonoDevelop? Why is the Edit References context menu item missing. I have it at the top (Project-Edit References...) but when I click it nothing happens. Grrr. I couldnt figure it out either tbh (creating dub projects using

Re: Is this a bug when creating proxies in classes?

2014-08-25 Thread Ali Çehreli via Digitalmars-d-learn
On 08/25/2014 11:10 AM, Gary Willoughby wrote: Compiling the following code: import std.typecons; class Foo { private int foo; mixin Proxy!(foo); this(int x) { this.foo = x; } } void main() { }

Re: Is this a bug when creating proxies in classes?

2014-08-25 Thread via Digitalmars-d-learn
On Monday, 25 August 2014 at 18:10:33 UTC, Gary Willoughby wrote: :!rdmd --force -de -debug -w test.d /usr/include/dmd/phobos/std/typecons.d(4043): Error: template instance isArray!(typeof(a)) template 'isArray' is not defined test.d(7): Error: mixin test.Foo.Proxy!(foo) error instantiating

Re: Is this a bug when creating proxies in classes?

2014-08-25 Thread Ali Çehreli via Digitalmars-d-learn
On 08/25/2014 11:38 AM, Marc Schütz schue...@gmx.net wrote: On Monday, 25 August 2014 at 18:10:33 UTC, Gary Willoughby wrote: :!rdmd --force -de -debug -w test.d /usr/include/dmd/phobos/std/typecons.d(4043): Error: template instance isArray!(typeof(a)) template 'isArray' is not defined

Re: Is this a bug when creating proxies in classes?

2014-08-25 Thread via Digitalmars-d-learn
On Monday, 25 August 2014 at 18:44:36 UTC, Ali Çehreli wrote: It can be explained if the mixed-in template is evaluated at the mixin context without bringing in the imported modules to that context. I don't know whether it is true or whether it is a known limitation. You're right, that's it!

Re: Is this a bug when creating proxies in classes?

2014-08-25 Thread via Digitalmars-d-learn
On Monday, 25 August 2014 at 19:12:48 UTC, Marc Schütz wrote: On Monday, 25 August 2014 at 18:44:36 UTC, Ali Çehreli wrote: It can be explained if the mixed-in template is evaluated at the mixin context without bringing in the imported modules to that context. I don't know whether it is true

Re: Using the delete Keyword /w GC

2014-08-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, 25 August 2014 at 17:20:20 UTC, Brad Anderson wrote: On Monday, 25 August 2014 at 17:10:11 UTC, Etienne wrote: People have been saying for quite a long time not to use the `delete` keyword on GC-allocated pointers. I've looked extensively through the code inside the engine and

Re: Learning D

2014-08-25 Thread Ryan via Digitalmars-d-learn
On Monday, 25 August 2014 at 18:12:25 UTC, Colin wrote: On Monday, 25 August 2014 at 17:57:54 UTC, Ryan wrote: Anyone know MonoDevelop? Why is the Edit References context menu item missing. I have it at the top (Project-Edit References...) but when I click it nothing happens. Grrr. I

Cross-module inlining with separate compilation?

2014-08-25 Thread ponce via Digitalmars-d-learn
Is there a way to have cross-module inlining but with separate compilation? Like with link-time generation in C++ compilers.

Getting RefCounted to work with classes

2014-08-25 Thread Bienlein via Digitalmars-d-learn
Hello, the code below compiles and runs fine. However, when I change Payload from struct to class I get compiler errors: Error 1 Error: template instance std.typecons.RefCounted!(Payload, cast(RefCountedAutoInitialize)1) does not match template declaration RefCounted(T,

Re: Is this a bug when creating proxies in classes?

2014-08-25 Thread Ali Çehreli via Digitalmars-d-learn
On 08/25/2014 12:17 PM, Marc Schütz schue...@gmx.net wrote: On Monday, 25 August 2014 at 19:12:48 UTC, Marc Schütz wrote: On Monday, 25 August 2014 at 18:44:36 UTC, Ali Çehreli wrote: It can be explained if the mixed-in template is evaluated at the mixin context without bringing in the

Re: D1: Error: duplicate union initialization for size

2014-08-25 Thread jicman via Digitalmars-d-learn
Ok, let's try something simpler... Where can I find the D1 v1.076 compiler error meaning of, Error: duplicate union initialization for size for this line, const Size DEFAULT_SCALE = { 5, 13 }; thanks.

Re: Using the delete Keyword /w GC

2014-08-25 Thread Baz via Digitalmars-d-learn
On Monday, 25 August 2014 at 17:10:11 UTC, Etienne wrote: People have been saying for quite a long time not to use the `delete` keyword on GC-allocated pointers. I've looked extensively through the code inside the engine and even made a few modifications on it/benchmarked it for weeks and I

Re: Learning D

2014-08-25 Thread Dicebot via Digitalmars-d-learn
On Monday, 25 August 2014 at 20:37:16 UTC, Ryan wrote: Then I thought I'd learn dub. Well, this is NOT going well... I did a git clone of gtk-d, then tried to build with dub (renamed the package.json to dub.json), and it told me Conflicting package multi-reference I have no clue and I've

Re: Are there any exercises/challenges for D?

2014-08-25 Thread Meta via Digitalmars-d-learn
On Sunday, 24 August 2014 at 23:20:21 UTC, maik klein wrote: On Sunday, 24 August 2014 at 21:51:39 UTC, Weaseldog wrote: On Sunday, 24 August 2014 at 20:32:02 UTC, maik klein wrote: Are there any exercises/challenges for D? Something like this?

Re: Are there any exercises/challenges for D?

2014-08-25 Thread Meta via Digitalmars-d-learn
On Tuesday, 26 August 2014 at 01:57:06 UTC, Meta wrote: Have you heard of Project Euler? https://projecteuler.net/ The problems are mostly mathematical, and once you answer you can compare your solution to the other solutions people have written in other languages. The early questions also

Re: Learning D

2014-08-25 Thread Weaseldog via Digitalmars-d-learn
Not sure how up your alley this is, but vim support for D is excellent.

Re: Learning D

2014-08-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 26, 2014 at 02:13:04AM +, Weaseldog via Digitalmars-d-learn wrote: Not sure how up your alley this is, but vim support for D is excellent. I use vim for D. T -- War doesn't prove who's right, just who's left. -- BSD Games' Fortune

Casting to union type?

2014-08-25 Thread cc via Digitalmars-d-learn
Is it possible to allow implicit casting from a base type to a union type? For example, considering the following basic vector union: union vec2 { struct { float x = 0.0f; float y = 0.0f; } float[2] v; enum length = v.length;

Re: Casting to union type?

2014-08-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, 26 August 2014 at 02:33:25 UTC, cc wrote: Is it possible to allow implicit casting from a base type to a union type? All implict conversions are done using alias this: http://dlang.org/class.html#AliasThis - Jonathan M Davis

Re: Cross-module inlining with separate compilation?

2014-08-25 Thread ketmar via Digitalmars-d-learn
On Mon, 25 Aug 2014 21:07:06 + ponce via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is there a way to have cross-module inlining but with separate compilation? Like with link-time generation in C++ compilers. i think that turning your functions into templates should do

Re: Cross-module inlining with separate compilation?

2014-08-25 Thread hane via Digitalmars-d-learn
On Tuesday, 26 August 2014 at 04:34:39 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 25 Aug 2014 21:07:06 + ponce via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is there a way to have cross-module inlining but with separate compilation? Like with link-time

Re: Cross-module inlining with separate compilation?

2014-08-25 Thread ketmar via Digitalmars-d-learn
On Tue, 26 Aug 2014 04:49:17 + hane via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: No template hack needed now. unless you using gdc, for example. ;-) signature.asc Description: PGP signature