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 foo(
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 refe
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
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 std.con
On 1/30/13, Jonathan M Davis 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 changed, TD
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
On Jan 30, 2013, at 2:58 PM, Sparsh Mittal 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 iteration. After e
On 01/30/2013 11:49 PM, Namespace wrote:
Is the compiler (dmd) fit enough to detect and avoid unnecessary casts?
...
Well, 'unnecessary casts' are a no-op anyway. (Yes, afaik DMD will even
eliminate them from the AST.)
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]
>
> O
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 (bec
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 iterat
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 perfor
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 == in
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.
> >
>
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 t
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 th
On 01/30/2013 11:08 AM, Philippe Sigaud wrote:
> On Wed, Jan 30, 2013 at 4:01 PM, Ali Çehreli 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 block
Aw
On Wed, Jan 30, 2013 at 4:01 PM, Ali Çehreli 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. What do yo
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 construct
On Tuesday, 29 January 2013 at 20:37:07 UTC, Andrej Mitrovic
wrote:
On 1/29/13, Vladimir Panteleev
wrote:
foreach (lineNumber, line; lines)
try
numbers ~= to!int(line);
catch (Exception e)
throw new Exception(format("Error on line %d: %s",
lineNumber, e.msg));
Of course,
Thanks for showing me how to use tuples in this problem.
Just for the record, the sort comparison should be reversed: "a > b".
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
Dear,
I have wrote anither fastq reader: http://dpaste.dzfl.pl/2a7885dd
Example of Fastq File--
@H8:C16L5ACXX:8:1101:1168:2103/1
TCTGAAGGCATGCTGCAATTGTGAATGGCAGAAATGT
+
?@@DD>DBDAFDF@4CFGICFHHECHEEBF;E@FFFG
@H8:C16L5ACXX:8:1101:1223:2104/1
CTCACGTACTTTAGACAAGCGCTTT
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 Tup
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 l
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.
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 SI
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], re
On 29.01.2013 21:25, Philippe Sigaud wrote:
> On Mon, Jan 28, 2013 at 10:14 PM, H. S. Teoh 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 yo
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.
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 will
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
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
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).
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 s
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 o
On Wed, 30 Jan 2013 09:20:54 -, simendsjo 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 scope. You
can mod
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. Whe
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:
http://forum.dlang.org/thread/rzvaprvvgdtwrnoto...@fo
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 wha
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
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 d
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
44 matches
Mail list logo