Re: sameness

2012-02-02 Thread sclytrack
On 01/20/2012 01:18 PM, sclytrack wrote: --- letters are different yet the same immutable(char) [] letter1; const(char) [] letter2; char [] letter3; void proc1( const(char) [] letter) {} --- letters are different struct

Why I could not cast string to int?

2012-02-02 Thread xancorreu
Hi, In this code, how can I cast the args[0] string to int for computing factorial(args[0])? import std.stdio, std.bigint, std.string, std.conv, std.stream; BigInt recFactorial(int n) { if (n == 0) return BigInt(1); else return (BigInt(n) * recFactorial(n - 1)); } void main(string[] args) {

Re: Why I could not cast string to int?

2012-02-02 Thread David Nadlinger
On 2/2/12 1:35 PM, xancorreu wrote: In this code, how can I cast the args[0] string to int for computing factorial(args[0])? std.conv.to!int(…) or parse(). Hope this helps, David

Re: Why I could not cast string to int?

2012-02-02 Thread Tobias Pankrath
Use to!int(args[1]) I receive: $ gdmd-4.6 factorial.d factorial.d: In function ‘main’: factorial.d:15:0: error: cannot cast expression of type string to int Thanks in advance, Xan.

Re: Why I could not cast string to int?

2012-02-02 Thread xancorreu
Al 02/02/12 16:58, En/na David Nadlinger ha escrit: On 2/2/12 1:35 PM, xancorreu wrote: In this code, how can I cast the args[0] string to int for computing factorial(args[0])? std.conv.to!int(…) or parse(). to!int gives me this error: $ ./factorial 222 Factorial requires a number

Re: Why I could not cast string to int?

2012-02-02 Thread Adam D. Ruppe
On Thursday, 2 February 2012 at 16:21:39 UTC, xancorreu wrote: $ ./factorial 222 Factorial requires a number args[0] is the name of your program. (The first thing you typed on the command line.) Use args[1] to get that number. parse() where is the doc?

Re: Why I could not cast string to int?

2012-02-02 Thread xancorreu
Al 02/02/12 16:58, En/na David Nadlinger ha escrit: On 2/2/12 1:35 PM, xancorreu wrote: In this code, how can I cast the args[0] string to int for computing factorial(args[0])? std.conv.to!int(…) or parse(). Sorry, if condition was wrong. conv.to!int is perfect! Thanks, Hope this helps,

Re: Why I could not cast string to int?

2012-02-02 Thread xancorreu
Why cast(int) does not work and I have to call another function? Thanks, Al 02/02/12 17:24, En/na Adam D. Ruppe ha escrit: On Thursday, 2 February 2012 at 16:21:39 UTC, xancorreu wrote: $ ./factorial 222 Factorial requires a number args[0] is the name of your program. (The first thing you

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

2012-02-02 Thread xancorreu
I get segment violation error with ./factorial 40 How can I resolve it? My code is: import std.stdio, std.bigint, std.string, std.conv, std.stream; BigInt recFactorial(int n) { if (n == 0) return BigInt(1); else return (BigInt(n) * recFactorial(n - 1)); } void

Re: Why I could not cast string to int?

2012-02-02 Thread Alex Rønne Petersen
On 02-02-2012 17:26, xancorreu wrote: Why cast(int) does not work and I have to call another function? Thanks, Al 02/02/12 17:24, En/na Adam D. Ruppe ha escrit: On Thursday, 2 February 2012 at 16:21:39 UTC, xancorreu wrote: $ ./factorial 222 Factorial requires a number args[0] is the name

Re: Why I could not cast string to int?

2012-02-02 Thread bearophile
Alex Rønne Petersen Wrote: On 02-02-2012 17:26, xancorreu wrote: Why cast(int) does not work and I have to call another function? Thanks, Al 02/02/12 17:24, En/na Adam D. Ruppe ha escrit: On Thursday, 2 February 2012 at 16:21:39 UTC, xancorreu wrote: $ ./factorial 222 Factorial

Re: Why I could not cast string to int?

2012-02-02 Thread bearophile
Alex R. Petersen: (Sorry for my last blank answer.) Because D is a strongly typed language. Casting a string to an int doesn't make sense from a type system perspective. I think that D being strongly typed is not significant here. When you cast a string to char* you are casting a 2 words

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: Why I could not cast string to int?

2012-02-02 Thread Ali Çehreli
On 02/02/2012 10:18 AM, bearophile wrote: The cast() is meant to be a light and very quick conversion, usually done at compile-time (unless it's a dynamic cast), I first read it as if you were saying that dynamic cast is the only one that is done at runtime. Actually many casts are done at

Re: Why I could not cast string to int?

2012-02-02 Thread Jonathan M Davis
On Thursday, February 02, 2012 13:18:17 bearophile wrote: Alex R. Petersen: (Sorry for my last blank answer.) Because D is a strongly typed language. Casting a string to an int doesn't make sense from a type system perspective. I think that D being strongly typed is not significant

i18n

2012-02-02 Thread xancorreu
Hi, Is there any way for localizate and internationalizate messages? I were shocked if D has something like Fantom [http://fantom.org/doc/docLang/Localization.html]. Gettext is pretty ugly ;-) If not, any plannings? Thanks, Xan.

Re: Why I could not cast string to int?

2012-02-02 Thread Jonathan M Davis
On Thursday, February 02, 2012 10:36:06 Ali Çehreli wrote: Just to be complete: You mean it for fundamental types. Of course user types' opCast operators may throw: import std.exception; class C { int opCast(T : int)() const { enforce(false, Not good.); return 42; } } void main()

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: Why I could not cast string to int?

2012-02-02 Thread Ali Çehreli
On 02/02/2012 11:00 AM, xancorreu wrote: Al 02/02/12 19:18, En/na bearophile ha escrit: Can I say serialize the first, second and third arguments as Class Person? I mean, if you define a class Person like: class Person { string name uint age dead bool } could you serialize the input

Re: Why I could not cast string to int?

2012-02-02 Thread Jonathan M Davis
On Thursday, February 02, 2012 11:11:28 Ali Çehreli wrote: On 02/02/2012 11:00 AM, xancorreu wrote: Al 02/02/12 19:18, En/na bearophile ha escrit: Can I say serialize the first, second and third arguments as Class Person? I mean, if you define a class Person like: class Person

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

How far can CTFE go?

2012-02-02 Thread H. S. Teoh
I'm experimenting with pluggable expression parser modules, and I'm wondering if I can use CTFE to build parser tables and such. What are the current limitations of CTFE? Are dynamic arrays of structs supported? Associative arrays? What about compile-time cross-module initialization? The idea is

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.

Re: How far can CTFE go?

2012-02-02 Thread Manfred Nowak
H. S. Teoh wrote: the ideal situation would be that CTFE can replace writing an arbitrarily complex helper program Aebitrary complex helper programs may include viruses and other nice surprises. Walter does not want that adminstrators have to worry about a compilation step to torture the

linker @ meaning and how to compile static libs

2012-02-02 Thread Kim
Hi, I am compiling parts of the 7zip SDK (the 7zDec.exe) as a static lib. I am having issues with compile a static lib (from c code, using dmc 8.50) that I can use with D v1.072. The main question is how do I either compile the library with the right version suffix (@12) Or get the linker to

Re: How far can CTFE go?

2012-02-02 Thread H. S. Teoh
On Fri, Feb 03, 2012 at 12:51:51AM +, Manfred Nowak wrote: H. S. Teoh wrote: the ideal situation would be that CTFE can replace writing an arbitrarily complex helper program Aebitrary complex helper programs may include viruses and other nice surprises. Walter does not want that

Re: How far can CTFE go?

2012-02-02 Thread Manfred Nowak
H. S. Teoh wrote: I don't think that should be grounds to get rid of CTFE, though. In contrast to your remark, I do not see the benefits of reducing two compiling phases to one. For me CTFE ist nothing else than running the executables of a first compilation in order to get some values