### Re: [racket-users] How to convert String to Integer

Did anyone suggest this code to you? Apologies if I’m re-treading an old conversation. #lang typed/racket (: string2value (-> String Integer)) (define (string2value str) (define maybe-integer (string->number str)) (cond [(exact-integer? maybe-integer) maybe-integer] [else (error

### Re: [racket-users] How to convert String to Integer

?? > (string2value "-1234") - : Integer -28766 > (string2value "abcd") - : Integer 54562 > Is this your desired behavior? > On Feb 12, 2020, at 16:43, Alain De Vos wrote: > > I came to the following result as conversion function : > > #lang typed/racket > (: string2value (-> String

### Re: [racket-users] How to convert String to Integer

Philip, For the last part, I will make my work through, convert a string to collection/list of characters, this to a collection/list of numbers with a value 48 subtracted i think, this to the correct end value base10. I have no complex numbers to deal with. But at each step I should raise , this

### Re: [racket-users] How to convert String to Integer

On Tuesday, February 11, 2020 at 5:33:37 PM UTC+1, Philip McGrath wrote: > > Others have tried to be more Socratic in pointing you this way, but here's > an attempt at being more explicit. > > As you note, the result of `string->number` has the type `(U Complex > False)`. If we try to think

### Re: [racket-users] How to convert String to Integer

Others have tried to be more Socratic in pointing you this way, but here's an attempt at being more explicit. As you note, the result of `string->number` has the type `(U Complex False)`. If we try to think about about this in a version of the HtDP design recipe, we have a few cases: 1.

### Re: [racket-users] How to convert String to Integer

No exact-integer is a check it is not a type. The error described above remains On Tuesday, February 11, 2020 at 3:50:27 PM UTC+1, Alain De Vos wrote: > > > > On Tuesday, February 11, 2020 at 3:25:42 PM UTC+1, Ben Greenman wrote: >> >> You may want `exact-integer?` >> True , i should use

### Re: [racket-users] How to convert String to Integer

On Tuesday, February 11, 2020 at 3:25:42 PM UTC+1, Ben Greenman wrote: > > You may want `exact-integer?` > True , i should use exact-integer. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving

### Re: [racket-users] How to convert String to Integer

You may want `exact-integer?` -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web

### Re: [racket-users] How to convert String to Integer

Indeed good question, but the following code works, #lang typed/racket (require typed/racket/gui) (: fib (-> Integer Integer)) (define (fib n) (if (< 2 n) n (+ (fib (- n 1)) (fib (- n 2) (: numericalchar2integer (-> Char Integer)) (define (numericalchar2integer char)

### Re: [racket-users] How to convert String to Integer

What should `(myconversion "apple")` return? What should `(myconversion "12.3")` return? What does `string->number` do in each of those cases? Ryan On Tue, Feb 11, 2020 at 11:34 AM Alain De Vos wrote: > I tried the following function to conver a String to an Integer. > > #lang typed/racket >

### [racket-users] How to convert String to Integer

I tried the following function to conver a String to an Integer. #lang typed/racket (: myconversion (-> String Integer)) (define (myconversion str) (string->number str)) The error given is : Type Checker: type mismatch expected: Integer given: (U Complex False) in: (string->number str) I