Re: MD5 hash on a file and rawRead

2011-02-10 Thread Lars T. Kyllingstad
On Wed, 09 Feb 2011 23:01:47 -0500, Andrej Mitrovic wrote: I'm trying to use the std.md5.sum method. It takes as an argument a digest to output the hash to, and the second argument is plain data. So I'm trying to read an entire file at once. I thought about using rawRead, but I get a

How to web programming with D2?

2011-02-10 Thread canalpay
I am trying to write the web framework(but not to write, to gain experience.). Maybe the framework can has got a MVC desing pattern. But first, the D2 is not has got for the web library and I am decided write to library for web. I am writed a function for post and get methods. (I am not tried

Re: How to web programming with D2?

2011-02-10 Thread Lars T. Kyllingstad
On Thu, 10 Feb 2011 04:29:21 -0500, canalpay wrote: I am trying to write the web framework(but not to write, to gain experience.). Maybe the framework can has got a MVC desing pattern. But first, the D2 is not has got for the web library and I am decided write to library for web. I am

Dynamic and Static Casting

2011-02-10 Thread d coder
Greetings All I have learnt that D has only one casting operator and that is 'cast'. The same operator assumes different functionality depending on the context in which it he being used. Now I have a situation where I have to downcast an object and I am sure of the objects type and thereby I am

Re: Dynamic and Static Casting

2011-02-10 Thread bearophile
d coder: I have learnt that D has only one casting operator and that is 'cast'. The same operator assumes different functionality depending on the context in which it he being used. Walter likes this design, I presume he thinks it's simpler. Now I have a situation where I have to downcast

Re: Dynamic and Static Casting

2011-02-10 Thread Lars T. Kyllingstad
On Thu, 10 Feb 2011 11:54:02 +, Lars T. Kyllingstad wrote: On Thu, 10 Feb 2011 16:44:12 +0530, d coder wrote: Greetings All I have learnt that D has only one casting operator and that is 'cast'. The same operator assumes different functionality depending on the context in which it he

Re: Invoke garbage collector?

2011-02-10 Thread spir
On 02/09/2011 10:15 PM, Steven Schveighoffer wrote: On Wed, 09 Feb 2011 15:58:13 -0500, bearophile bearophileh...@lycos.com wrote: Sean Eskapp: so is there a way to invoke a GC cleanup in some way? http://www.digitalmars.com/d/2.0/phobos/core_memory.html#minimize This attempts to

Re: Dynamic and Static Casting

2011-02-10 Thread bearophile
Lars T. Kyllingstad: Ok, bearophile's solution is better, because it has fewer casts. And your solution was better because it's inside a function :-) I forgot you can cast to void*. So here's an improved version, with some template constraints to make sure it's only used for class types:

opIn_r not detected

2011-02-10 Thread spir
Hello, Implicite deref of struct pointers on member access works fine for data, methods, even special methods with language semantics like opEquals (see example below). But I cannot have 'in' work with method opIn_r. I get: Error: rvalue of in expression must be an associative array, not

Re: Dynamic and Static Casting

2011-02-10 Thread d coder
Thanks Lars and Bearophile, I will give it a try. I understand that static downcasting is dangerous. But there are places where efficiency is paramount and you are sure that the casting is safe. So I wholeheartedly second your proposal to have the stuff in phobos. Regards - Cherry

Re: Invoke garbage collector?

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 07:34:53 -0500, spir denis.s...@gmail.com wrote: On 02/09/2011 10:15 PM, Steven Schveighoffer wrote: On Wed, 09 Feb 2011 15:58:13 -0500, bearophile bearophileh...@lycos.com wrote: Sean Eskapp: so is there a way to invoke a GC cleanup in some way?

Re: Dynamic and Static Casting

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 08:02:08 -0500, d coder dlang.co...@gmail.com wrote: Thanks Lars and Bearophile, I will give it a try. I understand that static downcasting is dangerous. But there are places where efficiency is paramount and you are sure that the casting is safe. So I wholeheartedly second

Re: Template for function or delegate (nothing else)

2011-02-10 Thread spir
On 02/09/2011 11:05 PM, Steven Schveighoffer wrote: On Wed, 09 Feb 2011 16:41:25 -0500, useo u...@start.bg wrote: == Auszug aus bearophile (bearophileh...@lycos.com)'s Artikel useo: I just have a problem with my variables. For example... my class/template just looks like: class

Re: opIn_r not detected

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 07:59:06 -0500, spir denis.s...@gmail.com wrote: Hello, Implicite deref of struct pointers on member access works fine for data, methods, even special methods with language semantics like opEquals (see example below). But I cannot have 'in' work with method opIn_r. I

Re: Template for function or delegate (nothing else)

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 08:39:13 -0500, spir denis.s...@gmail.com wrote: On 02/09/2011 11:05 PM, Steven Schveighoffer wrote: I don't think you want templates. What you want is a tagged union (and a struct is MUCH better suited for this): // untested! struct Example { private { bool

Re: Invoke garbage collector?

2011-02-10 Thread Johannes Pfau
Sean Eskapp wrote: I'm having an unfortunate DSFML issue, where failing to free objects like Images or Sprites causes exceptions to eventually be thrown. Calling the built-in member dispose() causes access violations, so I assume it's not for programmer use. However, I need the resources to be

Re: Invoke garbage collector?

2011-02-10 Thread Johannes Pfau
Johannes Pfau wrote: Sean Eskapp wrote: I'm having an unfortunate DSFML issue, where failing to free objects like Images or Sprites causes exceptions to eventually be thrown. Calling the built-in member dispose() causes access violations, so I assume it's not for programmer use. However, I need

Re: Template for function or delegate (nothing else)

2011-02-10 Thread useo
I implemented all I wanted and it works perfectly ;). But I'm using the if (is(T == delegate) || is(T == function))- statement in another class/template. class Example(T) if (is(T == delegate) || is(T == function)) { ... } Now, when I declare Example!(void function()) myVar; I always get:

Re: Template for function or delegate (nothing else)

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 09:09:03 -0500, useo u...@start.bg wrote: I implemented all I wanted and it works perfectly ;). But I'm using the if (is(T == delegate) || is(T == function))- statement in another class/template. class Example(T) if (is(T == delegate) || is(T == function)) { ... } Now,

Re: Template for function or delegate (nothing else)

2011-02-10 Thread useo
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Thu, 10 Feb 2011 09:09:03 -0500, useo u...@start.bg wrote: I implemented all I wanted and it works perfectly ;). But I'm using the if (is(T == delegate) || is(T == function))- statement in another class/template.

Re: Template for function or delegate (nothing else)

2011-02-10 Thread useo
== Auszug aus useo (u...@start.bg)'s Artikel == Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Thu, 10 Feb 2011 09:09:03 -0500, useo u...@start.bg wrote: I implemented all I wanted and it works perfectly ;). But I'm using the if (is(T == delegate) || is(T ==

Re: Template for function or delegate (nothing else)

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 09:48:14 -0500, useo u...@start.bg wrote: I created a complete, new file with the following code: module example; void main(string[] args) { Example!(void function()) myVar; } class Example(T) if (is(T == delegate) || is(T == function)) { } And what I get is:

Re: Template for function or delegate (nothing else)

2011-02-10 Thread useo
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel On Thu, 10 Feb 2011 09:48:14 -0500, useo u...@start.bg wrote: I created a complete, new file with the following code: module example; void main(string[] args) { Example!(void function()) myVar; } class

Re: Dynamic and Static Casting

2011-02-10 Thread spir
On 02/10/2011 01:38 PM, bearophile wrote: Lars T. Kyllingstad: Ok, bearophile's solution is better, because it has fewer casts. And your solution was better because it's inside a function :-) I forgot you can cast to void*. So here's an improved version, with some template constraints to

Re: MD5 hash on a file and rawRead

2011-02-10 Thread Andrej Mitrovic
On 2/10/11, Lars T. Kyllingstad public@kyllingen.nospamnet wrote: To read an entire file at once, you should use std.file.read(), or std.file.readText() if it's an UTF encoded text file. I missed that method while browsing through the docs. Thanks. There are actually three modules for file

Re: Dynamic and Static Casting

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 11:38:40 -0500, spir denis.s...@gmail.com wrote: On 02/10/2011 01:38 PM, bearophile wrote: Is a pair of similar staticDownCast(), staticUpCast() fit for Phobos? But I have never needed upcast in D as of now. What are common use cases? Aren't all upcasts static

foreach over string enum

2011-02-10 Thread Nrgyzer
Hey guys, I'm trying to iterate over an enumeration which contains strings like the this: enum FileName : string { file1 = file1.ext, file2 = file2.ext } I already found this article: http://lists.puremagic.com/pipermail/ digitalmars-d/2007-July/021920.html but it's an enum which contains

Re: Template for function or delegate (nothing else)

2011-02-10 Thread spir
On 02/10/2011 02:51 PM, Steven Schveighoffer wrote: On Thu, 10 Feb 2011 08:39:13 -0500, spir denis.s...@gmail.com wrote: On 02/09/2011 11:05 PM, Steven Schveighoffer wrote: I don't think you want templates. What you want is a tagged union (and a struct is MUCH better suited for this): //

Re: opIn_r not detected

2011-02-10 Thread spir
On 02/10/2011 02:39 PM, Steven Schveighoffer wrote: On Thu, 10 Feb 2011 07:59:06 -0500, spir denis.s...@gmail.com wrote: Hello, Implicite deref of struct pointers on member access works fine for data, methods, even special methods with language semantics like opEquals (see example below). But

Re: Template for function or delegate (nothing else)

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 12:04:28 -0500, spir denis.s...@gmail.com wrote: On 02/10/2011 02:51 PM, Steven Schveighoffer wrote: On Thu, 10 Feb 2011 08:39:13 -0500, spir denis.s...@gmail.com wrote: On 02/09/2011 11:05 PM, Steven Schveighoffer wrote: I don't think you want templates. What you want

Re: foreach over string enum

2011-02-10 Thread Jesse Phillips
Nrgyzer Wrote: Hey guys, I'm trying to iterate over an enumeration which contains strings like the this: enum FileName : string { file1 = file1.ext, file2 = file2.ext } I already found this article: http://lists.puremagic.com/pipermail/ digitalmars-d/2007-July/021920.html but it's

Re: foreach over string enum

2011-02-10 Thread Nrgyzer
== Auszug aus Jesse Phillips (jessekphillip...@gmail.com)'s Artikel Nrgyzer Wrote: Hey guys, I'm trying to iterate over an enumeration which contains strings like the this: enum FileName : string { file1 = file1.ext, file2 = file2.ext } I already found this article:

Re: std.concurrency immutable classes...

2011-02-10 Thread Tomek Sowiński
Michel Fortin napisał: Thanks for doing this. Is it approved by Walter? Depends on what you mean by approved. He commented once on the newsgroup after I posted an earlier version of the patch, saying I should add tests for type deduction and some other stuff. This change his

Re: std.concurrency immutable classes...

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 14:45:14 -0500, Tomek Sowiński j...@ask.me wrote: Michel Fortin napisał: Thanks for doing this. Is it approved by Walter? Depends on what you mean by approved. He commented once on the newsgroup after I posted an earlier version of the patch, saying I should add tests

Re: foreach over string enum

2011-02-10 Thread spir
On 02/10/2011 08:22 PM, Jesse Phillips wrote: Nrgyzer Wrote: Hey guys, I'm trying to iterate over an enumeration which contains strings like the this: enum FileName : string { file1 = file1.ext, file2 = file2.ext } I already found this article: http://lists.puremagic.com/pipermail/

Re: foreach over string enum

2011-02-10 Thread Jesse Phillips
spir Wrote: On 02/10/2011 08:22 PM, Jesse Phillips wrote: enum FileName : string { file1 = file1.ext, file2 = file2.ext } void main(string args[]) { foreach(a; __traits(allMembers, FileName)) writeln(mixin(FileName. ~ a)); } Why the mixin? Is it (just) to

Re: opIn_r not detected

2011-02-10 Thread spir
On 02/10/2011 07:43 PM, Stewart Gordon wrote: On 10/02/2011 12:59, spir wrote: Hello, Implicite deref of struct pointers on member access works fine for data, methods, even special methods with language semantics like opEquals (see example below). But I cannot have 'in' work with method

Re: foreach over string enum

2011-02-10 Thread Ali Çehreli
I don't have answers to your other questions. On 02/10/2011 03:25 PM, spir wrote: unittest { auto i = 1; auto s = i; It works if you define s as: enum s = i; writeln(mixin(i)); // compiler happy up to here -- 1 writeln(mixin(s)); // compiler unhappy -- Error: argument to mixin //

Assert compilation failure with certain message

2011-02-10 Thread Tomek Sowiński
Is there a way to statically assert compilation of an expression failed *with a certain message*? I want to check my static asserts trip when they should. -- Tomek

Re: Assert compilation failure with certain message

2011-02-10 Thread bearophile
Tomek Sowiñski: Is there a way to statically assert compilation of an expression failed *with a certain message*? I want to check my static asserts trip when they should. I have asked something like this a lot of time ago, but I don't know a way to do it. You are able to statically assert

Re: foreach over string enum

2011-02-10 Thread spir
On 02/11/2011 01:02 AM, Ali Çehreli wrote: I don't have answers to your other questions. On 02/10/2011 03:25 PM, spir wrote: unittest { auto i = 1; auto s = i; It works if you define s as: enum s = i; writeln(mixin(i)); // compiler happy up to here -- 1 writeln(mixin(s)); //

Re: Assert compilation failure with certain message

2011-02-10 Thread Jonathan M Davis
On Thursday, February 10, 2011 16:12:01 Tomek Sowiński wrote: Is there a way to statically assert compilation of an expression failed *with a certain message*? I want to check my static asserts trip when they should. You mean like static assert(0, We have a failure, Captain!); If a static

Re: Assert compilation failure with certain message

2011-02-10 Thread Tomek Sowiński
bearophile napisał: Is there a way to statically assert compilation of an expression failed *with a certain message*? I want to check my static asserts trip when they should. I have asked something like this a lot of time ago, but I don't know a way to do it. You are able to

Re: Assert compilation failure with certain message

2011-02-10 Thread Andrej Mitrovic
How's this? import std.stdio; import std.conv; void staticAssert(alias exp, string message, string file = __FILE__, int line = __LINE__)() { static if (!exp) { pragma(msg, file ~ :( ~ to!string(line) ~ ) ~ staticAssert: ~ to!string(message)); assert(0); } } void

Re: Assert compilation failure with certain message

2011-02-10 Thread Andrej Mitrovic
I've managed to screw up the colon placement though, here's a quick fix: import std.stdio; import std.conv; void staticAssert(alias exp, string message, string file = __FILE__, int line = __LINE__)() { static if (!exp) { pragma(msg, file ~ ( ~ to!string(line) ~ ): ~

Re: Assert compilation failure with certain message

2011-02-10 Thread bearophile
Tomek S.: Static catch, yeah. But I'd be content with traits__(fails, expr, msg) which seems tractable. Asking for new features in this newsgroup is not so useful. You may add it to bugzilla... Bye, bearophile

Re: foreach over string enum

2011-02-10 Thread Jesse Phillips
spir Wrote: But in your example the symbol a does not look like a constant, instead it the loop variable. Do, how does it work? Magic. No really, the best I can tell is that the compiler will try to run the foreach loop at compile-time if there is something in the body that must be

Re: How to web programming with D2?

2011-02-10 Thread Stephan Soller
On 10.02.2011 10:29, canalpay wrote: I am trying to write the web framework(but not to write, to gain experience.). Maybe the framework can has got a MVC desing pattern. But first, the D2 is not has got for the web library and I am decided write to library for web. I am writed a function for