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.


What am I missing? Or is this just a compiler bug?

Shachar


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 pure, as it changes a state 
external to the function.


What am I missing? Or is this just a compiler bug?

Shachar


http://klickverbot.at/blog/2012/05/purity-in-d/


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, it absolutely must 
be optional! Think of the implications of having this as the 
default and only behavior:


* Every overloaded function will have to do a runtime 
typecheck - this not only causes a usually unnecessary 
overhead but also has a negative impact on branch prediction.


Well, you'd only have to resolve *class* parameters (since
obviously literals and structs don't support inheritance). My
brain is a little foggy at the moment due to this nice flu I
have, but do we even need to do this at run-time? It's not like
we can do a Java and use run-time reflection to create new class
instances. The closest thing we have to that is Object.factory,
but that's all compile-time built and type-safe as far as I'm
aware? Or am I being silly?


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.


* What if you have multiple overloads that happen to be 
templated? Now the compiler will have to instantiate them all!


Hard to say, although surely there could be some examination of
what is and is not necessary to instantiate. This is again 
making

the implementation a tad more complicated, though. That said, if
something like @multimethod existed, it would assist in this
matter.


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?


Anyways, I don't think you get just how strong this language's 
tendency to push features to the library is, so I'd like to 
point you to this post by the language's creator:


http://forum.dlang.org/thread/lt00a9$2uoe$1...@digitalmars.com#post-lt00a9:242uoe:241:40digitalmars.com


Heh. Well, that's Walter for you! :P But I definitely understand
the push towards the library. I just feel that handling method
dispatch, even in compile-time template code, is not something
that we should really be writing ourselves. It's like trying to
do virtual method calls in C!


Virtual methods in C can be done with GObject - though the syntax 
is awkward. D is so much better than C when it comes to 
metaprogramming, that the syntax for multimethods wouldn't be 
awkward(unless you consider anything that's not burned to the 
core syntax awkward)


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 whole program analysis before and this is another 
example where it would be useful :-). When you have figured out 
the worst-case use pattern you can either make one function 
virtual and then inline the others as a switch or you can create 
class-ids that can be hashed perfectly to an array of function 
pointers.


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 system level programming 
language. Perhaps if you want to use D for an application level 
DSL? What are the use scenarios you guys have experience with 
where multiple dispatch was indispensable?


Ola.


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 library solution has to do this at compile-time... I
assume the implementation would be similar, albeit easier because
the compiler would have all the necessary information directly
accessible.

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?


Is that not what would have to be done for a library solution in
this case, anyway?

Virtual methods in C can be done with GObject - though the 
syntax is awkward. D is so much better than C when it comes to 
metaprogramming, that the syntax for multimethods wouldn't be 
awkward(unless you consider anything that's not burned to the 
core syntax awkward)


Of course, I understand this. What I'm saying is that while it's
possible to do virtual method calls in C, the very fact that it
had to be implemented so awkwardly meant that a library solution
was not ideal. Now in D, the syntax is infinitely better, given.
Templates and compile-time code-generation are all really good.
But as I said, we have a lot of template bloat issues already.
Running 3 foreach-loops at compile-time every time that
template-function gets instantiated doesn't seem scalable to
me... Having something like this in the compiler, which has all
the required information available directly, seems like it'd be
the most scalable solution.


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 system level 
programming language. Perhaps if you want to use D for an 
application level DSL? What are the use scenarios you guys have 
experience with where multiple dispatch was indispensable?


Ola.


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). But it's basically anything that
requires the Visitor Pattern, plus extra.

At the end of the day, most (if not all) of the major software
patterns have come about and are used due to shortfalls in the
major languages. D, at least in my experience, tends to solve a
lot of these shortfalls, and given that design path, why
*wouldn't* we want Multiple Dispatch in the language?


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) specialization not allowed for deduced parameter AS


what does it mean?

on dmd v2.065 it worked well

code without string template parameter work well on dmd v2.066.0

[code]
void doSome(size_t N, T)( vec!(N,T) v ) { }
struct vec(size_t N, T) { T[N] data; }
void main() { doSome( vec!(3,float)([1,2,3]) ); }
[/code]


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, 
AS) v) specialization not allowed for deduced parameter AS


what does it mean?


See also:


struct Vec(size_t N, T, alias string AS) {
T[N] data;
}

void doSome(size_t N, T, alias string AS)(Vec!(N, T, AS) v) {}

void main() {
auto v = Vec!(3, float, xyz)([1, 2, 3]);
doSome(v);
}


(Note that in D the names of types and structs start with an 
upper case).


Bye,
bearophile


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:

Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, 
AS) v) specialization not allowed for deduced parameter AS


what does it mean?


See also:


struct Vec(size_t N, T, alias string AS) {
T[N] data;
}

void doSome(size_t N, T, alias string AS)(Vec!(N, T, AS) v) {}

void main() {
auto v = Vec!(3, float, xyz)([1, 2, 3]);
doSome(v);
}


(Note that in D the names of types and structs start with an 
upper case).


Bye,
bearophile


Does it mean that I need write alias for all arrays in template 
parameters or only strings?


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 /lib64/libthread_db.so.1.
[New Thread 0x77ec9700 (LWP 29224)]
[Thread 0x77ec9700 (LWP 29224) exited]

Program received signal SIGSEGV, Segmentation fault.
0x0046c39a in ctfeInterpret(Expression*) ()
(gdb) bt
#0  0x0046c39a in ctfeInterpret(Expression*) ()
#1  0x00457012 in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long)::DeduceType::visit(TypeInstance*) ()
#2  0x0044e304 in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long) ()
#3  0x0045224f in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long)::DeduceType::visit(TypeStruct*) ()
#4  0x00455e80 in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long)::DeduceType::visit(Expression*) ()
#5  0x0044e32c in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long) ()
#6  0x00458251 in 
TemplateDeclaration::deduceFunctionTemplateMatch(TemplateInstance*, 
Scope*, FuncDeclaration*, Type*, ArrayExpression**) ()
#7  0x0045caf1 in functionResolve(Match*, Dsymbol*, Loc, 
Scope*, ArrayRootObject**, Type*, 
ArrayExpression**)::ParamDeduce::fp(void*, Dsymbol*) ()
#8  0x004dd577 in overloadApply(Dsymbol*, void*, int 
(*)(void*, Dsymbol*)) ()
#9  0x0045c401 in functionResolve(Match*, Dsymbol*, Loc, 
Scope*, ArrayRootObject**, Type*, ArrayExpression**) ()
#10 0x004e0343 in resolveFuncCall(Loc, Scope*, Dsymbol*, 
ArrayRootObject**, Type*, ArrayExpression**, int) ()

#11 0x004d9522 in CallExp::semantic(Scope*) ()
#12 0x004eef56 in ExpInitializer::inferType(Scope*) ()
#13 0x004b08ad in VarDeclaration::semantic(Scope*) ()
#14 0x004c1f7a in DeclarationExp::semantic(Scope*) ()
#15 0x0043cd3b in ExpStatement::semantic(Scope*) ()
#16 0x004479a6 in CompoundStatement::semantic(Scope*) ()
#17 0x004e5e2a in FuncDeclaration::semantic3(Scope*) ()
#18 0x00407b28 in Module::semantic3() ()
#19 0x004051bc in tryMain(unsigned long, char const**) ()
#20 0x00338be21b45 in __libc_start_main (main=0x406e60 
main, argc=4, ubp_av=0x7fffdc28, init=optimized out, 
fini=optimized out, rtld_fini=optimized out,

stack_end=0x7fffdc18) at libc-start.c:274
#21 0x00402739 in _start ()


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 homogeneous engine based on properties rather than classes. 
You usually can assign a small integer to the relevant properties 
and use a 2D LUT.



D, at least in my experience, tends to solve a
lot of these shortfalls, and given that design path, why
*wouldn't* we want Multiple Dispatch in the language?


I have never had a need for it, but maybe I would have used it if 
it was available.


I think, however, that it would fit better in Go which are going 
for a more dynamic implementation of interfaces without OOP.


I certainly see some value in detaching virtual functions from 
the record definition. I believe bitC might go in that direction 
as well.


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 rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllGetClassObject
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllCanUnloadNow
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllRegisterServer
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllUnregisterServer

OPTLINK : Error 81: Cannot EXPORT : DllCanUnloadNow
OPTLINK : Error 81: Cannot EXPORT : DllGetClassObject
OPTLINK : Error 81: Cannot EXPORT : DllRegisterServer
OPTLINK : Error 81: Cannot EXPORT : DllUnregisterServer
--- errorlevel 8

Not, very pretty. Do I have something not setup right? Im using 
the latest DMD as of 8/25/2014. 2.066.0


Any Ideas?


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) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllGetClassObject
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllCanUnloadNow
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllRegisterServer
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllUnregisterServer

OPTLINK : Error 81: Cannot EXPORT : DllCanUnloadNow
OPTLINK : Error 81: Cannot EXPORT : DllGetClassObject
OPTLINK : Error 81: Cannot EXPORT : DllRegisterServer
OPTLINK : Error 81: Cannot EXPORT : DllUnregisterServer
--- errorlevel 8

Not, very pretty. Do I have something not setup right? Im using 
the latest DMD as of 8/25/2014. 2.066.0


Any Ideas?


So, I figured it out! I used the wrong example for mydll.def.

-
LIBRARY MYDLL
DESCRIPTION 'My DLL written in D'

EXETYPE NT
CODEPRELOAD DISCARDABLE
DATAWRITE

EXPORTS
DllGetClassObject   @2
DllCanUnloadNow @3
DllRegisterServer   @4
DllUnregisterServer @5
--
The above will cause errors: even though it makes you think that 
it should be mydll.def it is not.


--
LIBRARY mydll.dll
EXETYPE NT
SUBSYSTEM WINDOWS
CODE SHARED EXECUTE
DATA WRITE
--
The above is the correct .def contents

Thanks all!


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) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllGetClassObject
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllCanUnloadNow
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllRegisterServer
OPTLINK : Error 180: No Match Found for Export/ENTRY -  : 
DllUnregisterServer

OPTLINK : Error 81: Cannot EXPORT : DllCanUnloadNow
OPTLINK : Error 81: Cannot EXPORT : DllGetClassObject
OPTLINK : Error 81: Cannot EXPORT : DllRegisterServer
OPTLINK : Error 81: Cannot EXPORT : DllUnregisterServer
--- errorlevel 8

Not, very pretty. Do I have something not setup right? Im using 
the latest DMD as of 8/25/2014. 2.066.0


Any Ideas?


If you don't use the extern(C) foreign function interface then 
the name won't match to the export name as written in the source 
(in the binary you'll get the bytecount of all the param size 
with a @ before).
si you need to create a name table for optlink 
(http://www.digitalmars.com/ctg/ctgDefFiles.html)

(http://www.digitalmars.com/archives/cplusplus/4029.html)


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 str[0..strlen(str)].idup; //I have strlen defined for 
each *string

}

I was going to add some || sections for the other string types, 
but this one won't even compile.


src/dsfml/system/string.d(34): Error: found ')' when expecting 
'.' following dchar
src/dsfml/system/string.d(35): Error: found '{' when expecting 
identifier following 'dchar.'
src/dsfml/system/string.d(36): Error: found 'return' when 
expecting ')'
src/dsfml/system/string.d(36): Error: semicolon expected 
following function declaration
src/dsfml/system/string.d(36): Error: no identifier for 
declarator str[0 .. strlen(str)]
src/dsfml/system/string.d(36): Error: no identifier for 
declarator .idup

src/dsfml/system/string.d(37): Error: unrecognized declaration


It compiles if I remove the 'if(typeof(T) is dchar)' section. Any 
thoughts?


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 signature


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 function. here. i.e.: `if (is(T == 
dchar))`


Is its ability to be used as a function like this documented 
anywhere? I looked and could not find it.


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 only seen it as an 'obj1 is obj2' 
sort of way. Thanks much!


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 a real function here,
it's more like special predicate syntax.


signature.asc
Description: PGP signature


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 it.

http://dlang.org/concepts.html
template constraints is a special case. is not a real function 
here,

it's more like special predicate syntax.


Awesome! Thanks so much.


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 options in the context menus, and although it looks like 
drag an drop might work (a '+' sign appears by the cursor), 
dropping a file from the filesystem doesn't work either.


Although I dream of someday being able to add a reference to a 
project, I'm not really sure what I might drag in.  I managed to 
download and compile GtkD, since it seems like a GUI would be a 
nice place to start (again, old fashion).  I got three *.lib 
files out of it... H... Maybe these are references??


I had installed the Visual Studio plugin, but I don't want to use 
this since I would like to eventually migrate away from Windows.


Let me cut to the chase.  I have no friggin' clue how to start, 
and I can't seem to find a tutorial anywhere...


What IDE should I use? I'm not big fan of Eclipse, although if I 
had to use it this wouldn't be a dealbreaker.  Give me something 
easy and lightweight, unless you've got a GUI builder (this is 
why I started with MonoDevelop, though this isn't working so well 
for me).


What Widget library should I use?  I started with GTKD, but since 
there are no tutorials does this mean nobody actually does this?  
Should I use DWT?  What about QT?


I just want something simple and mainstream to start learning D 
with.


Any thoughts?



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.

 immutable(T)[] toString(T)(const(T)* str)
   if(typeof(T) is dchar)//this is where the error is
 {
   return str[0..strlen(str)].idup; //I have strlen defined for
 each *string
 }

 I was going to add some || sections for the other string types,
 but this one won't even compile.

 src/dsfml/system/string.d(34): Error: found ')' when expecting
 '.' following dchar
 src/dsfml/system/string.d(35): Error: found '{' when expecting
 identifier following 'dchar.'
 src/dsfml/system/string.d(36): Error: found 'return' when
 expecting ')'
 src/dsfml/system/string.d(36): Error: semicolon expected
 following function declaration
 src/dsfml/system/string.d(36): Error: no identifier for
 declarator str[0 .. strlen(str)]
 src/dsfml/system/string.d(36): Error: no identifier for
 declarator .idup
 src/dsfml/system/string.d(37): Error: unrecognized declaration


 It compiles if I remove the 'if(typeof(T) is dchar)' section. Any
 thoughts?

As the others have pointed out, you need to do is(T == dchar). The way you
used is the is operator and it checks for bitwise equality (most frequently
used for comparing pointers), and it's a runtime operation, whereas the is
that you need to use in a template constraint is an is expression, which is a
compile time operation:

http://dlang.org/expression.html#IsExpression

is expressions actually get pretty complicated in their various forms, but the
most basic two are probably is(T == dchar), which checks that the two types ar
the same, and is(T : dchar), which checks that T implictly converts to dchar.
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
is(someOtherType) is true, so it's frequently used to check whether something
is valid. The Phobos source code is littered with examples (especially in
std.algorithm, std.range, and std.traits), since is expressions are frequently
used in template constraints.

- Jonathan M Davis


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 as adding references to a project.  There 
are no options in the context menus, and although it looks like 
drag an drop might work (a '+' sign appears by the cursor), 
dropping a file from the filesystem doesn't work either.


Although I dream of someday being able to add a reference to a 
project, I'm not really sure what I might drag in.  I managed 
to download and compile GtkD, since it seems like a GUI would 
be a nice place to start (again, old fashion).  I got three 
*.lib files out of it... H... Maybe these are references??


I had installed the Visual Studio plugin, but I don't want to 
use this since I would like to eventually migrate away from 
Windows.


Let me cut to the chase.  I have no friggin' clue how to start, 
and I can't seem to find a tutorial anywhere...


What IDE should I use? I'm not big fan of Eclipse, although if 
I had to use it this wouldn't be a dealbreaker.  Give me 
something easy and lightweight, unless you've got a GUI builder 
(this is why I started with MonoDevelop, though this isn't 
working so well for me).


What Widget library should I use?  I started with GTKD, but 
since there are no tutorials does this mean nobody actually 
does this?  Should I use DWT?  What about QT?


I just want something simple and mainstream to start learning D 
with.


Any thoughts?


Mono-D + dub (see code.dlang.org) is the easiest way to get 
things working quickly. Mono-D has builtin support for dub.


For learning D, see Ali's book: 
http://ddili.org/ders/d.en/index.html (from scratch) or Andrei's 
The D Programming Language (for the more experienced). Adam D. 
Ruppe's D Cookbook also has interesting examples of usage.


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)* str)
   if(typeof(T) is dchar)//this is where the error is

The correct syntax is:

if (is(typeof(T) == dchar))

When comparing two values for equality (i.e., are these two values equal
to each other), use if (a == b).

When comparing two variables for identity (i.e., do these two references
point to the same data), use if (a is b).

When comparing two types, use is(A == B).


T

-- 
Verbing weirds language. -- Calvin ( Hobbes)


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 as adding references to a project.  There 
are no options in the context menus, and although it looks like 
drag an drop might work (a '+' sign appears by the cursor), 
dropping a file from the filesystem doesn't work either.


Although I dream of someday being able to add a reference to a 
project, I'm not really sure what I might drag in.  I managed 
to download and compile GtkD, since it seems like a GUI would 
be a nice place to start (again, old fashion).  I got three 
*.lib files out of it... H... Maybe these are references??


I had installed the Visual Studio plugin, but I don't want to 
use this since I would like to eventually migrate away from 
Windows.


Let me cut to the chase.  I have no friggin' clue how to start, 
and I can't seem to find a tutorial anywhere...


What IDE should I use? I'm not big fan of Eclipse, although if 
I had to use it this wouldn't be a dealbreaker.  Give me 
something easy and lightweight, unless you've got a GUI builder 
(this is why I started with MonoDevelop, though this isn't 
working so well for me).


What Widget library should I use?  I started with GTKD, but 
since there are no tutorials does this mean nobody actually 
does this?  Should I use DWT?  What about QT?


I just want something simple and mainstream to start learning D 
with.


Any thoughts?


I don't use an IDE, but MonoD seems to be the most recommended 
cross-platform option. It has a wiki page here if it helps: 
http://wiki.dlang.org/Mono-D


I recommend only using an IDE that uses DUB 
(http://code.dlang.org/about), which is becoming the de facto 
standard for building D projects, and is cross-IDE, allowing you 
to move between IDEs and to work with developers using other 
IDEs. MonoD probably uses this, as does DDT(Eclipse). I have no 
idea what interface MonoD or other IDEs offer for DUB, but DUB 
uses a 'dub.json' file where you specify libraries you use and 
their versions. DUB will automatically download the libraries 
when you compile the project. Available DUB packages 
(libraries/apps) are listed at http://code.dlang.org . That is 
probably also the best list of D libs we have at the moment, 
although many projects are not there yet.


Only use DWT if you like Java-style code. QtD is not in usable 
state yet. GtkD should be good, better for 'big' apps (i.e. more 
features), TkD for simple ones (simpler to use).



To learn about the language itself, this (free) book is really 
good:

http://ddili.org/ders/d.en/index.html


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 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


The correct syntax is:

if (is(typeof(T) == dchar))


Almost... T is already a type; typeof(T) doesn't compile.


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 avoid collections and make a 
good hybrid of manual management/collected code? The free lists in the 
GC engine look quite convenient to use. Any ideas?


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 regular 
function overloading that we already have.


Well any library solution has to do this at compile-time... I
assume the implementation would be similar, albeit easier 
because

the compiler would have all the necessary information directly
accessible.


This CAN NOT BE DONE at compile-time, since the compiler doesn't 
know at compile time the exact subclass of the instance it'll get 
at runtime. To clarify: I'm not talking about the creation of the 
multi-method mechanism - which *can* be done at compile-time - 
I'm talking about invoking that mechanism to determine which 
overload to call, and this can only be done at runtime.


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?


Is that not what would have to be done for a library solution in
this case, anyway?


If you look back, you'll notice this argument(and the two before 
it) was not against multi-methods at the language level - it was 
about multi-methods by default. If they are optional, 
instantiating all the overloads will only happen when it's used, 
so it won't be that bad.


Virtual methods in C can be done with GObject - though the 
syntax is awkward. D is so much better than C when it comes to 
metaprogramming, that the syntax for multimethods wouldn't be 
awkward(unless you consider anything that's not burned to the 
core syntax awkward)


Of course, I understand this. What I'm saying is that while it's
possible to do virtual method calls in C, the very fact that it
had to be implemented so awkwardly meant that a library solution
was not ideal. Now in D, the syntax is infinitely better, given.
Templates and compile-time code-generation are all really good.
But as I said, we have a lot of template bloat issues already.
Running 3 foreach-loops at compile-time every time that
template-function gets instantiated doesn't seem scalable to
me... Having something like this in the compiler, which has all
the required information available directly, seems like it'd be
the most scalable solution.


No one is trying to claim that a library implementation will be 
superior to a language-level solution in terms of speed, memory 
usage, binary size, compilation speed or syntax elegance. 
Language-level solutions can usually achieve better results in 
these regards. The problem is that they come with a price:


 * External tools needs to be modified to work with them.

 * 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 matter))


 * Risking regressions - changing the code will never be as 
orthogonal as changing the data it works on...


The point is that the usefulness of multi-methods, and the 
inconvenience of having as a library solution are not nearly big 
enough to pay that price.


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 still can't see why it would be wrong. Wouldn't it help 
avoid collections and make a good hybrid of manual 
management/collected code? The free lists in the GC engine look 
quite convenient to use. Any ideas?


delete was deprecated because it is memory unsafe (there may 
still be references to the memory). You can still use GC.free() 
to free the memory but it must only be used with care.


I feel if you are managing delete yourself you might as well 
manage allocation yourself too and take pressure off the GC. If 
you are sure you have only one reference and GC.free() is safe, 
Unique was probably a better choice anyway.


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 
matter))


 * Risking regressions - changing the code will never be as 
orthogonal as changing the data it works on...


The point is that the usefulness of multi-methods, and the 
inconvenience of having as a library solution are not nearly 
big enough to pay that price.


If we assume just double-dispatch over class-types and that you 
instantiate all functions first. Couldn't you then have this:


eat(virtual BaseBeing v, virtual BaseFood f,float amount){}
eat(virtual Human v, virtual Fruit f,float amount){]
eat(virtual Human v, virtual Stone f,float amount){}
eat(virtual Monster v, virtual Corpse f,float amount){}
eat(virtual Human v, virtual Corpse f,float amount){}

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?


Or maybe there are some hidden traps…


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 that all 
double-dispatch functions with the same name are located in the 
same file.


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 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
 
 The correct syntax is:
 
  if (is(typeof(T) == dchar))
 
 Almost... T is already a type; typeof(T) doesn't compile.

Ah, right, it should be simply: if (is(T == dchar))

Should've read more carefully before replying. :-P


T

-- 
It only takes one twig to burn down a forest.


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) `typeof(invalid)` is an error;
(b) the `is(...)` expression swallows errors;

hence (a)+(b) -

   static assert(is(typeof(invalid))==false);

artur


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 there is a problem in the latest version or something.


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()
{
}

Produces this error:

:!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
Failed: [dmd, -de, -debug, -w, -v, -o-, test.d, 
-I.]


Can anyone else confirm or am i doing something wrong. I'm using 
DMD 2.066.0 64bit Ubuntu 14.04.


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 
MonoD)


I just fire up a command line, go to my workspace folder, and do
dub init project name here

Then, in monoD, File - Open - C:\Path\To\Project\dub.json

Then your good to go regarding MonoD.



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()
 {
 }

Produces this error:

:!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
Failed: [dmd, -de, -debug, -w, -v, -o-, test.d, -I.]

Can anyone else confirm or am i doing something wrong. I'm using DMD
2.066.0 64bit Ubuntu 14.04.


isArray is defined in std.traits. I don't know why it doesn't work even 
though std.typecons does import it.


The workaround is to import it yourself in your program:

import std.traits;

Ali



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
Failed: [dmd, -de, -debug, -w, -v, -o-, test.d, 
-I.]


Can anyone else confirm or am i doing something wrong. I'm 
using DMD 2.066.0 64bit Ubuntu 14.04.


It stopped working after this PR was merged:

https://github.com/D-Programming-Language/phobos/pull/1899

But I suspect that something else is going on. The PR only 
introduced the call to `isArray` into `std.typecons.Proxy`.


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
 test.d(7): Error: mixin test.Foo.Proxy!(foo) error instantiating
 Failed: [dmd, -de, -debug, -w, -v, -o-, test.d, -I.]

 Can anyone else confirm or am i doing something wrong. I'm using DMD
 2.066.0 64bit Ubuntu 14.04.

 It stopped working after this PR was merged:

 https://github.com/D-Programming-Language/phobos/pull/1899

 But I suspect that something else is going on. The PR only introduced
 the call to `isArray` into `std.typecons.Proxy`.

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.


Ali



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! It works when I import std.traits first.

So... the fix is to import std.traits inside template Proxy. 
Going to submit a PR.


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 or whether it is 
a known limitation.


You're right, that's it! It works when I import std.traits 
first.


So... the fix is to import std.traits inside template Proxy. 
Going to submit a PR.


https://github.com/D-Programming-Language/phobos/pull/2463


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 
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 
avoid collections and make a good hybrid of manual 
management/collected code? The free lists in the GC engine 
look quite convenient to use. Any ideas?


delete was deprecated because it is memory unsafe (there may 
still be references to the memory). You can still use GC.free() 
to free the memory but it must only be used with care.


I feel if you are managing delete yourself you might as well 
manage allocation yourself too and take pressure off the GC. If 
you are sure you have only one reference and GC.free() is safe, 
Unique was probably a better choice anyway.


Actually, delete hasn't technically been deprecated yet even 
though it was supposed to be, which is part of the problem. If it 
were, presumably folks would stop using it.


But yeah, the key problem is that deleting GCed memory is 
inherently unsafe. You can get away with it if you know for sure 
that there are no other references to that object, but if you 
screw it up, nasty things will happen. Normally, using the GC is 
supposed to guarantee memory safety, and freeing GC memory 
yourself negates that.


And as you point out, you really don't gain much by using the GC 
if you're going to be deleting stuff yourself. At that point, you 
might as well be managing the memory yourself. The main 
impediment there is the fact that we don't currently have a nice 
way to construct objects on the heap without new. After the 
memory is malloced, you need to use emplace to construct the 
object in that memory, and that gets complicated. However, once 
we have the custom allocators, that problem should go away, 
because then we should be able to do something like


auto foo = alloc.foo!Foo(arg1, arg2);

and all of the emplace pain will be dealt with for you. So, until 
we have that, I can see why someone would want to use delete, but 
it's inherently unsafe, and we really need to get it deprecated 
and then removed.


- Jonathan M Davis


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 couldnt figure it out either tbh (creating dub projects using 
MonoD)


I just fire up a command line, go to my workspace folder, and do
dub init project name here

Then, in monoD, File - Open - C:\Path\To\Project\dub.json

Then your good to go regarding MonoD.



Yeah, I gave up on MonoD to try and figure out what is going on 
behind the scenes by compiling with text files... I had a little 
success compiling, followed by a failure to run because I don't 
have the right version of GTK+ on my system...


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 tried 
removing package references


I tried dub remove gtk-d --version=* but it just lists out 
excuses why it can't work... no retrieval journal found for..., 
Untracked file found


So then I try every variation of dub remove-local and dub 
remove-path I can think of.


I give up.  Why not just have a dub 
-IFuckedUpSoLetsStartOverCleanSlated option?








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, RefCountedAutoInitialize autoInit = 
RefCountedAutoInitialize.yes) if (!is(T == 
class))	C:\Users\Nutzer\Windows Ordner\Documents\Visual Studio 
2013\Projects\RefCountedScratch\RefCountedScratch\main.d	26	


I tried many things, but nothing did it. Any help appreciated :-).
Thanks, Bienlein


import std.stdio;
import std.typecons;

struct Payload
{
private int num = 0;

this(int i)
{
num = i;
writefln(Payload's constructor called);
}

~this()
{
 writefln(Payload's destructor called);
}
}



int main(string[] argv)
{
alias RefCounted!(Payload, RefCountedAutoInitialize.yes) Data;

int bar = 12;
Data data = Data(bar);

return 0;
}


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 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! It works when I import std.traits first.

So... the fix is to import std.traits inside template Proxy. Going to
submit a PR.


https://github.com/D-Programming-Language/phobos/pull/2463


Thanks! And I learned from you in the pull request the following fact:

quote
Quoting http://dlang.org/template-mixin :
Unlike a template instantiation, a template mixin's body is evaluated 
within the scope where the mixin appears, not where the template 
declaration is defined. It is analogous to cutting and pasting the body 
of the template into the location of the mixin.

/quote

Ali



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 still can't see why it would be wrong. Wouldn't it help 
avoid collections and make a good hybrid of manual 
management/collected code? The free lists in the GC engine look 
quite convenient to use. Any ideas?


Until custom class de/allocators are not really deprecated, 
the delete keyword is not necessarly deleting from the GC. 
Look at this:


http://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation

You can do the same but without adding the class reference to the 
GC. Then delete will call the custom deallocator which is itself 
not calling the GC.


So in a way I think you're right when you say that delete could 
help into manual mem managment. But that's not a reliable (over 
time) situation.




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 tried removing package references


I tried dub remove gtk-d --version=* but it just lists out 
excuses why it can't work... no retrieval journal found 
for..., Untracked file found


Why you try removing from dub something you have manually cloned? 
It is not even aware of local gtk-d copy if you just cloned with 
registering local path.


Expected approach is to create a new dub project and add gtk-d to 
dependencies - rest is up to how well-maintained gtk-d itself is.


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? 
http://www.haskell.org/haskellwiki/99_questions/1_to_10


Well, you could port 99 lisp problems to D - D can be written 
in a fairly functional style ;)


I am just trying to learn D by writing code. Of course I could 
just do them in D but I would like to compare my version with 
idiomatic D.


It's actually quite strange that no one has done something like 
this in D, it's usually the first thing people do.


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 have some very 
unique and beautiful range-based D solutions.


import std.algorithm;
import std.range;
import std.stdio;

alias fold = std.functional.binaryReverseArgs!(reduce!((n1, n2) 
= n1 + n2));

enum limit = 4_000_000;

void main()
{
recurrence!q{a[n-1] + a[n-2]}(1, 1)
.take(1000)
.filter!(n = n = 0  n  limit  n % 2 == 0)
.sum.writeln;
}


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 have some 
very unique and beautiful range-based D solutions.


import std.algorithm;
import std.range;
import std.stdio;

alias fold = std.functional.binaryReverseArgs!(reduce!((n1, n2) 
= n1 + n2));

enum limit = 4_000_000;

void main()
{
recurrence!q{a[n-1] + a[n-2]}(1, 1)
.take(1000)
.filter!(n = n = 0  n  limit  n % 2 == 0)
.sum.writeln;
}


Whoops, wrong code. Also, this is the answer to PE problem 2.

import std.algorithm;
import std.range;
import std.stdio;

enum limit = 4_000_000;

void main()
{
recurrence!q{a[n-1] + a[n-2]}(1, 1)
.take(1000)
.filter!(n = n = 0  n  limit  n % 2 == 0)
.sum
.writeln;
}


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;

ref auto opIndex(size_t idx) {
assert(idx = 0  idx  length, Bounds error on index);
return v[idx];
}
auto opAssign(float[] f) {
assert(f.length == length, Bounds error on assignment);
v[0..length] = f[0..length];
return this;
}
}

vec2 a = vec2(1.0, 2.0); // fine
vec2 b;
b = [3.0, 4.0]; //fine
vec2 c = [5.0, 6.0]; // cannot cast float[] to vec2


Overloading opCast() seems to be only for outbound casting, and
unions can't have this() constructors like structs.  Is there any
way to accomplish this?


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 the trick.
i.e. int myfunc (int  n) -- int myfunc() (int n).

but this is a hack, of course.


signature.asc
Description: PGP signature


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 generation in C++ compilers.
i think that turning your functions into templates should do 
the trick.

i.e. int myfunc (int  n) -- int myfunc() (int n).

but this is a hack, of course.


No template hack needed now.
https://issues.dlang.org/show_bug.cgi?id=10985


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