On Tue, Feb 11, 2020 at 3:28 PM Alain De Vos <devosalai...@gmail.com> wrote:

> But first i need a list of characters. :)
> Does the language has a conversion operator ?
>

Yes, `string->list`:
https://docs.racket-lang.org/reference/strings.html#(def._((quote._~23~25kernel)._string-~3elist))
But read on …

On Tue, Feb 11, 2020 at 3:28 PM Alain De Vos <devosalai...@gmail.com> wrote:

> 0) Given a string,
> 1) convert to  a list of characters,
> 2) allow me to iterate,
> 3) convert a character to an int ,
> 4) subtract corresponding value of zero,
> 5) allow me to some positional stuff and addition.
>

If you really want to implement the algorithm you described, here's one way
to do it:
#lang typed/racket
(: string->integer (-> String Integer))
(define (string->integer str)
  (define base (char->integer #\0))
  (for/fold ([acc : Integer 0])
            ([char (in-string str)])
    (+ (* 10 acc) (- (char->integer char) base))))

Again, I actually would do this with `string->number`, as I illustrated
earlier, unless this arithmetic with Unicode scalars is really what you
want to compute. For example, what about "-"?

On Tue, Feb 11, 2020 at 2:15 PM Alain De Vos <devosalai...@gmail.com> wrote:

> But at each step I should raise , this is not ok.
> Otherwise the GUI just keeps eating memory ...
>

I don't understand what you mean here. Raising an exception should not
cause a memory leak. If you mean that it makes the GUI non-responsive, then
you should catch the exception and show a message to the user (or do the
equivalent using a designated "bad value" instead of an exception).

-Philip

-- 
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 
https://groups.google.com/d/msgid/racket-users/CAH3z3gYQKaKpWmSzWJoiTaHB3HDmrgUrcgH_CZOOhvmYwPV4zQ%40mail.gmail.com.

Reply via email to