Re: release mode optimization

2013-01-09 Thread Charles Hixson
On 01/09/2013 04:40 PM, Jonathan M Davis wrote: On Wednesday, January 09, 2013 16:14:47 Charles Hixson wrote: Would the following code: for (int i = 1; i< di.count; i++) { assert (node.di.entry[i - 1].key< node.di.entry[i].key); } be optimized away if compiled under -release? If you compile

Re: Enhancing foreach

2013-01-09 Thread Jonathan M Davis
On Thursday, January 10, 2013 04:43:48 bearophile wrote: > There are hundreds of use cases. Some examples: [snip] And I don't normally need to do any of those things in my programs. I think that you must be doing very different things with your typical programs than I'm doing with my typical pro

Re: Enhancing foreach

2013-01-09 Thread bearophile
Jonathan M Davis: I use it when I need it, I think there many usages of iota that you are missing. To spot those cases you probably need to train yourself a bit. A Python programmer doesn't need that training. I can't remember the last time that I needed to generate a range of numbers fo

Re: Enhancing foreach

2013-01-09 Thread Peter Summerland
On Thursday, 10 January 2013 at 02:04:57 UTC, ixid wrote: On Wednesday, 9 January 2013 at 23:15:10 UTC, Jonathan M Davis wrote: On Wednesday, January 09, 2013 05:38:16 ixid wrote: A very minor change that would be elegant and easy for beginners: foreach(i;5) //stuff Allowing just a single nu

Re: Enhancing foreach

2013-01-09 Thread Jonathan M Davis
On Thursday, January 10, 2013 03:51:34 bearophile wrote: > My first > answer is that you probably should use iota more, because it's > handy in many situations :-) I use it when I need it, but that's quite rare and almost always in unit tests. I might operate on ranges of numbers, but if so, they

Re: Enhancing foreach

2013-01-09 Thread bearophile
Jonathan M Davis: I almost never use iota. Then a problem is in the difference in usage frequency. My first answer is that you probably should use iota more, because it's handy in many situations :-) If I grep my code I count almost 120 usages of iota. I think D programmers that have some

bugzilla issue 8434? Confusing error message?

2013-01-09 Thread Charles Hixson
...$ dmd -unittest bptree.d Error: cannot implicitly convert expression (this.dnLftLnk) of type BPNode[7LU] to bptree.BPNode Type BPNode is only declared once, although the error message refers to: if (ndx == -1) node = dnLftLnk; a place where it is an out parameter in a function declared: boo

Re: Enhancing foreach

2013-01-09 Thread Jonathan M Davis
On Thursday, January 10, 2013 03:04:56 ixid wrote: > Regardless of this particular suggestion's value, I think you're > wrong to dismiss readable terseness and saving typing as > mattering, it's one of D's advantages over C++ that it makes a > lot of things far easier to do and understand because t

Re: Enhancing foreach

2013-01-09 Thread Jonathan M Davis
On Thursday, January 10, 2013 03:19:51 bearophile wrote: > In my code iota() is common, even if it's surely not as common as > range() in Python. I think it's common enough that you remember > that iota(5) is a range of five items. And D too is 0-based. (and > iota in APL accepted one argument). I

Re: Enhancing foreach

2013-01-09 Thread bearophile
Jonathan M Davis: I would argue that the mistake is that iota(5) works. That's not at all clear, Clarity is not an absolute property, it's also correlated to the frequency of usage and commonality. A symbol like a cross "+" doesn't have much of intrinsic meaning, but most people know what i

Re: Enhancing foreach

2013-01-09 Thread ixid
On Wednesday, 9 January 2013 at 23:15:10 UTC, Jonathan M Davis wrote: On Wednesday, January 09, 2013 05:38:16 ixid wrote: A very minor change that would be elegant and easy for beginners: foreach(i;5) //stuff Allowing just a single number to mean the end point and a default starting point o

Re: release mode optimization

2013-01-09 Thread David Nadlinger
On Thursday, 10 January 2013 at 01:14:42 UTC, H. S. Teoh wrote: I tested DMD on a loop containing assert(true);, and apparently that *is* optimized out with -O. I tested it with the program from Jonathan's post – still has an empty inc/cmp/jl loop in there with -O -release (x86_64). David

Re: release mode optimization

2013-01-09 Thread H. S. Teoh
On Thu, Jan 10, 2013 at 02:03:47AM +0100, David Nadlinger wrote: > On Thursday, 10 January 2013 at 00:40:21 UTC, Jonathan M Davis > wrote: > >So clearly, dmd does _not_ optimize out the loop. I have no idea what > >gdc and ldc do though. > > Wow, DMD doesn't optimize it away indeed, just confirmed

Re: release mode optimization

2013-01-09 Thread David Nadlinger
On Thursday, 10 January 2013 at 00:40:21 UTC, Jonathan M Davis wrote: So clearly, dmd does _not_ optimize out the loop. I have no idea what gdc and ldc do though. Wow, DMD doesn't optimize it away indeed, just confirmed that by a look at the assembly. LDC does delete the loop though, starti

Re: release mode optimization

2013-01-09 Thread Jonathan M Davis
On Wednesday, January 09, 2013 16:14:47 Charles Hixson wrote: > Would the following code: > for (int i = 1; i < di.count; i++) > { assert (node.di.entry[i - 1].key < node.di.entry[i].key); } > > be optimized away if compiled under -release? If you compile with -release, assertions will be compile

release mode optimization

2013-01-09 Thread Charles Hixson
Would the following code: for (int i = 1; i < di.count; i++) { assert (node.di.entry[i - 1].key < node.di.entry[i].key); } be optimized away if compiled under -release?

Re: Enhancing foreach

2013-01-09 Thread Jonathan M Davis
On Wednesday, January 09, 2013 05:38:16 ixid wrote: > A very minor change that would be elegant and easy for beginners: > > foreach(i;5) > //stuff > > Allowing just a single number to mean the end point and a default > starting point of zero is assumed, just as with iota it's > possible to write

Re: BitArray new design

2013-01-09 Thread Era Scarecrow
On Wednesday, 9 January 2013 at 21:16:37 UTC, Era Scarecrow wrote: Hmm as I'm thinking about it more, a mixin for BitString may be better.. I'm having troubles trying to understand why this won't work. Anyone clarify? mixin template BitString() { struct BitString { size_t opI

Re: BitArray new design

2013-01-09 Thread Era Scarecrow
On Wednesday, 9 January 2013 at 20:00:59 UTC, Era Scarecrow wrote: BitString { //bitfields for start/ending size_t[]* bulkRaw; //pointer to the array? //binaryOperators and opIndex, etc //length modifier, but no memory re-allocation allowed } BitArray { BitString array; size_t[] rawM

Re: Array remove 1 item? (std.container)

2013-01-09 Thread Jonathan M Davis
On Wednesday, January 09, 2013 16:20:39 Robert wrote: > On Wednesday, 9 January 2013 at 15:06:01 UTC, Damian wrote: > > Hi, I've got the jist of using most of std.container.Array, but > > I can't seem to remove a single item, I understand I must remove > > a range. > > > > Array!int arr; > > arr.i

Re: dynamic arrays of immutable question: Are the elements actually mutable

2013-01-09 Thread Jonathan M Davis
On Wednesday, January 09, 2013 17:22:25 ollie wrote: > On Wed, 09 Jan 2013 14:38:13 +0100, monarch_dodra wrote: > > On Wednesday, 9 January 2013 at 12:38:13 UTC, Jonathan M Davis wrote: > >> When you append to array, the elements being added are in untyped > >> memory. So, > >> no mutation of immut

BitArray new design

2013-01-09 Thread Era Scarecrow
Having insomnia has left me with a certain gifted curse. :P I've been thinking, and i think i've written BitArray all wrong, in order to better structure it i would break it up into four something parts. The following would remove the complication of 'isCompact' and the union, the code can b

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
.d.obj: $(DC) $(DFLAGS) -c $< Ali from http://digitalmars.com/ctg/make.html: Implicit Definition lines .targ_ext.dep_ext : [; rule] [# ... ] Isn't targ_ext .obj and dep_ext .d? If so, either the example or the documentation seems incorrect. The example provided works. The .obj is update

Re: dynamic arrays of immutable question: Are the elements actually mutable

2013-01-09 Thread monarch_dodra
On Wednesday, 9 January 2013 at 18:17:52 UTC, monarch_dodra wrote: The "good news" is that since the values are T.init'd, then opEqual becomes somewhat more valid, although arguably, it should really be in-place construction, *especially* if immutable is involved (or types without opAssign...).

Re: Something like godoc

2013-01-09 Thread H. S. Teoh
On Wed, Jan 09, 2013 at 03:21:53PM +0100, MrOrdinaire wrote: > On Wednesday, 9 January 2013 at 14:09:30 UTC, simendsjo wrote: > >On Wednesday, 9 January 2013 at 13:42:52 UTC, MrOrdinaire wrote: > >>Hi, > >> > >>In Go, I can just install the documentation and later consult it > >>using the godoc com

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
.d.obj: $(DC) $(DFLAGS) -c $< Ali Works like a charm! Case solved. Thank you very much!

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
don't know what make you're using, [...] I'am using the make.exe coming with the DMD 2.061 distro in D/dmd2/windows/bin/ Thought/hoped the GNU spec was applicable, but if it works with GNU make and not Digital Mars make, well.. make -man leads to http://digitalmars.com/ctg/make.html, which

Re: Array remove 1 item? (std.container)

2013-01-09 Thread Damian
On Wednesday, 9 January 2013 at 15:40:48 UTC, monarch_dodra wrote: On Wednesday, 9 January 2013 at 15:29:50 UTC, Damian wrote: On Wednesday, 9 January 2013 at 15:20:40 UTC, Robert wrote: On Wednesday, 9 January 2013 at 15:06:01 UTC, Damian wrote: Hi, I've got the jist of using most of std.conta

Re: Enhancing foreach

2013-01-09 Thread Jesse Phillips
On Wednesday, 9 January 2013 at 17:07:50 UTC, ixid wrote: It would be even nicer to be able to write for(i;5) and have it behave as foreach. I hated java's choice to use for as foreach. It does not prepare me for the semantics of what I'm about to read. And when I go to write it and don't rem

Re: Simple makefile problem - implicit rule

2013-01-09 Thread Ali Çehreli
On 01/09/2013 10:19 AM, deed wrote: Assuming that this is for GNU make, ensuring that the rule starts with a tab characters, that file works with GNU Make 3.81. Ali It is Digital Mars Make Version 5.06 and it's on Windows 7. That's why you didn't mark the subject with [OT]. ;) It looks like

Re: Simple makefile problem - implicit rule

2013-01-09 Thread Matthew Caron
On 01/09/2013 01:13 PM, deed wrote: Yeah, that's not the problem. Replacing %.obj and %.d with main.obj and main.d works. And $< with main.d don't know what make you're using, but this works for me: OBJS= hello.obj hello_loop.obj DC = gdc DCFLAGS = all : $(OBJS) %.obj : %.d

Re: Enhancing foreach

2013-01-09 Thread Ali Çehreli
On 01/09/2013 10:06 AM, bearophile wrote: > Instead, what I have had to tell friends reading my D code is what the > heck "iota" means. The meaning of the word "range" in Python is simpler > to guess. Same here. :) Ali

Re: Enhancing foreach

2013-01-09 Thread Ali Çehreli
On 01/09/2013 10:08 AM, ixid wrote: >> for (i; ++j) { >> /* ... */ >> } >> >> Did I forget something or is it "from zero to the incremented value of >> j"? > > If this was supposed to be a normal for loop > the user's forgotten to give i a type and a boundary condition and the > second semi-colo

Re: dynamic arrays of immutable question: Are the elements actually mutable

2013-01-09 Thread monarch_dodra
On Wednesday, 9 January 2013 at 13:38:14 UTC, monarch_dodra wrote: The original line I am concerned about is "HERE": Is this a legal mutation? I think I got my answer actually: No. No it isn't. Changing the array's length initialize the not yet typed memory to T.init, ergo, it types the mem

Re: Simple makefile problem - implicit rule

2013-01-09 Thread Ali Çehreli
On 01/09/2013 09:51 AM, deed wrote: # makefile --- OBJS = main.obj othermodule.obj DC = dmd DCFLAGS = -c all : $(OBJS) %.obj : %.d $(DC) $< $(DCFLAGS) # Error on line 9: expecting target : dependencies * main.d, othermodule.d and makefile are in the same folder.

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
Assuming that this is for GNU make, ensuring that the rule starts with a tab characters, that file works with GNU Make 3.81. Ali It is Digital Mars Make Version 5.06 and it's on Windows 7.

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
On Wednesday, 9 January 2013 at 17:57:28 UTC, Ali Çehreli wrote: On 01/09/2013 09:51 AM, deed wrote: $(DC) $< $(DCFLAGS) Your post has spaces at the beginning on that line. (Thunderbird removes those when I reply. Curse!) Target rules must start with a tab character. Ali Yeah, that's n

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
Yeah, that's not the problem. Replacing %.obj and %.d with main.obj and main.d works. And $< with main.d

Re: Enhancing foreach

2013-01-09 Thread bearophile
Ali Çehreli: iota got it wrong. I would expect new users to be confused by iota(5). Is that "ends at 5" or "begins with 5"? The latter is more consistent with how the function parameters at the and can have default values. So it is likely to be perceived as the following. Ignoring that iota i

Re: Enhancing foreach

2013-01-09 Thread ixid
I think you're rather a long way away from beginners to see how beginners would think. iota is behaving like the Python range syntax which beginners seem to find quite easy to use. A beginner thinks 'it goes up to that number', the thought process you outlined is that of someone learning their

Re: dynamic arrays of immutable question: Are the elements actually mutable

2013-01-09 Thread monarch_dodra
On Wednesday, 9 January 2013 at 17:22:25 UTC, ollie wrote: My question is about immutable and casting in general. I've heard Walter say of immutable, "Turtles all the way down.". If say I have a plug-in system with a defined interface and I pass it an immutable array (ie immutable(int)[]) the

Simple makefile problem - implicit rule

2013-01-09 Thread deed
# makefile --- OBJS= main.obj othermodule.obj DC = dmd DCFLAGS = -c all : $(OBJS) %.obj : %.d $(DC) $< $(DCFLAGS) # Error on line 9: expecting target : dependencies * main.d, othermodule.d and makefile are in the same folder. * make is executed in

Re: Enhancing foreach

2013-01-09 Thread Ali Çehreli
On 01/09/2013 09:07 AM, ixid wrote: >> Just like the terser iota, iota got it wrong. I would expect new users to be confused by iota(5). Is that "ends at 5" or "begins with 5"? The latter is more consistent with how the function parameters at the and can have default values. So it is likely to

Re: dynamic arrays of immutable question: Are the elements actually mutable

2013-01-09 Thread ollie
On Wed, 09 Jan 2013 14:38:13 +0100, monarch_dodra wrote: > On Wednesday, 9 January 2013 at 12:38:13 UTC, Jonathan M Davis wrote: >> >> When you append to array, the elements being added are in untyped >> memory. So, >> no mutation of immutable anything is going on at all. > > Ok, I guess that mak

Re: Enhancing foreach

2013-01-09 Thread ixid
On Wednesday, 9 January 2013 at 08:01:05 UTC, Jacob Carlborg wrote: On 2013-01-09 05:38, ixid wrote: A very minor change that would be elegant and easy for beginners: foreach(i;5) //stuff Allowing just a single number to mean the end point and a default starting point of zero is assumed,

Re: Enhancing foreach

2013-01-09 Thread ixid
Just like the terser iota, it's more elegant and easier for newer users. The fewer symbols there are in code the easier it is to parse for the user (up to a point). It's also more consistent with iota. It also means that a foreach that iterates a function return value can be written in the same

Re: Array remove 1 item? (std.container)

2013-01-09 Thread monarch_dodra
On Wednesday, 9 January 2013 at 15:29:50 UTC, Damian wrote: On Wednesday, 9 January 2013 at 15:20:40 UTC, Robert wrote: On Wednesday, 9 January 2013 at 15:06:01 UTC, Damian wrote: Hi, I've got the jist of using most of std.container.Array, but I can't seem to remove a single item, I understand

Re: Array remove 1 item? (std.container)

2013-01-09 Thread Damian
On Wednesday, 9 January 2013 at 15:20:40 UTC, Robert wrote: On Wednesday, 9 January 2013 at 15:06:01 UTC, Damian wrote: Hi, I've got the jist of using most of std.container.Array, but I can't seem to remove a single item, I understand I must remove a range. Array!int arr; arr.insert([1, 2, 3,

Re: Array remove 1 item? (std.container)

2013-01-09 Thread Robert
On Wednesday, 9 January 2013 at 15:06:01 UTC, Damian wrote: Hi, I've got the jist of using most of std.container.Array, but I can't seem to remove a single item, I understand I must remove a range. Array!int arr; arr.insert([1, 2, 3, 4, 5]); So now how would I remove lets say the number 3 from

Re: foreach range construction bug?!!?!?!?

2013-01-09 Thread Phil Lavoie
On Tuesday, 8 January 2013 at 04:49:42 UTC, Mike Parker wrote: On Monday, 7 January 2013 at 18:11:14 UTC, Phil Lavoie wrote: I have looked around the a while and I can say that the invalid calling convention is the most probable cause, though I am still wondering what is the best way to create

Re: Something like godoc

2013-01-09 Thread MrOrdinaire
On Wednesday, 9 January 2013 at 14:09:30 UTC, simendsjo wrote: On Wednesday, 9 January 2013 at 13:42:52 UTC, MrOrdinaire wrote: Hi, In Go, I can just install the documentation and later consult it using the godoc command, e.g. `godoc fmt Println` would give the documentation for the Println F

Re: Something like godoc

2013-01-09 Thread simendsjo
On Wednesday, 9 January 2013 at 13:42:52 UTC, MrOrdinaire wrote: Hi, In Go, I can just install the documentation and later consult it using the godoc command, e.g. `godoc fmt Println` would give the documentation for the Println Function inside the fmt package. Is there anything like that f

Re: Inner function overload bug?

2013-01-09 Thread dennis luehring
Am 09.01.2013 14:21, schrieb Philippe Sigaud: On Wed, Jan 9, 2013 at 12:52 PM, Era Scarecrow wrote: That's weird. Why does that work? Directly pasting the mixin content in main() does not compile, right? I can only assume if it does work, that the mixin template has it's own scope that enab

Re: Truth value of an empty slice

2013-01-09 Thread monarch_dodra
On Wednesday, 9 January 2013 at 13:38:21 UTC, MrOrdinaire wrote: On Wednesday, 9 January 2013 at 13:29:39 UTC, bearophile wrote: See also this old ER of mine: http://d.puremagic.com/issues/show_bug.cgi?id=4733 Bye, bearophile Thank you. This clears up the question. Long story short: the re

Something like godoc

2013-01-09 Thread MrOrdinaire
Hi, In Go, I can just install the documentation and later consult it using the godoc command, e.g. `godoc fmt Println` would give the documentation for the Println Function inside the fmt package. Is there anything like that for D? Thanks, Minh

Re: Truth value of an empty slice

2013-01-09 Thread MrOrdinaire
On Wednesday, 9 January 2013 at 13:29:39 UTC, bearophile wrote: See also this old ER of mine: http://d.puremagic.com/issues/show_bug.cgi?id=4733 Bye, bearophile Thank you. This clears up the question.

Re: dynamic arrays of immutable question: Are the elements actually mutable

2013-01-09 Thread monarch_dodra
On Wednesday, 9 January 2013 at 12:38:13 UTC, Jonathan M Davis wrote: When you append to array, the elements being added are in untyped memory. So, no mutation of immutable anything is going on at all. Ok, I guess that makes sense. I don't know what Appender is doing, but casting away immut

Re: Truth value of an empty slice

2013-01-09 Thread bearophile
See also this old ER of mine: http://d.puremagic.com/issues/show_bug.cgi?id=4733 Bye, bearophile

Re: Inner function overload bug?

2013-01-09 Thread Philippe Sigaud
On Wed, Jan 9, 2013 at 12:52 PM, Era Scarecrow wrote: >> That's weird. Why does that work? Directly pasting the mixin content in >> main() does not compile, right? > > I can only assume if it does work, that the mixin template has it's own > scope that enables the overloading. If you can't do it

Re: Truth value of an empty slice

2013-01-09 Thread bearophile
MrOrdinaire: Does it mean that the truth value of an empty slice depends on the underlying array, not on the number of elements the slice has, i.e. its length? The short answer is that the safe and readable way to do that in D is to use std.array.empty. Bye, bearophile

Truth value of an empty slice

2013-01-09 Thread MrOrdinaire
Hi, I am not sure why the following code would throw a range violation whenever haystack does not contain needle. int[] find(int[] haystack, int needle) { while (haystack && haystack[0] != needle) haystack = haystack[1 .. $]; return haystack; } Testing for haystack.length > 0

Re: dynamic arrays of immutable question: Are the elements actually mutable

2013-01-09 Thread Jonathan M Davis
On Wednesday, January 09, 2013 13:29:43 monarch_dodra wrote: > I was investigating the inner working of appender, and I'm not > 100% sure what it is doing with arrays of immutables is > completely kosher. > > However, I'm not 100% how arrays of immutables work. > > In particular, since dynamic ar

dynamic arrays of immutable question: Are the elements actually mutable

2013-01-09 Thread monarch_dodra
I was investigating the inner working of appender, and I'm not 100% sure what it is doing with arrays of immutables is completely kosher. However, I'm not 100% how arrays of immutables work. In particular, since dynamic arrays can be appended to, by design, the elements can be mutated, right?

Re: Inner function overload bug?

2013-01-09 Thread Era Scarecrow
On Wednesday, 9 January 2013 at 12:03:30 UTC, dennis luehring wrote: Am 08.01.2013 22:43, schrieb Era Scarecrow: That just means my unittest wouldn't work, so either it has to be global or inside a struct/union/class (and global is not very likely). Thanks for clearing that up. isn't tha

Re: Inner function overload bug?

2013-01-09 Thread dennis luehring
Am 08.01.2013 22:43, schrieb Era Scarecrow: On Tuesday, 8 January 2013 at 21:12:34 UTC, Philippe Sigaud wrote: It's conform to the spec http://dlang.org/function.html Last line of the 'nested functions' subsection: "Nested functions cannot be overloaded." Nested functions cannot be overloaded

Re: Inner function overload bug?

2013-01-09 Thread Era Scarecrow
On Wednesday, 9 January 2013 at 10:53:53 UTC, Philippe Sigaud wrote: On Wed, Jan 9, 2013 at 1:53 AM, Andrej Mitrovic wrote: On 1/9/13, bearophile wrote: If you define an inner static struct, its static methods can call each other freely. You can also use a mixin template: mixin template S()

Re: Inner function overload bug?

2013-01-09 Thread Philippe Sigaud
On Wed, Jan 9, 2013 at 1:53 AM, Andrej Mitrovic wrote: > On 1/9/13, bearophile wrote: >> If you define an inner static struct, its static methods can call >> each other freely. > > You can also use a mixin template: > > mixin template S() > { > void test(ref int x) { x = test(); } > int t

Re: Enhancing foreach

2013-01-09 Thread Jacob Carlborg
On 2013-01-09 05:38, ixid wrote: A very minor change that would be elegant and easy for beginners: foreach(i;5) //stuff Allowing just a single number to mean the end point and a default starting point of zero is assumed, just as with iota it's possible to write it iota(5) or even 5.iota, i