Re: BigInt problem

2011-02-12 Thread bearophile
tsukikage: > Is it my program bug or bigint broken? http://d.puremagic.com/issues/show_bug.cgi?id=5568 Bye, bearophile

Re: using a binary tree container

2011-02-12 Thread Ali Çehreli
On 02/11/2011 04:55 PM, spir wrote: > Also, trees are not always O(logN): tries () are O(1) for access, > relative to number of elements, in fact their search is not related to > that factor, just like hash table instead to the length of keys > (O(log(length)). Yep. I should know: I had written

BigInt problem

2011-02-12 Thread tsukikage
Please see source in attachment. The output is M2 M3 M5 M7 M13 M17 M19 M31 M61 M89 M107 M127 M521 M607 M1279 M2203 M2281 M3217 M4253 M4423 *** M9689*** M9941 M11213 M19937 *** M21701*** M23209 It missed 2 Mersenne Primes 9689 & 21701. Is it my program bug or bigint broken? It seems subtle.

Re: exit() to end a function

2011-02-12 Thread Jonathan M Davis
On Saturday 12 February 2011 14:03:09 bearophile wrote: > A small D2 function: > > import std.c.stdlib: exit; > int foo(int x) { > if (x > 0) > return x; > exit(0); > //assert(0); > } > void main() {} > > > DMD 2.051 gives this compile-time error: > test.d(2): Error: function

Re: Get function name at compile time?

2011-02-12 Thread Simen kjaeraas
Sean Eskapp wrote: Is there a way to get a function's name at compile time, for instance as part of a template? Using .stringof doesn't work, and I can't find another way to do it. Any help? class FunctionWrapper(alias func) { string name = func.stringof; } This should work (and does

exit() to end a function

2011-02-12 Thread bearophile
A small D2 function: import std.c.stdlib: exit; int foo(int x) { if (x > 0) return x; exit(0); //assert(0); } void main() {} DMD 2.051 gives this compile-time error: test.d(2): Error: function test4.foo no return exp; or assert(0); at end of function If I comment out the th

Re: regex start-of-line

2011-02-12 Thread spir
On 02/12/2011 06:57 PM, Jesse Phillips wrote: "The pipe has the lowest precedence of all operators." Right, I guess this answers my question :) Denis -- _ vita es estrany spir.wikidot.com

Re: opIn_r not detected

2011-02-12 Thread Stewart Gordon
On 10/02/2011 22:32, spir wrote: On 02/10/2011 07:43 PM, Stewart Gordon wrote: That got me thinking. It would appear that it auto-dereferences only the left operand. Try adding this to your code and see: writeln(s2 == sp); Works, indeed, but using opEquals on s2, and because s2 is not "poin

Get function name at compile time?

2011-02-12 Thread Sean Eskapp
Is there a way to get a function's name at compile time, for instance as part of a template? Using .stringof doesn't work, and I can't find another way to do it. Any help? class FunctionWrapper(alias func) { string name = func.stringof; }

Re: How to call binary functions on primitive on runtime?

2011-02-12 Thread Jonathan M Davis
On Saturday 12 February 2011 10:49:15 Tom wrote: > how can I make an implementation of some thing like Foo: > >> assert(Foo("+", 1, 2) == 1+2); > >> assert(Foo("*", 3, 2) == 3*2); > > without writing a long switch with case for each operator like: > >> switch (oper) { > >> > >> case "+": return

How to call binary functions on primitive on runtime?

2011-02-12 Thread Tom
how can I make an implementation of some thing like Foo: >> assert(Foo("+", 1, 2) == 1+2); >> assert(Foo("*", 3, 2) == 3*2); without writing a long switch with case for each operator like: >> switch (oper) { >> case "+": return a+b; >> .. >> } I know how to implementation a compile-time equival

Re: regex start-of-line

2011-02-12 Thread Jesse Phillips
spir Wrote: > Hello, > > I have a regex bug in following conditions: users pass a series of regex > formats (strings) from which I create regex engines later used for lexing. To > ensure matching at start of (rest of) source, I prefix each format with '^'. > Right in most cases. But the follow

regex start-of-line

2011-02-12 Thread spir
Hello, I have a regex bug in following conditions: users pass a series of regex formats (strings) from which I create regex engines later used for lexing. To ensure matching at start of (rest of) source, I prefix each format with '^'. Right in most cases. But the following regex: `^(t

Re: Number of references to a Class Object

2011-02-12 Thread Jonathan M Davis
On Saturday 12 February 2011 08:45:03 d coder wrote: > > If you know roughly what to do and want to take a stab at producing a > > viable patch to fix the problem, then feel free. If it's solid, it may > > get in. I don't know. It doesn't hurt to try though (as long as you're > > prepared for the f

Re: assert(expression, error)

2011-02-12 Thread Jonathan M Davis
On Saturday 12 February 2011 08:38:45 spir wrote: > On 02/12/2011 05:27 PM, Jonathan M Davis wrote: > > Aside from enforce, this function is a one-liner. It's obvious that it > > should be inlined and that it _would_ be inlined if enforce isn't used. > > But if I were to use enforce, it couldn't be

Re: Number of references to a Class Object

2011-02-12 Thread d coder
> If you know roughly what to do and want to take a stab at producing a viable > patch to fix the problem, then feel free. If it's solid, it may get in. I > don't > know. It doesn't hurt to try though (as long as you're prepared for the fact > that it may not be accepted). Thanks for letting me k

Re: assert(expression, error)

2011-02-12 Thread spir
On 02/12/2011 05:27 PM, Jonathan M Davis wrote: Aside from enforce, this function is a one-liner. It's obvious that it should be inlined and that it _would_ be inlined if enforce isn't used. But if I were to use enforce, it couldn't be inlined. It's situations like that which really bother me. en

Re: assert(expression, error)

2011-02-12 Thread Jonathan M Davis
On Saturday 12 February 2011 08:05:15 Andrej Mitrovic wrote: > On 2/12/11, Jonathan M Davis wrote: > > But > > if > > your function isn't likely to be inlined anyway, or for some reason, you > > just > > don't like having the if statement, then enforce is just fine. > > > > - Jonathan M Davis >

Re: assert(expression, error)

2011-02-12 Thread bearophile
Andrej Mitrovic: > Right. That's why I need it in this case, since the library can return > null at runtime due to user or even (audio) hardware errors. So in your case enforce is OK. (In general, I suggest to use D design by contract a lot (with asserts)). Bye, bearophile

Re: Number of references to a Class Object

2011-02-12 Thread bearophile
d coder: > What do you guys suggest? I suggest you to be very careful before "adapting" code from Tango, because of troublesome license issues :-( Bye, bearophile

Re: assert(expression, error)

2011-02-12 Thread Andrej Mitrovic
On 2/12/11, Jonathan M Davis wrote: > But > if > your function isn't likely to be inlined anyway, or for some reason, you > just > don't like having the if statement, then enforce is just fine. > > - Jonathan M Davis > It's noticeable in code and partially self-documenting, that's why I use it. I

Re: Number of references to a Class Object

2011-02-12 Thread Jonathan M Davis
On Saturday 12 February 2011 07:44:05 d coder wrote: > > Also tango (for D 1.0) implements it. > > Link: > > http://www.dsource.org/projects/tango/docs/current/tango.core.WeakRef.htm > > l > > > > Might be worth a look if you are going to implement it for D 2.0. > > I looked at the D1 implementat

Re: Number of references to a Class Object

2011-02-12 Thread d coder
> Also tango (for D 1.0) implements it. > Link: > http://www.dsource.org/projects/tango/docs/current/tango.core.WeakRef.html > > Might be worth a look if you are going to implement it for D 2.0. > I looked at the D1 implementation. It depends on GC methods weakPointerCreate and weakPointerDestroy.

Re: assert(expression, error)

2011-02-12 Thread Jonathan M Davis
On Saturday 12 February 2011 07:05:34 Andrej Mitrovic wrote: > On 2/12/11, bearophile wrote: > > Andrej Mitrovic: > >> Yeah, enforce is great. > > > > Enforce is not disabled in release mode. > > Right. That's why I need it in this case, since the library can return > null at runtime due to user

Re: assert(expression, error)

2011-02-12 Thread Michel Fortin
On 2011-02-12 10:05:34 -0500, Andrej Mitrovic said: Btw, is the inline problem just a DMD implementation problem, or does enforce have to be fixed for that? DMD implementation problem. The inliner doesn't support ref, out, lazy, and delegate arguments at this time. Enforce uses a lazy secon

Re: assert(expression, error)

2011-02-12 Thread Jonathan M Davis
On Saturday 12 February 2011 06:54:01 bearophile wrote: > Andrej Mitrovic: > > Yeah, enforce is great. > > Enforce is not disabled in release mode. Currently a function with enforce > inside can't be nothrow, and it can't be inlined. Yeah. Well it makes no sense whatsover for a function with enfo

Re: assert(expression, error)

2011-02-12 Thread Andrej Mitrovic
On 2/12/11, bearophile wrote: > Andrej Mitrovic: > >> Yeah, enforce is great. > > Enforce is not disabled in release mode. Right. That's why I need it in this case, since the library can return null at runtime due to user or even (audio) hardware errors. > Currently a function with enforce > ins

Re: assert(expression, error)

2011-02-12 Thread bearophile
Andrej Mitrovic: > Yeah, enforce is great. Enforce is not disabled in release mode. Currently a function with enforce inside can't be nothrow, and it can't be inlined. Bye, bearophile

Re: assert(expression, error)

2011-02-12 Thread Andrej Mitrovic
Yeah, enforce is great. Here's one way I use it for external libraries in one of my projects: class sndfileException : Exception { this(SNDFILE *sndfile) { super(to!string(sf_strerror(sndfile))); } } auto handle = sf_open(args); // on failure returns null enforce(handle !is n

Re: assert(expression, error)

2011-02-12 Thread spir
On 02/12/2011 02:44 PM, Jonathan M Davis wrote: On Saturday 12 February 2011 05:23:06 spir wrote: Hello, Is there a way to specify what error to throw using (a variant of) assert: assert(n> 0, new ValueError("...")); (Sure, one can write: if (n<= 0) throw new ValueError(

Re: assert(expression, error)

2011-02-12 Thread Tomek Sowiński
spir napisał: > Is there a way to specify what error to throw using (a variant of) assert: > assert(n > 0, new ValueError("...")); > > (Sure, one can write: > if (n <= 0) > throw new ValueError("...")); > but the same remark applies to plain assert: the whole point of assert is

Re: assert(expression, error)

2011-02-12 Thread Jonathan M Davis
On Saturday 12 February 2011 05:23:06 spir wrote: > Hello, > > Is there a way to specify what error to throw using (a variant of) assert: > assert(n > 0, new ValueError("...")); > > (Sure, one can write: > if (n <= 0) > throw new ValueError("...")); > but the same remark applie

assert(expression, error)

2011-02-12 Thread spir
Hello, Is there a way to specify what error to throw using (a variant of) assert: assert(n > 0, new ValueError("...")); (Sure, one can write: if (n <= 0) throw new ValueError("...")); but the same remark applies to plain assert: the whole point of assert is to have it as builtin

Re: Number of references to a Class Object

2011-02-12 Thread Simon Buerger
On 12.02.2011 11:47, bearophile wrote: d coder: Is there a way fro the users like myself to vote up an issue on DMD Bugzilla. In this case I think voting is not so useful. I think that actually implementing weak references is better (and later they may be added to Phobos). It requires some

Re: Number of references to a Class Object

2011-02-12 Thread spir
On 02/12/2011 08:33 AM, d coder wrote: I believe what you're referring to is generally called a Weak Reference, which is a reference that the GC doesn't consider when deciding to keep an object alive, but that the GC will update if an object dies. There's a feature request at http://d.puremagic.c

Re: Number of references to a Class Object

2011-02-12 Thread bearophile
d coder: > Is there a way fro the users like myself to vote up an issue on DMD Bugzilla. In this case I think voting is not so useful. I think that actually implementing weak references is better (and later they may be added to Phobos). It requires some work and knowledge of D and its GC. rebin