Re: How to get nogc to work with manual memory allocation

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 24 August 2014 at 09:29:53 UTC, Jacob Carlborg wrote: On 2014-08-24 10:03, Bienlein wrote: I have omitted the code for the TestClass class to save space. Problem is that the compiler outputs this: Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' cannot call non-@nogc fu

Re: How to get nogc to work with manual memory allocation

2014-09-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 04/09/14 22:30, Kagamin wrote: emplace calls constructor, and constructor can't be realistically required to be nogc. It depends on the constructor. Similar for destroy. But if the constructor is @nogc or if there's a default constructor. -- /Jacob Carlborg

Re: Mutable array with fixed length

2014-09-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Fri, 05 Sep 2014 00:26:07 + Freddy via Digitalmars-d-learn wrote: > How would you create a mutable array with a fixed(compile error > when trying to change) length. Static arrays have a fixed length and live on the stack. int[12] arr; Dynamic arrays have a mutable length and the memory

Re: dub github dependencies?

2014-09-04 Thread evilrat via Digitalmars-d-learn
On Thursday, 4 September 2014 at 17:22:42 UTC, Gary Willoughby wrote: On Thursday, 4 September 2014 at 16:43:13 UTC, evilrat wrote: how i can specify github repo & branch? i've already tried adding everything i have in mind but no luck so far. so in theory it should be like this: --

Mutable array with fixed length

2014-09-04 Thread Freddy via Digitalmars-d-learn
How would you create a mutable array with a fixed(compile error when trying to change) length.

Re: How to get nogc to work with manual memory allocation

2014-09-04 Thread Kiith-Sa via Digitalmars-d-learn
On Sunday, 24 August 2014 at 08:03:11 UTC, Bienlein wrote: Hello, I was having a look at the new nogc annotation and therefore wrote some code that creates an instance on the heap bypassing the GC (code adapted from http://dpaste.dzfl.pl/2377217c7870). Problem is that calls to call the class'

Re: Allowing Expressions such as (low < value < high)

2014-09-04 Thread ketmar via Digitalmars-d-learn
On Thu, 04 Sep 2014 20:29:08 + "Nordlöw" via Digitalmars-d-learn wrote: > On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote: > > if (low < value < high) > > An alternative could be > > if (value in low..high) and then we need new overload for 'in' operator... signature

Re: Allowing Expressions such as (low < value < high)

2014-09-04 Thread Ary Borenszweig via Digitalmars-d-learn
On 9/4/14, 7:03 PM, "Nordlöw" wrote: On Thursday, 4 September 2014 at 22:02:20 UTC, Nordlöw wrote: D can also, in this case, do (or will do) common sub-expression elimination because it has a strict memory model (const and immutability) and function purity (template inference). Correction: foo

Re: opSlice() or opIndex() for the entire slice?

2014-09-04 Thread Ali Çehreli via Digitalmars-d-learn
On 09/04/2014 02:04 PM, monarch_dodra wrote: > On Thursday, 4 September 2014 at 19:12:27 UTC, Ali Çehreli wrote: >> The documentation says "To overload a[], simply define opIndex with no >> parameters": >> >> http://dlang.org/operatoroverloading.html#Slice >> >> And it works with some uses of a

Re: Allowing Expressions such as (low < value < high)

2014-09-04 Thread Matt Soucy via Digitalmars-d-learn
On 09/04/2014 04:03 PM, "Nordlöw" wrote: > Are there any programming languages that extend the behaviour of comparison > operators to allow expressions such as > > if (low < value < high) > > ? > > This syntax is currently disallowed by DMD. > > I'm aware of the risk of a programmer misint

Re: Allowing Expressions such as (low < value < high)

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 22:02:20 UTC, Nordlöw wrote: D can also, in this case, do (or will do) common sub-expression elimination because it has a strict memory model (const and immutability) and function purity (template inference). Correction: foo cannot be pure in this case. But I b

Re: Allowing Expressions such as (low < value < high)

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 20:45:41 UTC, Ary Borenszweig wrote: That's because the middle expression in the comparison is first assigned to a temporary variable, so `foo` is only invoked once. This makes both the code more readable, efficient and saves the programmer from having to save t

Re: opSlice() or opIndex() for the entire slice?

2014-09-04 Thread Ali Çehreli via Digitalmars-d-learn
On 09/04/2014 12:19 PM, "Marc Schütz" " wrote: On Thursday, 4 September 2014 at 19:12:27 UTC, Ali Çehreli wrote: The documentation says "To overload a[], simply define opIndex with no parameters": http://dlang.org/operatoroverloading.html#Slice And it works with some uses of a[]. However, op

Re: opSlice() or opIndex() for the entire slice?

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 19:12:27 UTC, Ali Çehreli wrote: The documentation says "To overload a[], simply define opIndex with no parameters": http://dlang.org/operatoroverloading.html#Slice And it works with some uses of a[]. However, opSlice() seems to be needed to actually use the

Re: Building a string from n chars

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 20:57:43 UTC, monarch_dodra wrote: On Thursday, 4 September 2014 at 20:38:39 UTC, Nordlöw wrote: On Thursday, 4 September 2014 at 19:24:00 UTC, Nordlöw wrote: string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= "*".replicate(n); After having read http:

Re: Building a string from n chars

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 20:38:39 UTC, Nordlöw wrote: On Thursday, 4 September 2014 at 19:24:00 UTC, Nordlöw wrote: string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= "*".replicate(n); After having read http://dlang.org/phobos/std_array.html#.replicate I came to the conclu

Re: writeln() assertion failed in hybrid x64

2014-09-04 Thread Kagamin via Digitalmars-d-learn
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L270 well, this sucks.

Re: writeln() assertion failed in hybrid x64

2014-09-04 Thread Kagamin via Digitalmars-d-learn
https://github.com/D-Programming-Language/druntime/blob/master/src/core/stdc/stdio.d#L457 see? It's null. Hmm... where is it initialized?

Re: Allowing Expressions such as (low < value < high)

2014-09-04 Thread Ary Borenszweig via Digitalmars-d-learn
On 9/4/14, 5:03 PM, "Nordlöw" wrote: Are there any programming languages that extend the behaviour of comparison operators to allow expressions such as if (low < value < high) ? This syntax is currently disallowed by DMD. I'm aware of the risk of a programmer misinterpreting this as

Re: writeln() assertion failed in hybrid x64

2014-09-04 Thread Szymon Gatner via Digitalmars-d-learn
On Thursday, 4 September 2014 at 20:38:38 UTC, Kagamin wrote: Maybe some module constructor wasn't run due to linking mess. So it remains uninitialized. Is there a way I can check if module c-tor run? rt_init() returned no error.

Re: Building a string from n chars

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 19:24:00 UTC, Nordlöw wrote: string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= "*".replicate(n); After having read http://dlang.org/phobos/std_array.html#.replicate I came to the conclusion that the lazy std.range:repeat is preferred. I'm stil

Re: writeln() assertion failed in hybrid x64

2014-09-04 Thread Kagamin via Digitalmars-d-learn
Maybe some module constructor wasn't run due to linking mess. So it remains uninitialized.

Re: How to get nogc to work with manual memory allocation

2014-09-04 Thread Kagamin via Digitalmars-d-learn
On Sunday, 24 August 2014 at 13:27:01 UTC, Jacob Carlborg wrote: On 2014-08-24 14:18, Kagamin wrote: Shouldn't emplace and destroy infer their attributes instead of strictly annotating them as nogc. If they are templates, I guess they should. I don't know how good the compiler is at inferri

Re: Allowing Expressions such as (low < value < high)

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 20:25:52 UTC, monarch_dodra wrote: In the case of D, it's a C compatibility thing. Other languages I don't know. FYI, auto x = 1 < 2 < 3; as C++ is accepted (but warned about) by GCC as x.cpp:19:20: warning: comparisons like ‘X<=Y<=Z’ do not have their m

Re: Allowing Expressions such as (low < value < high)

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote: if (low < value < high) An alternative could be if (value in low..high) but then the problem would be to remember that this range is actually [low..high[ to be compliant with range indexing semantics. But it could

Re: Allowing Expressions such as (low < value < high)

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote: Are there any programming languages that extend the behaviour of comparison operators to allow expressions such as if (low < value < high) ? This syntax is currently disallowed by DMD. I'm aware of the risk of a programmer mis

Allowing Expressions such as (low < value < high)

2014-09-04 Thread Nordlöw
Are there any programming languages that extend the behaviour of comparison operators to allow expressions such as if (low < value < high) ? This syntax is currently disallowed by DMD. I'm aware of the risk of a programmer misinterpreting this as if ((low < value) < high) Is this th

Re: Building a string from n chars

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 19:22:42 UTC, Nordlöw wrote: Is DMD/Phobos already that clever!? Further -vgc has nothing to say about string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= "*".replicate(n); .

Re: Building a string from n chars

2014-09-04 Thread Nordlöw
On Wednesday, 3 September 2014 at 20:20:09 UTC, Meta wrote: Does this work? s ~= "*".replicate(n); Yes, thanks. So what's best? type ~= '*'.repeat(pointerCount).array; or type ~= "*".replicate(pointerCount); ? Further, -vgc says only ~= will allocate: t_repeat_replicate.d(12,19)

Re: opSlice() or opIndex() for the entire slice?

2014-09-04 Thread via Digitalmars-d-learn
On Thursday, 4 September 2014 at 19:12:27 UTC, Ali Çehreli wrote: The documentation says "To overload a[], simply define opIndex with no parameters": http://dlang.org/operatoroverloading.html#Slice And it works with some uses of a[]. However, opSlice() seems to be needed to actually use the

opSlice() or opIndex() for the entire slice?

2014-09-04 Thread Ali Çehreli via Digitalmars-d-learn
The documentation says "To overload a[], simply define opIndex with no parameters": http://dlang.org/operatoroverloading.html#Slice And it works with some uses of a[]. However, opSlice() seems to be needed to actually use the returned slice further. Note that opSlice() also seems to be for

Re: Building a string from n chars

2014-09-04 Thread Nordlöw
On Wednesday, 3 September 2014 at 20:46:40 UTC, monarch_dodra wrote: Is there a simpler way to way to s ~= repeat('*', n).array.to!string; if s has to be of type string? s ~= repeat('*', n).array(); Should be enough. Why the "to!string"? You're correct. The .to!string was unnecessary

Re: literate programming in D

2014-09-04 Thread Philippe Sigaud via Digitalmars-d-learn
> Ah that sounds interesting too! Immediately I start thinking in terms like > tidlywiki http://tiddlywiki.com/ or something similar, I guess the emacs way > described earlier also would support this. I personally always enjoy reading > the readthedocs stuff http://docs.readthedocs.org/en/latest/ i

Re: writeln() assertion failed in hybrid x64

2014-09-04 Thread Szymon Gatner via Digitalmars-d-learn
On Thursday, 4 September 2014 at 18:22:55 UTC, Marc Schütz wrote: On Thursday, 4 September 2014 at 17:57:47 UTC, Szymon Gatner wrote: On Thursday, 4 September 2014 at 15:25:59 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 04 Sep 2014 15:10:21 + "Jorge A. S. via Digitalmars-d-learn" wr

Re: writeln() assertion failed in hybrid x64

2014-09-04 Thread via Digitalmars-d-learn
On Thursday, 4 September 2014 at 17:57:47 UTC, Szymon Gatner wrote: On Thursday, 4 September 2014 at 15:25:59 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 04 Sep 2014 15:10:21 + "Jorge A. S. via Digitalmars-d-learn" wrote: In one of the specializations of the write function in the s

Re: writeln() assertion failed in hybrid x64

2014-09-04 Thread Szymon Gatner via Digitalmars-d-learn
On Thursday, 4 September 2014 at 15:25:59 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 04 Sep 2014 15:10:21 + "Jorge A. S. via Digitalmars-d-learn" wrote: In one of the specializations of the write function in the std.stdio (the call site that you showed in your post) no check for c

Re: dub github dependencies?

2014-09-04 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 4 September 2014 at 16:43:13 UTC, evilrat wrote: how i can specify github repo & branch? i've already tried adding everything i have in mind but no luck so far. so in theory it should be like this: -- dub.json "dependencies": { "cairod": {"version": "~ReworkWin32", "path

Re: Should formattedWrite take the outputrange by ref?

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 17:06:00 UTC, Márcio Martins wrote: On Wednesday, 3 September 2014 at 07:43:20 UTC, Guillaume Chatelet wrote: +1 I've been bitten by this also. Same here, +1 It's still on my radar, but it's actually not that trivial of a change, especially if we want to avo

Re: Should formattedWrite take the outputrange by ref?

2014-09-04 Thread via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 07:43:20 UTC, Guillaume Chatelet wrote: +1 I've been bitten by this also. Same here, +1

dub github dependencies?

2014-09-04 Thread evilrat via Digitalmars-d-learn
how i can specify github repo & branch? i've already tried adding everything i have in mind but no luck so far. so in theory it should be like this: -- dub.json "dependencies": { "cairod": {"version": "~ReworkWin32", "path": "https://github.com/evilrat666/cairoD.git"} }

Re: Intended behavior of std.range.cycle?

2014-09-04 Thread rcor via Digitalmars-d-learn
A closer look shows that cycle "repeats the given _forward_ range indefinitely", so I guess the current behavior is at least consistent with the docs.

Re: Intended behavior of std.range.cycle?

2014-09-04 Thread rcor via Digitalmars-d-learn
On Thursday, 4 September 2014 at 11:58:58 UTC, monarch_dodra wrote: On Thursday, 4 September 2014 at 11:43:28 UTC, monarch_dodra wrote: Indexing is done with the unsigned size_t. I re-read your post, and I don't think I actually answered your question...? I don't know of any case where you'

Re: writeln() assertion failed in hybrid x64

2014-09-04 Thread ketmar via Digitalmars-d-learn
On Thu, 04 Sep 2014 15:10:21 + "Jorge A. S. via Digitalmars-d-learn" wrote: > In one of the specializations of the write function in the > std.stdio (the call site that you showed in your post) no check > for closed stdout (when stdout._p is null) is done. I can't say > if this is a bug in

Re: writeln() assertion failed in hybrid x64

2014-09-04 Thread Jorge A. S. via Digitalmars-d-learn
I'm having an error related to yours: when I call writeln function in a closed stdout I will get a segfault message. Example: import std.stdio; void main() { stdout.close(); write("hello\n"); } The code above will crash with segfault buf the following code will raise an exception instead

Re: basic question about adresses and values in structs

2014-09-04 Thread nikki via Digitalmars-d-learn
On Thursday, 4 September 2014 at 14:00:14 UTC, Ali Çehreli wrote: On 09/04/2014 02:54 AM, nikki wrote: > a pointer variable to save an adres of a function, then dereferencing to use > it. If possible, even in C, I would recommend using a 'function pointer' for that. However, there are cases wh

Re: basic question about adresses and values in structs

2014-09-04 Thread Ali Çehreli via Digitalmars-d-learn
On 09/04/2014 02:54 AM, nikki wrote: > a pointer variable to save an adres of a function, then dereferencing to use > it. If possible, even in C, I would recommend using a 'function pointer' for that. However, there are cases where the signature of the function should be unknown to the code

Re: literate programming in D

2014-09-04 Thread nikki via Digitalmars-d-learn
I should have read your post more carefully, the 'tagging' in the code is not really what I am after, I want the file including the documentation to just be a valid d file, does'nt mean however that there aren't ways of solving the issue without such precise tagging I guess

Re: literate programming in D

2014-09-04 Thread nikki via Digitalmars-d-learn
On Saturday, 30 August 2014 at 07:24:39 UTC, Philippe Sigaud wrote: On Sat, Aug 30, 2014 at 1:37 AM, nikki wrote: I wasn't too happy about it and I wrote my own little parse thingie and have a literate version nice and meta and small and sloppy ;) http://nikkikoole.github.io/docs/dokidokDOC.ht

Re: literate programming in D

2014-09-04 Thread nikki via Digitalmars-d-learn
On Friday, 29 August 2014 at 23:41:00 UTC, bearophile wrote: nikki: I use it to change my d sourcefile slightly (into valid markdown) then I use a node module (ghmd) to make sortof sexy html from that. Are you going to add popups of the types as in the F# page I have linked? Bye, bearophi

Re: Intended behavior of std.range.cycle?

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 11:43:28 UTC, monarch_dodra wrote: Indexing is done with the unsigned size_t. I re-read your post, and I don't think I actually answered your question...? I don't know of any case where you'd want to index negativelly. That said, I'm sure it could be possibl

Re: Intended behavior of std.range.cycle?

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 11:29:30 UTC, rcor wrote: auto c = cycle([1,2,3]); foreach(i ; iota(-4,4)) { writeln(c[i]); } prints the sequence 1 2 3 1 1 <- c[0] == c[-1] 2 3 I understand this is what would happen if I were to just use modulus on an index to access the original arra

Intended behavior of std.range.cycle?

2014-09-04 Thread rcor via Digitalmars-d-learn
auto c = cycle([1,2,3]); foreach(i ; iota(-4,4)) { writeln(c[i]); } prints the sequence 1 2 3 1 1 <- c[0] == c[-1] 2 3 I understand this is what would happen if I were to just use modulus on an index to access the original array, but should Cycle really mimic this behavior? I feel like

Re: basic question about adresses and values in structs

2014-09-04 Thread evilrat via Digitalmars-d-learn
On Thursday, 4 September 2014 at 09:54:57 UTC, nikki wrote: thanks! just what I needed, with some stumbling I managed to get everything working as intended: using a pointer variable to save an adres of a function, then dereferencing to use it. Now I am wondering when to use the ** ? for examp

Re: Using TreeSet and __gshared values

2014-09-04 Thread via Digitalmars-d-learn
On Thursday, 4 September 2014 at 09:02:26 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 04 Sep 2014 08:38:50 + via Digitalmars-d-learn wrote: Hmm... would be nice if there were a warning/error when __gshared is used without static in a class. would you fill enhancement request in b

Re: basic question about adresses and values in structs

2014-09-04 Thread nikki via Digitalmars-d-learn
thanks! just what I needed, with some stumbling I managed to get everything working as intended: using a pointer variable to save an adres of a function, then dereferencing to use it. Now I am wondering when to use the ** ? for example I found this function over at https://github.com/d-gamede

Re: Using TreeSet and __gshared values

2014-09-04 Thread ketmar via Digitalmars-d-learn
On Thu, 04 Sep 2014 08:38:50 + via Digitalmars-d-learn wrote: > Hmm... would be nice if there were a warning/error when __gshared > is used without static in a class. would you fill enhancement request in bugzilla? signature.asc Description: PGP signature

Re: Using TreeSet and __gshared values

2014-09-04 Thread via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 20:10:51 UTC, ketmar via Digitalmars-d-learn wrote: On Wed, 03 Sep 2014 19:53:15 + nrgyzer via Digitalmars-d-learn wrote: __gshared class members are effectively "static", i.e. they are "class members", not "instance members". Hmm... would be nice if