This works, for instance (and I would much prefer case to hash-ref):

#lang typed/racket

(regexp-replace* #rx"[ABC]"
                 "ABCABC"
                 (λ ([c : String] . _)
                   (case c
                     [("A") "AC"]
                     [("B") "BA"]
                     [("C") "CCA"]
                     [else (error 'bad-match c)])))

-Philip

On Sat, Jul 8, 2017 at 8:14 AM, Alasdair McAndrew <amc...@gmail.com> wrote:

> Many thanks - that works fine!  And it makes sense, to use regexp-replace*
> with a hash table.  (All these things I'm still finding out...)  Is it
> possible to do this - or something similar - in Typed Racket?
>
> On Saturday, 8 July 2017 22:45:04 UTC+10, Neil Van Dyke  wrote:
> > This is one OK way that people are likely to do:
> >
> >
> > #lang racket/base
> >
> > (define (foo str)
> >    (regexp-replace* #rx"[ABC]"
> >                     str
> >                    (lambda (s)
> >                      (hash-ref #hash(("A" . "AC")
> >                                      ("B" . "BA")
> >                                      ("C" . "CCA"))
> >                                s))))
> >
> > (module+ test
> >    (require rackunit)
> >    (check-equal? (foo "")         "")
> >    (check-equal? (foo "ABCABC")   "ACBACCAACBACCA")
> >    (check-equal? (foo "ABCDABCD") "ACBACCADACBACCAD"))
> >
> >
> > It's not necessarily the most maintainable (note the duplicated info
> > between the regexp and the map) nor most efficient, but it's OK, IMHO.
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to