Re: Understanding the GC

2013-01-30 Thread Mike Parker
On Wednesday, 30 January 2013 at 06:00:44 UTC, Jeremy DeHaan wrote: From what I understand, when an object is recovered by the GC, the destructor may or may not be called. Why is that? Is it for That's not quite correct. When the object is collected, its destructor will be called. But you

Re: Understanding the GC

2013-01-30 Thread Mike Parker
The take-home point of all of this is that you shouldn't rely on destructors for resource deallocation. You could do it in by manually destructing objects when you are finished with them (via the destroy() method), but then you have to be extra careful about class members, ownership, order of

Re: Why is the 'protected' attribute considered useless?

2013-01-30 Thread simendsjo
On Wednesday, 30 January 2013 at 03:38:39 UTC, Chad Joan wrote: I've read more than once now that 'protected' is considered useless in D. Why is this? I'm not sure what articles you are referring to, but a couple of points it might think of: * Anything protected can be made public by derived

Re: Why is the 'protected' attribute considered useless?

2013-01-30 Thread Don
On Wednesday, 30 January 2013 at 03:38:39 UTC, Chad Joan wrote: I've read more than once now that 'protected' is considered useless in D. Why is this? I've never heard that before. Where have you read that? Several people, including me, have said that 'package' is useless -- could that be

Re: try to compile githubs dmd-master zip with vstudio 2010

2013-01-30 Thread Namespace
On Wednesday, 30 January 2013 at 05:39:03 UTC, dennis luehring wrote: Am 27.01.2013 15:08, schrieb Namespace: You mean the Visual Studio solution? I tried it also, but for me only the solution above works fine. I asked for that problem here:

Re: Understanding the GC

2013-01-30 Thread monarch_dodra
On Wednesday, 30 January 2013 at 08:15:15 UTC, Mike Parker wrote: On Wednesday, 30 January 2013 at 06:00:44 UTC, Jeremy DeHaan wrote: From what I understand, when an object is recovered by the GC, the destructor may or may not be called. Why is that? Is it for That's not quite correct.

Re: Why is the 'protected' attribute considered useless?

2013-01-30 Thread Regan Heath
On Wed, 30 Jan 2013 09:20:54 -, simendsjo simend...@gmail.com wrote: On Wednesday, 30 January 2013 at 03:38:39 UTC, Chad Joan wrote: I've read more than once now that 'protected' is considered useless in D. Why is this? ... * private and protected in D works at module scope, not class

Re: Why is the 'protected' attribute considered useless?

2013-01-30 Thread Dicebot
On Wednesday, 30 January 2013 at 03:38:39 UTC, Chad Joan wrote: I've read more than once now that 'protected' is considered useless in D. Why is this? In my opinion this is because implementation inheritance is not idiomatic for D and lot of people may never encounter practical need to use

Re: Why is the 'protected' attribute considered useless?

2013-01-30 Thread David
Am 30.01.2013 04:38, schrieb Chad Joan: I've read more than once now that 'protected' is considered useless in D. Why is this? Tbh, I would consider everything else other than public useless. It's part of the user to use things according to the documentation and there are conrnercases where

Re: Is there a string remove method, that takes an index

2013-01-30 Thread FG
On 2013-01-30 04:27, Ali Çehreli wrote: s = s[0..7] ~ s[8..$]; As with the other slicing approaches, it would be best to check first if s.length = i (with i = 8 in this case).

Re: Understanding the GC

2013-01-30 Thread Maxim Fomin
On Wednesday, 30 January 2013 at 10:29:26 UTC, monarch_dodra wrote: On Wednesday, 30 January 2013 at 08:15:15 UTC, Mike Parker wrote: Destructors of members will not be called when an object is collected. Only that of the object itself. But, there's no guarantee that any member references will

Re: Understanding the GC

2013-01-30 Thread monarch_dodra
On Wednesday, 30 January 2013 at 11:57:01 UTC, Maxim Fomin wrote: On Wednesday, 30 January 2013 at 10:29:26 UTC, monarch_dodra wrote: On Wednesday, 30 January 2013 at 08:15:15 UTC, Mike Parker wrote: Destructors of members will not be called when an object is collected. Only that of the object

Re: Understanding the GC

2013-01-30 Thread Maxim Fomin
On Wednesday, 30 January 2013 at 12:08:07 UTC, monarch_dodra wrote: On Wednesday, 30 January 2013 at 11:57:01 UTC, Maxim Fomin wrote: On Wednesday, 30 January 2013 at 10:29:26 UTC, monarch_dodra wrote: On Wednesday, 30 January 2013 at 08:15:15 UTC, Mike Parker wrote: Destructors of members

Re: Understanding the GC

2013-01-30 Thread monarch_dodra
On Wednesday, 30 January 2013 at 12:17:33 UTC, Maxim Fomin wrote: English is not native for me. Sometimes non-natives misunderstand the meaning of the words. My apologies.

Re: Tutorial on how to build DMD/druntime/phobos and docs from source?

2013-01-30 Thread timewulf
On 29.01.2013 21:25, Philippe Sigaud wrote: On Mon, Jan 28, 2013 at 10:14 PM, H. S. Teoh hst...@quickfur.ath.cx wrote: On Mon, Jan 28, 2013 at 09:24:46PM +0100, Philippe Sigaud wrote: Besides the wiki, see: https://xtzgzorex.wordpress.com/2011/07/31/d-building-dmd-and-phobos-on-linux/ Would

Sorted output from an associative array

2013-01-30 Thread FG
Let's say i have an array: int[string] wordCount. How to print key:value pairs ordered by descending value? Or generally how to to store wordCount in an array of structs or type tuples for later sorting? In Python I would use something like this: sorted(wordCount.items(), key=lambda a: a[1],

Variadic constructor conflict

2013-01-30 Thread andrea9940
This code compiles fine: struct Vector(T, uint SIZE) { T[SIZE] vector; this(T value) { foreach (ref v; vector) v = value; } } alias Vector!(int, 3) Vec3i; but if I add a variadic constructor: struct Vector(T, uint

Re: Sorted output from an associative array

2013-01-30 Thread bearophile
FG: Let's say i have an array: int[string] wordCount. That's an associative array, and it's unsorted just like a Python dict. In Phobos there is a sorted tree, if you want, that keeps keys sorted. How to print key:value pairs ordered by descending value? There are various solutions.

Re: Sorted output from an associative array

2013-01-30 Thread monarch_dodra
On Wednesday, 30 January 2013 at 15:43:21 UTC, FG wrote: Let's say i have an array: int[string] wordCount. How to print key:value pairs ordered by descending value? Or generally how to to store wordCount in an array of structs or type tuples for later sorting? In Python I would use something

Re: Sorted output from an associative array

2013-01-30 Thread bearophile
Tuple!(string, int)[] items; foreach (k, v; wordCount) items ~= tuple(k, v); items.schwartzSort!(it = it[1], a b)(); A little tested: import std.stdio, std.algorithm, std.typecons; void main() { uint[string] wordCount = [the:200, val:100, blue:1000]; auto items = new

Fastq reader

2013-01-30 Thread bioinfornatics
Dear, I have wrote anither fastq reader: http://dpaste.dzfl.pl/2a7885dd Example of Fastq File-- @H8:C16L5ACXX:8:1101:1168:2103/1 TCTGAAGGCATGCTGCAATTGTGAATGGCAGAAATGT + ?@@DDDBDAFDF@4CFGICFHHECHEEBF;E@FFFG @H8:C16L5ACXX:8:1101:1223:2104/1

Re: Sorted output from an associative array

2013-01-30 Thread monarch_dodra
On Wednesday, 30 January 2013 at 16:22:37 UTC, monarch_dodra wrote: On Wednesday, 30 January 2013 at 15:43:21 UTC, FG wrote: Let's say i have an array: int[string] wordCount. How to print key:value pairs ordered by descending value? Or generally how to to store wordCount in an array of structs

Re: Sorted output from an associative array

2013-01-30 Thread FG
Thanks for showing me how to use tuples in this problem. Just for the record, the sort comparison should be reversed: a b.

Re: Adding more information to exceptions

2013-01-30 Thread Vladimir Panteleev
On Tuesday, 29 January 2013 at 20:37:07 UTC, Andrej Mitrovic wrote: On 1/29/13, Vladimir Panteleev vladi...@thecybershadow.net wrote: foreach (lineNumber, line; lines) try numbers ~= to!int(line); catch (Exception e) throw new Exception(format(Error on line %d: %s,

Re: Variadic constructor conflict

2013-01-30 Thread Simen Kjaeraas
On 2013-01-30, 17:08, andrea9940 wrote: This code compiles fine: struct Vector(T, uint SIZE) { T[SIZE] vector; this(T value) { foreach (ref v; vector) v = value; } } alias Vector!(int, 3) Vec3i; but if I add a variadic

Re: No mixin inside asm blocks

2013-01-30 Thread Philippe Sigaud
On Wed, Jan 30, 2013 at 4:01 PM, Ali Çehreli acehr...@yahoo.com wrote: A friend of mine is trying to figure out the D equivalent of using macros with asm blocks in C: #define NEXT() __asm__(jmp *%0::r((++ip)-jmp)); goto *ip-jmp D's asm blocks are very restrictive: mixins are not allowed.

Re: Variadic constructor conflict

2013-01-30 Thread andrea9940
Aw

Re: No mixin inside asm blocks

2013-01-30 Thread Ali Çehreli
On 01/30/2013 11:08 AM, Philippe Sigaud wrote: On Wed, Jan 30, 2013 at 4:01 PM, Ali Çehreliacehr...@yahoo.com wrote: A friend of mine is trying to figure out the D equivalent of using macros with asm blocks in C: #define NEXT() __asm__(jmp *%0::r((++ip)-jmp)); goto *ip-jmp D's asm

Re: Adding more information to exceptions

2013-01-30 Thread Jesse Phillips
On Tuesday, 29 January 2013 at 21:53:46 UTC, Ali Çehreli wrote: On 01/29/2013 12:32 PM, Vladimir Panteleev wrote: I would like to add some information to any exceptions thrown inside the loop's body (e.g. whatever std.conv.to may throw), in our case the line number. Here is a RAII idea that

Re: Adding more information to exceptions

2013-01-30 Thread Ali Çehreli
On 01/30/2013 12:05 PM, Jesse Phillips wrote: On Tuesday, 29 January 2013 at 21:53:46 UTC, Ali Çehreli wrote: Here is a RAII idea that takes advantage of exception chaining without directly using the 'next' parameter. umm, so why can't using next directly be valid? The OP had quoted the

Re: Adding more information to exceptions

2013-01-30 Thread Jonathan M Davis
On Wednesday, January 30, 2013 12:58:10 Ali Çehreli wrote: On 01/30/2013 12:05 PM, Jesse Phillips wrote: On Tuesday, 29 January 2013 at 21:53:46 UTC, Ali Çehreli wrote: Here is a RAII idea that takes advantage of exception chaining without directly using the 'next' parameter. umm, so

unnecessary casts

2013-01-30 Thread Namespace
Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? E.g. [code] void foo(T)(T num) { int f = cast(int) num; // ... } foo(42); // cast is unnecessary foo(4.2); // cast is necessary [/code] Or should I wrote everytime [code] void foo(T)(T num) { static if (is(T ==

Re: unnecessary casts

2013-01-30 Thread bearophile
On Wednesday, 30 January 2013 at 22:49:01 UTC, Namespace wrote: Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? I think the most important casts most worth avoiding are the ones you write in the code (because they are a source of bugs), not the ones the compiler

Looking for command for synchronization of threads

2013-01-30 Thread Sparsh Mittal
Background: I am implementing an iterative algorithm in parallel manner. The algorithm iteratively updates a matrix (2D grid) of data. So, I will divide the grid to different threads, which will work on it for single iteration. After each iteration, all threads should wait since next

Re: unnecessary casts

2013-01-30 Thread Namespace
On Wednesday, 30 January 2013 at 22:57:39 UTC, bearophile wrote: On Wednesday, 30 January 2013 at 22:49:01 UTC, Namespace wrote: Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? I think the most important casts most worth avoiding are the ones you write in the code

Re: unnecessary casts

2013-01-30 Thread Jonathan M Davis
On Wednesday, January 30, 2013 23:49:00 Namespace wrote: Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? E.g. [code] void foo(T)(T num) { int f = cast(int) num; // ... } foo(42); // cast is unnecessary foo(4.2); // cast is necessary [/code] Or should I

Re: Looking for command for synchronization of threads

2013-01-30 Thread Sean Kelly
On Jan 30, 2013, at 2:58 PM, Sparsh Mittal sparsh0mit...@gmail.com wrote: Background: I am implementing an iterative algorithm in parallel manner. The algorithm iteratively updates a matrix (2D grid) of data. So, I will divide the grid to different threads, which will work on it for single

Re: unnecessary casts

2013-01-30 Thread bearophile
Namespace: I'm talking about exactly these kind of casts. See my example. I don't understand what you are trying to minimize. In both versions of your foo function you have 1 cast, so you aren't minimizing the number of casts you are writing in the code. Bye, bearophile

Re: Adding more information to exceptions

2013-01-30 Thread Andrej Mitrovic
On 1/30/13, Jonathan M Davis jmdavisp...@gmx.com wrote: The next parameter is used internally and should be always be null when passed by user code. Really? That's a weird note. I don't see any reason for it to not be used by user code. I wonder why that note is there. It should probably be

Re: Looking for command for synchronization of threads

2013-01-30 Thread Sparsh Mittal
I suggest looking at std.parallelism since it's designed for this kind of thing. That aside, all traditional synchronization methods are in core.sync. The equivalent of sync in Cylk would be core.sync.barrier. Thanks. I wrote this: #!/usr/bin/env rdmd import std.stdio; import

How does array assignment for different sized types work?

2013-01-30 Thread estew
void main() { float[3] v1 = [1.0, 2.0, 3.0];// No error float[3] v = [1.0, 2.0, 3.0].dup; // Fails at runtime with error message } Why does the array assignment work when dup is not used. My understanding is that arrays, like classes, are references. So I declare v1 as a float[3]

Re: How does array assignment for different sized types work?

2013-01-30 Thread Jacob Carlborg
On 2013-01-31 05:48, estew wrote: void main() { float[3] v1 = [1.0, 2.0, 3.0];// No error float[3] v = [1.0, 2.0, 3.0].dup; // Fails at runtime with error message } Why does the array assignment work when dup is not used. My understanding is that arrays, like classes, are

Re: unnecessary casts

2013-01-30 Thread n00b
Le 30/01/2013 17:49, Namespace a écrit : Is the compiler (dmd) fit enough to detect and avoid unnecessary casts? E.g. [code] void foo(T)(T num) { int f = cast(int) num; // ... } foo(42); // cast is unnecessary foo(4.2); // cast is necessary [/code] Or should I wrote everytime [code] void