Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-04 Thread Artur Skawina
On 02/04/12 02:03, Timon Gehr wrote: On 02/03/2012 11:08 AM, Artur Skawina wrote: On 02/03/12 00:20, Jonathan M Davis wrote: in is pointless on value types. All it does is make the function parameter const, which really doesn't do much for you, and in some instances, is really annoying.

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-04 Thread Timon Gehr
On 02/04/2012 06:55 PM, Artur Skawina wrote: On 02/04/12 02:03, Timon Gehr wrote: On 02/03/2012 11:08 AM, Artur Skawina wrote: On 02/03/12 00:20, Jonathan M Davis wrote: in is pointless on value types. All it does is make the function parameter const, which really doesn't do much for you, and

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-04 Thread Artur Skawina
On 02/04/12 22:20, Timon Gehr wrote: On 02/04/2012 06:55 PM, Artur Skawina wrote: On 02/04/12 02:03, Timon Gehr wrote: On 02/03/2012 11:08 AM, Artur Skawina wrote: On 02/03/12 00:20, Jonathan M Davis wrote: in is pointless on value types. All it does is make the function parameter const,

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-04 Thread Timon Gehr
On 02/04/2012 11:23 PM, Artur Skawina wrote: On 02/04/12 22:20, Timon Gehr wrote: On 02/04/2012 06:55 PM, Artur Skawina wrote: On 02/04/12 02:03, Timon Gehr wrote: On 02/03/2012 11:08 AM, Artur Skawina wrote: On 02/03/12 00:20, Jonathan M Davis wrote: in is pointless on value types. All it

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-04 Thread Artur Skawina
On 02/04/12 23:44, Timon Gehr wrote: On 02/04/2012 11:23 PM, Artur Skawina wrote: On 02/04/12 22:20, Timon Gehr wrote: On 02/04/2012 06:55 PM, Artur Skawina wrote: Semi-related quiz: immutable(char)[] a = a; const(char)[] b = b; auto aa = a ~ a; auto bb = b ~ b;

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread Artur Skawina
On 02/03/12 00:20, Jonathan M Davis wrote: in is pointless on value types. All it does is make the function parameter const, which really doesn't do much for you, and in some instances, is really annoying. Personally, I see no point in using in unless the parameter is a reference type, and

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread Alex Rønne Petersen
On 03-02-2012 11:08, Artur Skawina wrote: On 02/03/12 00:20, Jonathan M Davis wrote: in is pointless on value types. All it does is make the function parameter const, which really doesn't do much for you, and in some instances, is really annoying. Personally, I see no point in using in unless

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread Artur Skawina
On 02/03/12 11:41, Artur Skawina wrote: On 02/03/12 11:21, Alex Rønne Petersen wrote: On 03-02-2012 11:08, Artur Skawina wrote: On 02/03/12 00:20, Jonathan M Davis wrote: in is pointless on value types. All it does is make the function parameter const, which really doesn't do much for you,

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread Alex Rønne Petersen
On 03-02-2012 11:41, Artur Skawina wrote: On 02/03/12 11:21, Alex Rønne Petersen wrote: On 03-02-2012 11:08, Artur Skawina wrote: On 02/03/12 00:20, Jonathan M Davis wrote: in is pointless on value types. All it does is make the function parameter const, which really doesn't do much for you,

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread Jonathan M Davis
On Friday, February 03, 2012 11:08:54 Artur Skawina wrote: BTW, scope should have been the default for *all* reference type function arguments, with an explicit modifier, say esc, required to let the thing escape. It's an all-or-nothing thing, just like immutable strings - not using it

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread Artur Skawina
On 02/03/12 13:06, Jonathan M Davis wrote: On Friday, February 03, 2012 11:08:54 Artur Skawina wrote: BTW, scope should have been the default for *all* reference type function arguments, with an explicit modifier, say esc, required to let the thing escape. It's an all-or-nothing thing, just

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread bearophile
Jonathan M Davis: in is pointless on value types. All it does is make the function parameter const, which really doesn't do much for you, and in some instances, is really annoying. Having const value types is useful because you can't change them later inside the method. This helps you avoid

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread bearophile
Artur Skawina: Would marking the ctor as scope (similarly to const or pure) work for your case? (it is reasonable to expect that the compiler checks this by itself; it's per-type, so not nearly as expensive as analyzing the flow) Maybe this is a topic worth discussing in the main D

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread xancorreu
Al 03/02/12 00:14, En/na bearophile ha escrit: xancorreu: But you only put a in in recFactorial function argument. What this mean? **Why** this is more efficient than mine? It wasn't meant to improve performance. in turns a function argument to input only (and eventually scoped too).

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread Timon Gehr
On 02/03/2012 11:08 AM, Artur Skawina wrote: On 02/03/12 00:20, Jonathan M Davis wrote: in is pointless on value types. All it does is make the function parameter const, which really doesn't do much for you, and in some instances, is really annoying. Personally, I see no point in using in

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread Timon Gehr
On 02/03/2012 01:06 PM, Jonathan M Davis wrote: On Friday, February 03, 2012 11:08:54 Artur Skawina wrote: BTW, scope should have been the default for *all* reference type function arguments, with an explicit modifier, say esc, required to let the thing escape. It's an all-or-nothing thing,

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread bearophile
Timon Gehr: However, it is nice that the shortest storage class, 'in', implies scope. I'd like to ask this to be valid, to shorten my code: alias immutable imm; Is this silly? Bye, bearophile

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-03 Thread Daniel Murphy
bearophile bearophileh...@lycos.com wrote in message news:jgi3jn$2o6p$1...@digitalmars.com... I'd like to ask this to be valid, to shorten my code: alias immutable imm; Is this silly? Yes =) immutable might be more characters than you want to type, but at this point it's extremely unlikely

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread bearophile
xancorreu: I get segment violation error with ./factorial 40 How can I resolve it? You are having a stack overflow. DMD currently doesn't print a good message because of this regression that is being worked on: http://d.puremagic.com/issues/show_bug.cgi?id=6088 On Windows with DMD you

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread xancorreu
Al 02/02/12 19:30, En/na bearophile ha escrit: xancorreu: I get segment violation error with ./factorial 40 How can I resolve it? You are having a stack overflow. DMD currently doesn't print a good message because of this regression that is being worked on:

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread Timon Gehr
On 02/02/2012 08:04 PM, xancorreu wrote: Al 02/02/12 19:30, En/na bearophile ha escrit: xancorreu: I get segment violation error with ./factorial 40 How can I resolve it? You are having a stack overflow. DMD currently doesn't print a good message because of this regression that is being

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread H. S. Teoh
On Thu, Feb 02, 2012 at 10:55:06PM +0100, Timon Gehr wrote: On 02/02/2012 08:04 PM, xancorreu wrote: [...] For the other hand, how can increase the stack in linux? [...] I don't know, but it is best to just rewrite the code so that it does not use recursion. (This kind of problem is

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread H. S. Teoh
On Thu, Feb 02, 2012 at 02:47:22PM -0800, H. S. Teoh wrote: [...] int fib(int n) { if (n = 2) return 1; else return fib(n-2) + fib(n+1); [...] Ugh. That should be fib(n-1), not fib(n+1). But no matter, such a thing shouldn't ever be actually written and

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread bearophile
xancorreu: But you only put a in in recFactorial function argument. What this mean? **Why** this is more efficient than mine? It wasn't meant to improve performance. in turns a function argument to input only (and eventually scoped too). Generally when you program in D2 it's a good

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread Timon Gehr
On 02/02/2012 11:47 PM, H. S. Teoh wrote: On Thu, Feb 02, 2012 at 10:55:06PM +0100, Timon Gehr wrote: On 02/02/2012 08:04 PM, xancorreu wrote: [...] For the other hand, how can increase the stack in linux? [...] I don't know, but it is best to just rewrite the code so that it does not use

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread bearophile
Timon Gehr: This is not a tail-recursive function. And neither is recFactorial, my bad. Anyway, my point was that the compiler should not generate code that blows up on a (in principle) perfectly sane implementation. Is it possible to create a function attribute like @tail_recursive that

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread Jonathan M Davis
On Thursday, February 02, 2012 18:14:25 bearophile wrote: xancorreu: But you only put a in in recFactorial function argument. What this mean? **Why** this is more efficient than mine? It wasn't meant to improve performance. in turns a function argument to input only (and eventually

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread Jonathan M Davis
On Thursday, February 02, 2012 18:17:36 bearophile wrote: Timon Gehr: This is not a tail-recursive function. And neither is recFactorial, my bad. Anyway, my point was that the compiler should not generate code that blows up on a (in principle) perfectly sane implementation. Is it

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread H. S. Teoh
On Fri, Feb 03, 2012 at 12:10:01AM +0100, Timon Gehr wrote: [...] LList!ulong fib(){ LList!ulong r; r=cons(st(1UL),cons(st(1UL),lz(()=zipWith((Lazy!ulong a, Lazy!ulong b)=lz(()=a+b),r,r.tail)(; return r; } Whoa. A caching recursive definition of fibonacci. Impressive! Now I

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread Ali Çehreli
On 02/02/2012 03:10 PM, Timon Gehr wrote: LList!ulong fib(){ LList!ulong r; r=cons(st(1UL),cons(st(1UL),lz(()=zipWith((Lazy!ulong a, Lazy!ulong b)=lz(()=a+b),r,r.tail)(; return r; } Sorry, wrong newsgroup. alt.comp.lang.perl is around the corner. :p Ali

Re: Segment violation (was Re: Why I could not cast string to int?)

2012-02-02 Thread H. S. Teoh
On Thu, Feb 02, 2012 at 03:26:52PM -0800, Ali Çehreli wrote: On 02/02/2012 03:10 PM, Timon Gehr wrote: LList!ulong fib(){ LList!ulong r; r=cons(st(1UL),cons(st(1UL),lz(()=zipWith((Lazy!ulong a, Lazy!ulong b)=lz(()=a+b),r,r.tail)(; return r; } Sorry, wrong newsgroup.