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 'stri
??
> (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 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 is
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 abo
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. `strin
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 exact-in
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
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 visit
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)
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
> (
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 g
11 matches
Mail list logo