Re: nextPermutation: why possible for dchar but not for char?

2014-01-19 Thread monarch_dodra
On Saturday, 28 December 2013 at 22:58:43 UTC, Ivan Kazmenko wrote: Also, the example at http://dlang.org/phobos/std_algorithm.html#nextPermutation is wrong: while (nextPermutation(a)) { } should in fact be do { } while (nextPermutation(a)); as above, or we miss the very first permutation.

Re: nextPermutation: why possible for dchar but not for char?

2014-01-19 Thread monarch_dodra
On Saturday, 28 December 2013 at 22:55:39 UTC, Ivan Kazmenko wrote: Another quick question, two of them. 1. This is a minimal example of trying the permutations of a character array. - import std.algorithm; void main () { char [] a; do { } while (nextPermutation(a)); } -

When is a class's destructor called?

2014-01-19 Thread Mike
I'm trying to implement a very minimal D runtime for the ARM Cortex-M platform. I've been quite successful so far, but I'm now getting into reference types and I need to understand better what D does under the hood. I have a working malloc/free implementation, but don't have a garbage

Re: nextPermutation: why possible for dchar but not for char?

2014-01-19 Thread Ivan Kazmenko
On Saturday, 28 December 2013 at 23:05:54 UTC, monarch_dodra wrote: 1. This is a minimal example of trying the permutations of a character array. - import std.algorithm; void main () { char [] a; do { } while (nextPermutation(a)); } - This gives a compile error. However, it

Shared library ld issue?

2014-01-19 Thread Mineko
So, these are the commands I put in: ../gdc/x86_64/gdc -c -fPIC -B ../gdc/x86_64 -I ../gdc/x86_64/phobos test.d This one worked fine, as expected. The problem is here: ../gdc/x86_64/gdc -lgphobos2 -shared -B ../gdc/x86_64 test.o -o test.so And this is what the problem outputs: ld:

Re: When is a class's destructor called?

2014-01-19 Thread Mike
On Sunday, 29 December 2013 at 06:53:08 UTC, Mike Parker wrote: On 12/29/2013 2:03 PM, Mike wrote: x's destructor never gets called. What do I need to implement to have the destructor called when x goes out of scope? Class destructors are not called when an object goes out of scope.

Re: When is a class's destructor called?

2014-01-19 Thread Dicebot
On Sunday, 29 December 2013 at 06:58:03 UTC, Mike wrote: Ok, I understand that, but since I don't have a garbage collector, what must I implement to call the destructor when it goes out of scope? Patch compiler to make all classes scope classes. But that won't be D anymore.

Re: extern(C) function declarations and extra keywords.

2014-01-19 Thread Jacob Carlborg
On 2013-12-28 22:47, Jeremy DeHaan wrote: Since the C functions can't access anything from D code save for what is passed through as parameters, can it be called pure? And if so, does the compiler know how to distinguish C and D in this instance and make it inherently pure? Does purity do

Re: When is a class's destructor called?

2014-01-19 Thread bearophile
Ali Çehreli: On 12/29/2013 04:00 AM, Mike: Do you happen to know of any clever technique to make object, and everything that inherits from it, a referenced counted object? There is std.typecons.RefCounted: http://dlang.org/phobos/std_typecons.html#.RefCounted I think it only works on a

Re: When is a class's destructor called?

2014-01-19 Thread Dicebot
Also destructors are not guaranteed to be run by D specification. It is perfectly legal to skip such cleanup step upon program termination. http://dlang.org/class.html#destructors : The garbage collector is not guaranteed to run the destructor for all unreferenced objects. Furthermore, the

Re: nextPermutation: why possible for dchar but not for char?

2014-01-19 Thread Ivan Kazmenko
On Saturday, 28 December 2013 at 23:07:21 UTC, monarch_dodra wrote: Also, the example at http://dlang.org/phobos/std_algorithm.html#nextPermutation is wrong: while (nextPermutation(a)) { } should in fact be do { } while (nextPermutation(a)); as above, or we miss the very first permutation.

Re: When is a class's destructor called?

2014-01-19 Thread Ali Çehreli
On 12/29/2013 04:00 AM, Mike wrote: On Sunday, 29 December 2013 at 10:16:33 UTC, ponce wrote: If you want deterministic destruction, you have plenty of choices: - scoped! - using structs instead - scope(exit) - RefCounted! - Unique! - ... Do you happen to know of any clever technique to make

Re: When is a class's destructor called?

2014-01-19 Thread ponce
Ok, I understand that, but since I don't have a garbage collector, what must I implement to call the destructor when it goes out of scope? Another way of asking the question is: How does the garbage collector know when something has gone out of scope and is therefore safe to collect? And

A little DUB question

2014-01-19 Thread thedeemon
I've missed all the DUB discussions here and couldn't find the answer to my question in the docs, so here it is, very simple: I've got an app with one dependency stated in package.json as dependencies: { pegged: ~master } When I build my app with dub build

Re: A little DUB question

2014-01-19 Thread ponce
On Tuesday, 31 December 2013 at 10:35:46 UTC, thedeemon wrote: I've missed all the DUB discussions here and couldn't find the answer to my question in the docs, so here it is, very simple: I've got an app with one dependency stated in package.json as dependencies: {

Re: When is a class's destructor called?

2014-01-19 Thread Mike
On Sunday, 29 December 2013 at 10:16:33 UTC, ponce wrote: If you want deterministic destruction, you have plenty of choices: - scoped! - using structs instead - scope(exit) - RefCounted! - Unique! - ... Do you happen to know of any clever technique to make object, and everything that

Re: nextPermutation: why possible for dchar but not for char?

2014-01-19 Thread Ivan Kazmenko
2. Why does nextPermutation hang up for empty arrays? I suppose that's a bug? I suppose so. Please file it. If it is deemed illegal, at the very least, it should throw. My fault, i mis-used it. The right behavior for ranges of size 0 and 1 is checked explicitly in the unittests. Ivan

Re: nextPermutation: why possible for dchar but not for char?

2014-01-19 Thread monarch_dodra
On Saturday, 28 December 2013 at 23:38:38 UTC, Ivan Kazmenko wrote: Ouch, is it an exception hard-coded into the language itself? I thought it's just the nextPermutation's parameter type restrictions which don't allow char []... No, a char[] is just a char[] as far as the language is

Re: When is a class's destructor called?

2014-01-19 Thread bearophile
Mike: How does the garbage collector know when something has gone out of scope The garbage collector doesn't know that. Look in Wikipedia how a MarkSweep GC works. Bye, bearophile

Re: Thread Building Blocks

2014-01-19 Thread Ross Hays
It seems to be somewhat similar to std.parallelism (http://dlang.org/phobos/std_parallelism.html) I have seen that before, didn't know if there was anything closer with the task scheduler and worker threads described in the documentation for TBB, or if that was the closest thing. I see that

Re: Pure

2014-01-19 Thread Meta
On Wednesday, 8 January 2014 at 20:21:22 UTC, John Carter wrote: Very well written, a pleasure to read. And very hard to translate! :) Leaping off the immediate topic of computer language D into the realm of human languages English and Turkish... With the Sapir–Whorf hypothesis in the

Study on hash associative arrays

2014-01-19 Thread bearophile
Through Reddit I've found posts about hash-based associative arrays: http://bannalia.blogspot.it/2013/10/implementation-of-c-unordered.html http://bannalia.blogspot.it/2014/01/a-better-hash-table.html Those little images like this one are excellent at explaining in a short space the basic

DMD linking fails because of missing _adCmp2 and _adEq2

2014-01-19 Thread Nordlöw
I regularly rebuild and use DMD git master locally on Ubuntu 13.10. Yesterday my toolchain dmd fails to link all D programs with the error: Example compilation output from dmd

Re: Better idea for double list comprehension?

2014-01-19 Thread Stanislav Blinov
On Saturday, 18 January 2014 at 07:56:15 UTC, Stanislav Blinov wrote: Although that won't give you a string[], but in a dchar[][]. ...but that is solvable: auto strings = array(cross(ab,12).map!to!string(a)()); Or maybe even by providing additional overload: auto cross(alias fun,R1,R2)(R1

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
Hit the wrong key and posted too early. I finished the code sample below. My main question was for something prettier and more concise. I feel like the code below is long and not as pretty in comparison to the Python. Sometimes that's an unavoidable consequence of static typing, but I'm not

Better idea for double list comprehension?

2014-01-19 Thread CJS
I'm trying to write a D function that does the same as this Python function: def cross(A, B): Cross product of elements in A and elements in B. return [a+b for a in A for b in B] where A and B are strings. (So cross(ab,12) is [a1, b1, a2, b2]). It's easy to get something that works

Re: Array of pointers

2014-01-19 Thread bearophile
Arjan Fetahu: Since each Node connects to multiple others i came up with this solution. class Node { auto content; Node*[] nodes; //..constructor.. } Nodes are reference types in D, so probably you don't need to use a * for Node. Alternatively use a struct handled by

Re: Array of pointers

2014-01-19 Thread Arjan Fetahu
Keep in mind that, unlike in c++, D classes are reference types: class Node { Node[] nodes; // This is valid } Structs are value types though, so using a struct in the above example is illegal. You mean: struct Node { Node[] nodes; } or struct Node { Node*[]

Re: Better idea for double list comprehension?

2014-01-19 Thread bearophile
CJS: I'm trying to write a D function that does the same as this Python function: def cross(A, B): Cross product of elements in A and elements in B. return [a+b for a in A for b in B] where A and B are strings. (So cross(ab,12) is [a1, b1, a2, b2]). One solution: import

Re: Array of pointers

2014-01-19 Thread Arjan Fetahu
Nodes are reference types in D, so probably you don't need to use a * for Node. Alternatively use a struct handled by pointer. auto content; can't compile, you need a type, or you have to template Node on T and use it for content. Bye, bearophile Youre right, it compiles now, and the

Re: errors with filesystem operations

2014-01-19 Thread Kagamin
On Friday, 17 January 2014 at 12:52:09 UTC, Hugo Florentino wrote: On Fri, 17 Jan 2014 07:07:35 +, Kagamin wrote: Does it fail for that one directory only or for any directory? Interesting question. I would have to do more tests with odd names, but apparently both remove() and rename()

Re: [Windows DMD] No callstack when crash with Access violation reading location 0x00000000

2014-01-19 Thread Xavier Bigand
Le 13/01/2014 22:47, Benjamin Thaut a écrit : Am 13.01.2014 21:52, schrieb Xavier Bigand: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,9) glBindBuffer(GL_ARRAY_BUFFER,10) glEnableVertexAttribArray(0) glVertexAttribPointer(0,3,GL_FLOAT,false,12,) glBindBuffer(GL_ARRAY_BUFFER,11)

Re: errors with filesystem operations

2014-01-19 Thread Kagamin
remove uses DeleteFile, but MSDN says To remove an empty directory, use the RemoveDirectory function. so remove probably won't work on directories.

Re: package.d imports

2014-01-19 Thread Leandro Motta Barros
Hi! I made similar questions here a month ago, but also couldn't get definitive answers. I just sent a message about this to the main D forum. Let's see if we have better luck there :-) Cheers, LMB On Fri, Jan 17, 2014 at 5:39 PM, Lemonfiend le...@fie.nd wrote: I think this is what you are

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
import std.stdio, std.conv, std.algorithm, std.array; string[] cross(in string A, in string B) { return cartesianProduct(A, B).map!(ab = ab[].text).array; } void main() { cross(ab, 12).writeln; } But note that currently cartesianProduct doesn't return the pairs in a natural order.

Should formattedWrite take the outputrange by ref?

2014-01-19 Thread Tobias Pankrath
I want to print a tree structure and need to keep track of the indention for different parts of the tree. My idea was to write a generic wrapper for an output range that outputs tabs when it encounters a newline. This wrapper has internal state and if I want to use formattedWrite with this

Re: Better idea for double list comprehension?

2014-01-19 Thread bearophile
units[s] = unitlist.filter!(x = any!(y = (s == y))); And you don't need a pair of ( ): units[s] = unitlist.filter!(x = any!(y = s == y)); And now you need to feed any with some range. Bye, bearophile

Re: Better idea for double list comprehension?

2014-01-19 Thread bearophile
CJS: Unfortunately my current best attemp doesn't compile: What errors are you seeing? auto cross(R1, R2)(in R1 A, in R2 B){ Better to add a space before the open brace. Also you may want to remove in if you want to use cross() on lazy ranges. return

Re: Should formattedWrite take the outputrange by ref?

2014-01-19 Thread bearophile
monarch_dodra: *I* think it should. File a report, and I'll see what I can do about it. The problem with these kinds of things though might be breaking existing code... Given the frequency of bugs caused by such functions that require a pointer to the data, I think that a breaking change is

Re: Should formattedWrite take the outputrange by ref?

2014-01-19 Thread monarch_dodra
On Saturday, 18 January 2014 at 21:55:54 UTC, Tobias Pankrath wrote: I want to print a tree structure and need to keep track of the indention for different parts of the tree. My idea was to write a generic wrapper for an output range that outputs tabs when it encounters a newline. This wrapper

Re: Should formattedWrite take the outputrange by ref?

2014-01-19 Thread anonymous
On Saturday, 18 January 2014 at 21:55:54 UTC, Tobias Pankrath wrote: I want to print a tree structure and need to keep track of the indention for different parts of the tree. My idea was to write a generic wrapper for an output range that outputs tabs when it encounters a newline. This wrapper

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
to!string(c) === c.text That's more concise but I also think it's more confusing. I assume that to!string is doing the exact same thing, but I was hoping for something to do the appropriate implicit conversations. Especially to a range of length 1, though I can understand that kind of

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
Thanks! auto app = appender(unitlist); Ah, I'd been wondering if there was something like this. But why does it need unitlist's address? (Assume has the same meaning as in C and C++.) This one seems like it should be unitlist.filter!(x = x.any!(y = s==y)).array(); Oh. Duh.

Re: Better idea for double list comprehension?

2014-01-19 Thread Stanislav Blinov
On Sunday, 19 January 2014 at 02:10:01 UTC, CJS wrote: That's more concise but I also think it's more confusing. I assume that to!string is doing the exact same thing, but I was hoping for something to do the appropriate implicit conversations. Especially to a range of length 1, though I can

Re: Better idea for double list comprehension?

2014-01-19 Thread Stanislav Blinov
On Sunday, 19 January 2014 at 06:57:37 UTC, CJS wrote: Ah, I'd been wondering if there was something like this. But why does it need unitlist's address? (Assume has the same meaning as in C and C++.) Look at the docs for Appender. It can either provide its own storage, or use an existing

Re: Better idea for double list comprehension?

2014-01-19 Thread bearophile
CJS: units[s] = unitlist.filter!(x = any!(y = s==y)); One of your problems is that any that needs some range to work on. Bye, bearophile

Re: Should formattedWrite take the outputrange by ref?

2014-01-19 Thread Tobias Pankrath
On Sunday, 19 January 2014 at 15:03:13 UTC, monarch_dodra wrote: So, my conclusion, * might be a workable solution. But simply taking by ref would be cleaner, and make more sense as a whole. Or a special template constraint path for T*. foo(T)(T t) if (is(T = Q*)) manyOtherChecks!(Q)

Re: Should formattedWrite take the outputrange by ref?

2014-01-19 Thread monarch_dodra
On Saturday, 18 January 2014 at 23:06:42 UTC, Tobias Pankrath wrote: I actually didn't think that a ptr (to output range) would work. This way we can have best of both worlds and I'm happy with it. A fun fact is that since . notation works with pointers, more often than not, if T verifies

Re: Should formattedWrite take the outputrange by ref?

2014-01-19 Thread Tobias Pankrath
On Sunday, 19 January 2014 at 15:12:07 UTC, Tobias Pankrath wrote: On Sunday, 19 January 2014 at 15:03:13 UTC, monarch_dodra wrote: So, my conclusion, * might be a workable solution. But simply taking by ref would be cleaner, and make more sense as a whole. Or a special template constraint

Re: How can i get the value from an enum when passed to a function?

2014-01-19 Thread Tobias Pankrath
On Sunday, 19 January 2014 at 17:37:54 UTC, Gary Willoughby wrote: How can i get the value from an enum when passed to a function? For example i have the following code: import std.stdio; enum E : string { one = 1, two = 2, } void print(E e) { writefln(%s, e); } void

Re: struct postblit not called, but still destructed

2014-01-19 Thread Benjamin Thaut
Am 19.01.2014 18:48, schrieb Lemonfiend: import std.stdio; struct C { A[] _objs; this(A[] objs...) { writeln(` C this()`); _objs = objs; // A.this(this) is not called // yet A.~this IS called } } struct B { A sup; alias sup

How can i get the value from an enum when passed to a function?

2014-01-19 Thread Gary Willoughby
How can i get the value from an enum when passed to a function? For example i have the following code: import std.stdio; enum E : string { one = 1, two = 2, } void print(E e) { writefln(%s, e); } void main(string[] args) { print(E.one); } The output is 'one'.

Re: How can i get the value from an enum when passed to a function?

2014-01-19 Thread Jakob Ovrum
On Sunday, 19 January 2014 at 18:07:46 UTC, Tobias Pankrath wrote: You'll need to cast the value, but you can guard this cast using std.traits.OriginalType or write a toOType function. auto toOType(E)(E e) if(is(E == enum)) { return cast(OriginalType!E) e; } I never get these is-expressions

Re: struct postblit not called, but still destructed

2014-01-19 Thread Lemonfiend
I just tried the new beta, and the issue remains.

Re: Should formattedWrite take the outputrange by ref?

2014-01-19 Thread monarch_dodra
On Sunday, 19 January 2014 at 15:28:04 UTC, Tobias Pankrath wrote: On Sunday, 19 January 2014 at 15:12:07 UTC, Tobias Pankrath wrote: On Sunday, 19 January 2014 at 15:03:13 UTC, monarch_dodra wrote: So, my conclusion, * might be a workable solution. But simply taking by ref would be cleaner,

Re: Python calling D

2014-01-19 Thread Russel Winder
On Wed, 2013-12-11 at 12:56 +0100, John Colvin wrote: On Wednesday, 11 December 2013 at 11:41:11 UTC, Chris wrote: […] Have you had a look at this: http://pyd.dsource.org/ https://github.com/dansanduleac/pyd both of those are out of date, this is where development is now:

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
That's std.array.join() there. However, I notice that the output (the order of elements) differs from the one on that page you linked earlier. The order shouldn't be a problem. Join is a great idea. I'd thought it was only for an array of strings. Thanks for all the help!

struct postblit not called, but still destructed

2014-01-19 Thread Lemonfiend
When a struct is passed to a function as argument, it is first copied and at the end destructed. But in the following code it is not copied, yet still destructed? module main; import std.stdio; struct C { A[] _objs; this(A[] objs...) { writeln(` C

Re: struct postblit not called, but still destructed

2014-01-19 Thread monarch_dodra
On Sunday, 19 January 2014 at 19:24:23 UTC, Benjamin Thaut wrote: Yes this looks like a bug to me. Please file a bug report at https://d.puremagic.com/issues/ Kind Regards Benjamin Thaut Here is a reduced case: // import std.stdio; struct B { A sup; this(A a) {

Re: struct postblit not called, but still destructed

2014-01-19 Thread monarch_dodra
On Sunday, 19 January 2014 at 20:46:06 UTC, monarch_dodra wrote: I'll file it as an ER, and try to get Kenji on it. https://d.puremagic.com/issues/show_bug.cgi?id=11952 As a workaround, it is usually recommended in the destructor to try to detect initial state, and do nothing in such cases.

Re: Python calling D

2014-01-19 Thread CJS
Sorry to be late coming to this. It would great to be able to push D as a CPython extension language. However the state of pyd.dsource.org and places reached from it do make it seem that the project died in 2009. ariovistus' GitHub project on Bitbucket is moving but everything else appears