Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Timon Gehr
On 07/06/2012 02:57 AM, Wouter Verhelst wrote: Jonathan M Davisjmdavisp...@gmx.com writes: On Thursday, July 05, 2012 21:32:11 dcoder wrote: Thanks for the thorough explanation, but it begs the question why not make strings be array of chars that have \0 at the end of it? Since, lots of D

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Timon Gehr
On 07/06/2012 03:40 AM, Wouter Verhelst wrote: Timon Gehrtimon.g...@gmx.ch writes: On 07/06/2012 02:57 AM, Wouter Verhelst wrote: To be fair, there are a _few_ areas in which zero-terminated strings may possibly outperform zero-terminated strings (appending data in the case where you know

Re: Parser generator?

2012-07-04 Thread Timon Gehr
On 07/04/2012 11:41 PM, Jonathan M Davis wrote: On Wednesday, July 04, 2012 15:32:16 Wouter Verhelst wrote: Jonathan M Davisjmdavisp...@gmx.com writes: On Wednesday, July 04, 2012 14:53:02 Wouter Verhelst wrote: Hi folks, Does someone know of a parser generator for D? If it doesn't exist,

Re: Debugging compiler crashes?

2012-07-02 Thread Timon Gehr
On 07/02/2012 08:38 PM, Wouter Verhelst wrote: Hi, I have a body of code which makes the compiler frontend segfault. Is there some automated tool which will help me produce a minimal testcase so I can file a bugreport? The body in question is fairly large, just posting that to a bugreport

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 12:47 PM, Namespace wrote: A friend of mine ask me why D's foreach isn't like C# Means, why is it like int[] arr = [1, 2, 3]; foreach (int val; arr) { foreach(val; arr) { and not foreach (int val in arr) { which it is more intuitive. To someone coming from C#, yes. I

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 01:01 PM, bearophile wrote: Namespace: A friend of mine ask me why D's foreach isn't like C# In D you often omit the type: foreach (val; arr) { Using in is better for the human programmers. Certainly not. (except if 'human' means 'python' or 'C#'.) It is just as good as ';'.

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 04:16 PM, bearophile wrote: Timon Gehr: Just because. This does not matter. Now and then I write foreach(x;y;data) error: found ';' when expecting ')' or foreach(x,y,data) or error: found ')' when expecting ';' foreach(x;y,data). error: undefined identifier y

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 04:23 PM, Timon Gehr wrote: ... foreach(x;y,data). error: undefined identifier y BTW, it would certainly be better if this didn't actually pass the parser.

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 04:34 PM, bearophile wrote: Timon Gehr: foreach(x in y,data) There is no way to avoid all possible mistakes, but it's easier to mistake a ; for a ,, than mistake a in for a ,. I don't think optimizing the grammar for error cases that are not even compilable code

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 06:09 PM, Namespace wrote: It wasn't my intention to start a syntax war. :D But i must agree, that in is a lot more readable as ;. Event : ist more readable as ;. But i just would know the real reason to this decision. Tanks to all. :) But why correct a few guys here my code? It

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 06:27 PM, Namespace wrote: You mean just change line 3817 to if (t-value == TOKcomma || t-value == TOKsemicolon || t-value == TOKin) ? But know i have to rebuild dmd (i use windows), and i never did this before. :/ You'll also have to change the line that says

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 07:47 PM, Namespace wrote: On Friday, 29 June 2012 at 17:08:36 UTC, Namespace wrote: Which is easy. Even on Windows? :O I tried with win32.mak in src/dmd and i get a dmd.exe. But the compiler still says found 'in' when expecting ';'! if i try to write foreach (val in vals) {.

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 07:50 PM, Namespace wrote: You'll also have to change the line that says expect(TOKsemicolon); In what? comment out? Looking at some other parts of the parse.c source reveals that if(token.value == TOKin) nextToken(); else expect(TOKsemicolon); might get you going.

Re: How would I sort an associative array by value?

2012-06-29 Thread Timon Gehr
On 06/29/2012 07:52 PM, ixid wrote: Or more generally does D have a library function so I can sort one array based on sorting the contents of another? sort!a[0]b[0](zip(basedOnThis, alsoSortThis)); This sorts both ranges in-place based on the contents of the first range.

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 08:04 PM, Namespace wrote: On Friday, 29 June 2012 at 17:55:57 UTC, Timon Gehr wrote: On 06/29/2012 07:50 PM, Namespace wrote: You'll also have to change the line that says expect(TOKsemicolon); In what? comment out? Looking at some other parts of the parse.c source reveals

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 08:18 PM, Namespace wrote: My bad: Replacing the line with the following, together with the other change you made, works: if(token.value == TOKin) nextToken(); else check(TOKsemicolon); Impressive, thanks a lot, sometimes I'm a bit stupid. :) Last question: It works fine, but

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 09:51 PM, Namespace wrote: But there is no overhead or something else _if_ i put the type, or? There is a slight typing and compilation overhead. Nothing significant.

Re: foreach syntax

2012-06-29 Thread Timon Gehr
On 06/29/2012 10:02 PM, Roman D. Boiko wrote: On Friday, 29 June 2012 at 19:52:33 UTC, Timon Gehr wrote: On 06/29/2012 09:51 PM, Namespace wrote: But there is no overhead or something else _if_ i put the type, or? There is a slight typing and compilation overhead. Nothing significant. You

Re: Bug in Auto Functions and Template? Or Am I Just Crazy...

2012-06-27 Thread Timon Gehr
On 06/27/2012 11:07 AM, Michael wrote: Hello all, I came across some weird behaviors yesterday and I can't figure out what it's about. (1) auto factorial(int n) { if (n 2) return 1; return n * factorial(n-1); } The compiler complained about forward declaration of factorial. If I

Re: Bug in Auto Functions and Template? Or Am I Just Crazy...

2012-06-27 Thread Timon Gehr
On 06/27/2012 01:24 PM, Timon Gehr wrote: On 06/27/2012 11:07 AM, Michael wrote: Hello all, I came across some weird behaviors yesterday and I can't figure out what it's about. (1) auto factorial(int n) { if (n 2) return 1; return n * factorial(n-1); } The compiler complained

Re: Removing from SList (std.container)...

2012-06-27 Thread Timon Gehr
On 06/27/2012 08:46 PM, Roman D. Boiko wrote: On Wednesday, 27 June 2012 at 18:26:46 UTC, Steven Schveighoffer wrote: The thing that makes SList useless is the O(n) removal. Nobody will ever use SList when they can write a replacement that has O(1) removal in 10 minutes. Do you mean something

Re: Circle Calculator Help

2012-06-26 Thread Timon Gehr
On 06/26/2012 09:43 PM, Steven Schveighoffer wrote: On Tue, 26 Jun 2012 10:40:18 -0400, Alexander alexan...@alexandermohn.com wrote: ... //Wait void wait() { writefln (Type A to continue!); exittest(); } //Exit tester void exittest() { char[] a; stdin.readln(a); if (a == A)

Re: Circle Calculator Help

2012-06-26 Thread Timon Gehr
On 06/27/2012 01:40 AM, Steven Schveighoffer wrote: On Tue, 26 Jun 2012 19:10:25 -0400, bearophile bearophileh...@lycos.com wrote: Steven Schveighoffer: I agree with Andrei, there is no outlet for errors in the to!T function, exception is the logical choice. Maybe I was not clear enough,

Re: Stack overflow

2012-06-25 Thread Timon Gehr
On 06/25/2012 02:48 AM, Jonathan M Davis wrote: On Sunday, June 24, 2012 19:03:17 Namespace wrote: This might work: this(U)(U obj) if(is(U : T) !is(U == typeof(null))) { } - Jonathan M Davis Interesting. With or wihtout that, if i add a method to Foo it prints Stack overflow also.

Re: front doesn't compile for arrays of immutable data

2012-06-25 Thread Timon Gehr
On 06/25/2012 04:27 PM, Roman D. Boiko wrote: @property ref T front(T)(T[] a) if (!isNarrowString!(T[]) !is(T[] == void[])) { assert(a.length, Attempting to fetch the front of an empty array of ~ typeof(a[0]).stringof); return a[0]; } Why is front returned by ref even when it is not possible

Re: Stack overflow

2012-06-25 Thread Timon Gehr
On 06/25/2012 02:18 PM, Namespace wrote: Fine. But nothing of them explain the Stack overflow if i add an additional method or disable/add an additional ctor. It does not have to be explained: it is a compiler bug.

Re: Stack overflow

2012-06-24 Thread Timon Gehr
On 06/24/2012 12:37 PM, David wrote: Am 24.06.2012 11:35, schrieb Namespace: A non-nullable type _will_ be added to Phobos at some point. As struct or class or as built-in type? And can me explain somebody why [code] @disable this(typeof(null)); [/code] print Stack overflow? What should

Re: Address of TLS variables

2012-06-23 Thread Timon Gehr
On 06/23/2012 09:51 PM, Alex Rønne Petersen wrote: Hi, Does taking the address of a TLS variable and passing it to other threads have defined semantics? I would assume it results in a pointer to the thread's instance of the TLS variable (which makes sense), I'd assume that it results in a

Re: Allocate an Array!T on the heap?

2012-06-22 Thread Timon Gehr
On 06/22/2012 08:45 AM, Tobias Pankrath wrote: import std.container; struct A {}; void main() { Array!(A)* arr = new Array!(A); } yields bug.d(7): Error: template std.container.Array!(A).Array.__ctor does not match any function template declaration /usr/include/d/std/container.d(1625):

Re: const behaviour

2012-06-22 Thread Timon Gehr
On 06/22/2012 11:21 AM, Namespace wrote: Based to the current const discussions (once again) I wanted to appease my curiosity and want to ask why the following code works as described in the comments: [code] import std.stdio; class Bar { } class Foo { private: string _text; Bar

Re: Stack overflow

2012-06-22 Thread Timon Gehr
On 06/22/2012 12:22 PM, Namespace wrote: I have this code: http://codepad.org/vz17iZrm And as long as i comment out the assert's in the constructor on line 10 and the assert in the invariant on line 16 it works as i want. But otherwise the compiler prints stackoverflow and that's all. Why and

Re: const behaviour

2012-06-22 Thread Timon Gehr
On 06/22/2012 12:25 PM, Namespace wrote: As far as i know int is not immutable or const by default. So, why work this code: [code] import std.stdio; class Bar { } class Foo { private: int _id; Bar _b; public: this(int id, Bar b) { this._id = id; this._b =

Re: what is the difference between static method of the class, module method and static method of the module?

2012-06-20 Thread Timon Gehr
On 06/20/2012 09:52 PM, bearophile wrote: Alex Rønne Petersen: The static keyword has no effect on module functions, so 2 and 3 are equivalent. This problem is caused by DMD sloppyness regarding its management of attributes. A serious language doesn't accept a keyword like static where it

Re: D: Unexpected output when using a delegate and EnumMembers

2012-06-19 Thread Timon Gehr
On 06/19/2012 04:44 PM, Travis Gockel wrote: I am clearly doing something wrong, You are not. but I have no idea what and would appreciate some insight. You have found a bug in DMD. Reduced test case that should compile: template Seq(T...){alias T Seq;} auto exec(alias a)(){return

Re: D: Unexpected output when using a delegate and EnumMembers

2012-06-19 Thread Timon Gehr
On 06/19/2012 05:08 PM, Artur Skawina wrote: Yes, it can be surprising, but I'm not convinced it's actually wrong behavior (the bug is http://d.puremagic.com/issues/show_bug.cgi?id=2043) It is not this bug. (And what is listed there is clearly wrong behaviour, because it can be used to break

Re: Does the 'with' statement affect object lifetime?

2012-06-19 Thread Timon Gehr
On 06/19/2012 07:51 PM, Ali Çehreli wrote: Bug? Bug.

Re: Swap furthest element type of an array

2012-06-18 Thread Timon Gehr
On 06/18/2012 06:29 PM, Andrej Mitrovic wrote: I just had a need for this but couldn't find it in Phobos: import std.stdio; import std.traits; import std.range; template SwapElem(Arr, Type) { static if (isArray!(ElementType!Arr)) { static if (isDynamicArray!Arr)

Re: Swap furthest element type of an array

2012-06-18 Thread Timon Gehr
On 06/19/2012 12:01 AM, Andrej Mitrovic wrote: On 6/18/12, Timon Gehrtimon.g...@gmx.ch wrote: template SwapElem(A, E){ static if(is(A X:X[N],size_t N)) alias SwapElem!(X,E)[N] R; else static if(is(A X:X[])) alias SwapElem!(X,E)[] R; else static if(is(A X:X*)) alias

Re: Using consistently auto as function return type

2012-06-16 Thread Timon Gehr
On 06/16/2012 11:31 AM, Tommi wrote: Do you consider it to be good or bad style of programming to use consistently auto as function return type? One of the pros is that it saves some redundant typing when the function returns some complex templated type: auto getValue() { return

Re: sorting associative array's keys by values

2012-06-16 Thread Timon Gehr
On 06/16/2012 06:34 PM, maarten van damme wrote: Right now I have an associative array int[string] aa and stored the keys in string[] keys. Now I want to sort keys[] so that aa[keys[0]]aa[keys[1]] I remember someone gave the answer to that question on stackoverflow but after some googling I

Re: sorting associative array's keys by values

2012-06-16 Thread Timon Gehr
On 06/16/2012 06:41 PM, Timon Gehr wrote: On 06/16/2012 06:34 PM, maarten van damme wrote: Right now I have an associative array int[string] aa and stored the keys in string[] keys. Now I want to sort keys[] so that aa[keys[0]]aa[keys[1]] I remember someone gave the answer to that question

Re: sorting associative array's keys by values

2012-06-16 Thread Timon Gehr
On 06/16/2012 07:51 PM, maarten van damme wrote: For some crazy reason my program now crashes on seemingly random locations when parsing content of the form: div class=details h1 class=uniquerandomname/h1 I want to extract randomname but an xml parser would be overkill so I

Re: Constraining template's function parameter signature

2012-06-14 Thread Timon Gehr
On 06/14/2012 02:57 PM, Tommi wrote: I'm trying to constrain a struct template based on a parameter that's supposed be a function with a certain signature. Difficult to explain, easier just to show the problem: module pseudorange; struct PseudoInputRange(T, alias advance) //The next line

Re: How to specialize templates for l-value and non-l-value arguments?

2012-06-14 Thread Timon Gehr
You can overload based on 'ref'. auto just(ref immutable(T) data) { return Maybe!T(data); } auto just(immutable(T) data) { return Maybe!T([data].ptr); }

Re: Immutability and other attributes, please review

2012-06-14 Thread Timon Gehr
On 06/14/2012 06:42 PM, Jonathan M Davis wrote: I wish that you could do auto f = new float(2.1); and therefore auto f = new immutable(float)(2.1); but you can't. This seems to be an arbitrary limitation. Imho it should be fixed. Probably it was missed because allocating a primitive type

Re: Package and virtual functions

2012-06-13 Thread Timon Gehr
On 06/14/2012 01:34 AM, BLM768 wrote: override will eventually be required when overriding a function. It is already if you compile with -w but not yet all of the time - though since protected isn't virtual and isn't really overriding anything, the compiler doesn't complain if you don't use

Re: Package and virtual functions

2012-06-13 Thread Timon Gehr
On 06/14/2012 01:57 AM, BLM768 wrote: I guess that another solution to this whole mess is to just start requiring the use of override; then everyone would be educated and it would be obvious where the bug is in the code I posted. Since we don't want to break code, though, maybe there should be a

Re: Auto-conversion in array literals?

2012-06-11 Thread Timon Gehr
On 06/12/2012 12:55 AM, bearophile wrote: This is valid Scala code: object Main { def main(args: Array[String]): Unit = { val a: List[BigInt] = List(1, BigInt(2)) } } Is it possible/meaningful to support/allow D code like this? import std.bigint; void main() {

Re: Is it possible to force CTFE?

2012-06-10 Thread Timon Gehr
On 06/10/2012 09:04 AM, Tommi wrote: Three related questions: 1) Is there a way to force a function to be always executed at compile time (when it's possible to do so) no matter what context it's called in? No there is not. You could use a template that calls a private function at compile

Re: Multi-Dimensional Associative Arrays .get and in

2012-06-08 Thread Timon Gehr
On 06/06/2012 04:17 PM, Paul wrote: I've seen examples using .get and in to test for keys: aa.get(hello, salute) == ciao hello in aa Can I use this .get function or in operator with multi-D arrays? string[string][string][string] aa; if ([hello][][] in aa) ? Well,

Re: alias this with template class?

2012-06-03 Thread Timon Gehr
On 06/03/2012 08:43 PM, Namespace wrote: I think this should work: [code] import std.stdio; class Foo(T) { public: T Num; @property Foo!(U) ConvertTo(U)() inout { return cast(Foo!(U)) this; } alias ConvertTo this; } void Call(const Foo!(float) FFoo) { }

Re: Make all functions from std.typecons Proxy inout

2012-05-11 Thread Timon Gehr
On 05/11/2012 08:56 AM, Kenji Hara wrote: The spec: http://dlang.org/template#TemplateThisParameter doesn't talk about typeof(this). I think current behavior is less useful than I have thought. What would the current behavior be useful for? And, current std.typecons.Proxy doesn't work as

Re: foreach_reverse error

2012-05-09 Thread Timon Gehr
On 05/09/2012 10:50 PM, ixid wrote: With this code foreach works but foreach_reverse does not: void main() { int[] ints = [2,2,2,5,5,5,4,4,4]; auto temp = group(ints); foreach_reverse(i;temp) i[1].writeln; } Is this a known issue? Is there a sensible reason for this? group returns a

Re: foreach_reverse error

2012-05-09 Thread Timon Gehr
On 05/09/2012 11:33 PM, ixid wrote: Thanks, sorry to have not understand such a basic point, it's rather hard to get to grips with everything like this in D. No worries.

Re: static means too many things

2012-05-02 Thread Timon Gehr
On 05/02/2012 01:46 AM, bearophile wrote: This is the brief of some D code, it shows one consequence of the excessive overloading of the D static keyword: struct Foo { bool solve() { /*static*/ bool fill(int r, int c, Cell n) { // ... if (fill(r + i, c + j, n

Re: Conditional compilation for non-release version

2012-04-28 Thread Timon Gehr
On 04/28/2012 02:05 PM, Joseph Rushton Wakeling wrote: Hello all, I've just been reading through this page: http://dlang.org/version.html Is there a way to put in place a conditional segment of code that is included if the code is _not_ compiled with the -release flag? Of course I can put in

Re: Docs: Section on local variables

2012-04-26 Thread Timon Gehr
On 04/25/2012 06:10 PM, Andrej Mitrovic wrote: On 4/25/12, Stewart Gordonsmjg_1...@yahoo.com wrote: Even if it's left over from debugging, it looks silly, and might lead other people reading the code to believe something's wrong. There's about a million ways to make code unreadable, and

Re: Pointer to variables in D

2012-04-26 Thread Timon Gehr
On 04/26/2012 04:43 AM, Victor Vicente de Carvalho wrote: Hi there, In c++ one can access a pointer to a class/struct variable using this semantic: struct C { int x; }; int C::* ptr = C::x; C foo; foo.*ptr = 10; assert(foo.x == 10); It is possible to do something like that on D? I've

Re: No implicitly convert derived ptr to base ptr?

2012-04-25 Thread Timon Gehr
On 04/25/2012 07:50 AM, Nick Sabalausky wrote: The compiler rejects this: class Base {} class Derived : Base {} void main() { Base*basePtr; Derived* derivedPtr; basePtr = derivedPtr; // ERROR } Is that really correct that it shouldn't

Re: Stack overflow / recursive expansion with alias this

2012-04-24 Thread Timon Gehr
On 04/23/2012 11:29 PM, Namespace wrote: I have this code: ... T _get() { return this._value; } const(T) _get() const { return this._value; } You missed the 'immutable' and 'inout cases. Just use inout(T) _get() inout { return _value; } instead of the

Re: How to pass list of strings as compile-time parameters?

2012-04-24 Thread Timon Gehr
On 04/24/2012 07:37 PM, H. S. Teoh wrote: I'm trying to write a template function for doing member-wise comparisons between two objects, with an optional list of members to ignore. But I can't seem to figure out the syntax for passing a list of strings (or an AA of strings) to the function? I

Re: Stack overflow / recursive expansion with alias this

2012-04-24 Thread Timon Gehr
On 04/24/2012 07:09 PM, Namespace wrote: ... And therefore i get the same error, as if i wrote return NotNull!(Foo)(this); instead of return assumeNotNull(this);, in the _convert method of NotNull. The Output is Stack overflow. I think that comes from recursive calls which fills the stack? Is

Re: Keyword to avoid not null references

2012-04-21 Thread Timon Gehr
On 04/21/2012 11:40 PM, Namespace wrote: My question is, why D hasn't got an explicit Keyword to check at compile time for non null references? It shouldn't be a special keyword. If the compiler can do the necessary analysis to actually enforce that the reference cannot hold a null

Re: Keyword to avoid not null references

2012-04-21 Thread Timon Gehr
On 04/22/2012 12:48 AM, Namespace wrote: On Saturday, 21 April 2012 at 22:18:02 UTC, Adam D. Ruppe wrote: We can do not null in the library reasonably well. I have a basic one in github: https://github.com/D-Programming-Language/phobos/pull/477 So every time i want to avoid null references i

Re: pure functions/methods

2012-04-20 Thread Timon Gehr
On 04/20/2012 10:06 AM, Namespace wrote: The sense of pure functions isn't clear to me. What is the advantage of pure functions / methods? 1. It enables stateless reasoning about program parts. 2. It enables certain compiler optimizations. I inform the compiler with const that this method

Re: variadic mixin templates and other stuff

2012-04-20 Thread Timon Gehr
On 04/20/2012 03:23 PM, Martin Drasar wrote: Hi, I am migrating a C++ project to D and I have hit a roadblock that I hope you might help me with. My code is heavily inspired by the COM architecture, so I have naturally take a look at std/c/windows/com.d, just to find out that it does not

Re: Immutable Structs and std.concurrency

2012-04-19 Thread Timon Gehr
On 04/19/2012 03:27 PM, Russel Winder wrote: The program: import std.concurrency ; import std.stdio ; /*immutable*/ struct X { int i ; } void printI ( ) { receive ( ( X x ) { writeln ( x.i ) ; } ) ;

Re: Immutable Structs and std.concurrency

2012-04-19 Thread Timon Gehr
On 04/19/2012 11:11 PM, Jakob Ovrum wrote: Fixing std.concurrency entails fixing std.variant which entails fixing std.typecons.Rebindable by moving its functionality into the language where it belongs. https://github.com/D-Programming-Language/dmd/pull/3 This one has been lurking around

Re: Immutable Structs and std.concurrency

2012-04-19 Thread Timon Gehr
On 04/19/2012 11:55 PM, Jakob Ovrum wrote: On Thursday, 19 April 2012 at 21:33:46 UTC, Timon Gehr wrote: Unfortunately the patch is incomplete. (template parameter matching is not implemented afaik and it does not work for structs) Ah, didn't know about the template blocker, but how should

Re: retro() on a `string` creates a range of `dchar`, causing array() pains

2012-04-17 Thread Timon Gehr
On 04/17/2012 06:09 PM, Ali Çehreli wrote: On 04/17/2012 08:58 AM, bearophile wrote: Ali Çehreli: The reason is, a sequence of UTF-8 code units are not a valid UTF-8 when reversed (or retro'ed :p). But reversed(char[]) now works :-) That's pretty cool. :) (You meant reverse()).

Re: Aquivalent References as in C++?

2012-04-17 Thread Timon Gehr
On 04/17/2012 08:10 PM, Namespace wrote: Best of all solutions would be that a special keyword, for example scope, ensure that lvalues would except but _no_ null-references. Yes, the keyword would be a little shorter than the assert() or enforce() above but D already has very many keywords.

Re: Aquivalent References as in C++?

2012-04-17 Thread Timon Gehr
On 04/17/2012 08:40 PM, Namespace wrote: Define 'ensure'. Guarantee, that the given object parameter isn't a null reference. But C++ does not do that either. Are you asking for a full-blown non-null type system?

Re: Aquivalent References as in C++?

2012-04-17 Thread Timon Gehr
On 04/17/2012 09:16 PM, Namespace wrote: But C++ does not do that either. Are you asking for a full-blown non-null type system? Yes, but of course only with a special Keyword/Storage class. If it is not the default, how would you enforce it at the caller side?

Re: const AB c = {a,20, numbers};

2012-04-16 Thread Timon Gehr
On 04/16/2012 06:49 PM, bearophile wrote: sclytrack: ... Shouldn't the code above accept the const(int []) ? I think it is a bug that it does not. I think you are asking too much to the poor type system. You are giving a const dynamic array (that's not a value) to assign it to a

Re: Aquivalent References as in C++?

2012-04-16 Thread Timon Gehr
On 04/16/2012 11:25 PM, Namespace wrote: Hi, I have a few questions about D and could use some help. For instance, how can i rebuild such a behavior? class Foo { public: Foo(const Bar b) { At C++ you can ensure that a reference is requested and must not null. Nevertheless lvalues are

Re: const AB c = {a,20, numbers};

2012-04-16 Thread Timon Gehr
On 04/16/2012 11:43 PM, bearophile wrote: Timon Gehr: auto c = AB(a, 20, numbers)=AB c = {a, 20, numbers}; auto c = const(AB)(a, 20, numbers)=const AB c = {a, 20, numbers}; I think your second equivalence is wrong: const c = AB(a, 20, numbers)=const AB c = {a, 20, numbers}; Bye

Re: D 50% slower than C++. What I'm doing wrong?

2012-04-16 Thread Timon Gehr
On 04/17/2012 12:24 AM, ReneSac wrote: On Monday, 16 April 2012 at 07:28:25 UTC, Andrea Fontana wrote: Are you on linux/windows/mac? Windows. DMC runtime ! My main question is now *WHY* D is slower than C++ in this program? The code is identical (even the same C functions) No. They are

Re: D 50% slower than C++. What I'm doing wrong?

2012-04-15 Thread Timon Gehr
On 04/15/2012 02:23 PM, Kevin Cox wrote: On Apr 15, 2012 4:30 AM, Joseph Rushton Wakeling joseph.wakel...@webdrake.net mailto:joseph.wakel...@webdrake.net wrote: ... the compiler accepts it. Whether that's because it's acceptably pure, or because the compiler just doesn't detect this case of

Re: Higher-order functions?

2012-04-11 Thread Timon Gehr
On 04/11/2012 11:37 AM, Xan wrote: On Wednesday, 11 April 2012 at 09:17:12 UTC, Jacob Carlborg wrote: On 2012-04-11 10:45, Xan wrote: Good answer. For the other hand, what is the simplest method for implementing this (in pseucode) in D: Sure: FUNC someprocedure(int a, int b, funcint, int:

Re: Higher-order functions?

2012-04-11 Thread Timon Gehr
On 04/11/2012 11:51 AM, Xan wrote: On Wednesday, 11 April 2012 at 09:43:27 UTC, Timon Gehr wrote: On 04/11/2012 11:37 AM, Xan wrote: On Wednesday, 11 April 2012 at 09:17:12 UTC, Jacob Carlborg wrote: On 2012-04-11 10:45, Xan wrote: Good answer. For the other hand, what is the simplest

Re: Higher-order functions?

2012-04-10 Thread Timon Gehr
On 04/11/2012 01:13 AM, Jonas H. wrote: Hi everyone, does D have any runtime higher-order function facilities? D has full runtime support for higher-order functions and closures. import std.stdio; int[] map(scope int delegate(int) f, int[] a){ auto b = new int[a.length];

Re: Issue with const

2012-04-09 Thread Timon Gehr
On 04/09/2012 04:49 PM, Jacob Carlborg wrote: But now when I compile this code I get this error: Error: cannot implicitly convert expression (this.data) of type const(void*) to void* Any idea how to solve this? Or would I need to drop const. -- /Jacob Carlborg Either clone the data too or

Re: Operator Overloading : opOpAssign

2012-04-08 Thread Timon Gehr
On 04/08/2012 07:56 PM, Eyyub wrote: Hai, I would to know how to overload this operator and why I have this error at compile-time : http://paste.pocoo.org/show/vlfSSekGLCAriCJpiZvp/ Thanks a lot. Try void opOpAssign(string op)(const Matrix other) if(op == +) I think the fact that

Re: Operator Overloading : opOpAssign

2012-04-08 Thread Timon Gehr
On 04/08/2012 10:06 PM, Eyyub wrote: It works with : http://paste.pocoo.org/show/4oIhMg5eBdUoirhk5iYS/ Thanks for all, kiss ! You don't need/want the 'ref's there.

Re: asm stackframe question

2012-04-07 Thread Timon Gehr
On 04/08/2012 12:13 AM, Stefan wrote: As a little learning exercise for D I’m writing a fixed point library. Part of this is checking standard integer operations for overflows. This is the code for adding 2 longs: int64 add64ov(int64 a, int64 b) { int64 res; asm { mov EAX,a ; mov EDX,a+4 ; add

Re: Questions about the slice operator

2012-04-05 Thread Timon Gehr
On 04/04/2012 12:06 PM, Jacob Carlborg wrote: On 2012-04-04 04:11, Jonathan M Davis wrote: foreach(i; 0 .. 5) is more efficient only because it has _nothing_ to do with arrays. Generalizing the syntax wouldn't help at all, and if it were generalized, it would arguably have to be consistent in

Re: log2 buggy or is a real thing?

2012-04-04 Thread Timon Gehr
On 04/04/2012 05:15 PM, Don Clugston wrote: I don't think so. For 80-bit reals, every long can be represented exactly in an 80 bit real, as can every ulong from 0 up to and including ulong.max - 1. The only non-representable built-in integer is ulong.max, which (depending on rounding mode) gets

Re: log2 buggy or is a real thing?

2012-04-04 Thread Timon Gehr
On 04/04/2012 01:46 PM, bearophile wrote: Do you know why is this program: import std.stdio; void main() { real r = 9223372036854775808UL; writefln(%1.19f, r); } Printing: 9223372036854775807.800 Instead of this? 9223372036854775808.000 Bye,

Re: Custom Allocators

2012-04-03 Thread Timon Gehr
On 04/03/2012 05:47 AM, James Miller wrote: I've been doing some reading on dlang.org and the newsgroup archives and have seen talk about allocators and things around the garbage collector. I have a few questions about the entire thing: - I understand that allocators are all about memory

Re: Min-Heap and Hash Table help

2012-04-03 Thread Timon Gehr
On 04/03/2012 05:17 AM, Chris Pons wrote: I'm still having troubles with the min-heap. Node[] a; auto b = BinaryHeap!a.fScore b.fScore( a[] ); Error 1 Error: template instance BinaryHeap!(a.fScore b.fScore) BinaryHeap!(a.fScore b.fScore) does not match template declaration

Re: HelloWordl in Webserver

2012-04-03 Thread Timon Gehr
On 04/03/2012 10:45 AM, Xan wrote: On Tuesday, 3 April 2012 at 08:42:01 UTC, Xan wrote: I receive errors: xan@gerret:~/proves/dlang-proves$ ls cgi.d functions.d httpd.d netman.d server.d xan@gerret:~/proves/dlang-proves$ gdmd-4.6 server.d cgi.d netman.d httpd.d httpd.d:5: Error: module netman

Re: ref const parameters in functions

2012-04-02 Thread Timon Gehr
On 04/02/2012 06:23 AM, Jonathan M Davis wrote: No. It's not. It's a temporary, and temporaries are almost always rvalues. The sole (and very bizarre) exception is struct literals (e.g. ABC(20) is currently considered an lvalue). DMD 2.059head treats struct literals as rvalues.

Re: Nested interface

2012-04-01 Thread Timon Gehr
On 04/01/2012 08:13 PM, Read Bixby wrote: Hm, I guess it's much simpler than that. I must not be understanding something about covariance. The following code produces the same error message (it has nothing to do with nestedness or shared classes): interface Interface { Interface

Re: Is this a bug in overload resolution?

2012-03-30 Thread Timon Gehr
On 03/30/2012 01:53 PM, Andrej Mitrovic wrote: class Foo { bool test() { return true; } } class Bar { this() { foo = new Foo; } Foo foo; alias foo this; } class FooBar : Bar { bool test(int x) { return true; } alias super.test test; } void main() {} test.d(17):

Re: Where does U in Rebindable.Rebindable come from?

2012-03-30 Thread Timon Gehr
On 03/30/2012 09:20 PM, Philippe Sigaud wrote: On Fri, Mar 30, 2012 at 01:09, Simen Kjæråssimen.kja...@gmail.com wrote: The same pattern is used in std.typecons.isTuple: template isTuple(T) { static if (is(Unqual!T Unused : Tuple!Specs, Specs...)) { Wait, does that work now? Yes.

Re: Problem about lambda expressions

2012-03-28 Thread Timon Gehr
On 03/28/2012 10:28 AM, Tongzhou Li wrote: On Wednesday, 28 March 2012 at 08:22:25 UTC, Tongzhou Li wrote: I understood. But why it compiles instead of giving an error? What does the complier do when I write the wrong code? Oh, I mean if I write the wrong code, what objectcode does the

Re: GC collecting too much..

2012-03-26 Thread Timon Gehr
On 03/26/2012 11:55 AM, simendsjo wrote: It seems threads created in the c library is totally unknown to D. How can I make D aware of these threads when there is no library support for it? You may be looking for this: http://dlang.org/phobos/core_thread.html#thread_attachThis

Re: Referencing an overloaded function

2012-03-24 Thread Timon Gehr
On 03/24/2012 09:07 PM, Philippe Sigaud wrote: On Sat, Mar 24, 2012 at 18:07, Artur Skawinaart.08...@gmail.com wrote: foreach (f; __traits(getOverloads, __traits(parent, main), foo)) { Hey, this ^^ it's a way to get the current module, right? Nice trick, I didn't

Re: Making sense of ranges

2012-03-24 Thread Timon Gehr
On 03/25/2012 12:07 AM, Stewart Gordon wrote: On 24/03/2012 18:57, Ali Çehreli wrote: snip Iterating an output range is also by popFront(). So what it says is, put this element to the output range and advance the range. There is a gotcha about this when the output range is a slice: Whatever is

Re: Referencing an overloaded function

2012-03-24 Thread Timon Gehr
On 03/25/2012 12:34 AM, Artur Skawina wrote: On 03/24/12 23:10, Timon Gehr wrote: On 03/24/2012 09:07 PM, Philippe Sigaud wrote: On Sat, Mar 24, 2012 at 18:07, Artur Skawinaart.08...@gmail.com wrote: foreach (f; __traits(getOverloads, __traits(parent, main), foo)) { Hey

<    1   2   3   4   5   6   7   8   9   >