On Jul 14, 2016, at 1:50 AM, 'Thomas Prebeck' via Racket Users 
<racket-users@googlegroups.com> wrote:

> Hi I want to do something like this:
> 
> (define test "(1,2,3)(4,5,6)(7,8,9)")
> 
> (define (convert m)
>  (for/list ([i (cdr m)])
>    (string->number i)))
> 
> (regexp-match* #rx"([^,\\(\\)]*),([^,\\(\\)]),([^,\\(\\)])" test 
> #:match-select convert)
> 
> But that fails because the matches are represented as pairs of indexes(the 
> matching substrings) in the string. Is there a way to do this or do I have to 
> convert afterwards


;; two options

#lang racket
(require rackunit)
(define test "(1,2,3)(4,5,6)(7,8,9)")

(check-equal?
 (map (curry map string->number) (regexp-match* 
#rx"([^,\\(\\)]*),([^,\\(\\)]),([^,\\(\\)])" test #:match-select cdr))
 '((1 2 3)(4 5 6)(7 8 9)))

(check-equal?
 (for/list ([i (in-port read (open-input-string (string-replace test "," " 
")))])
           i)
 '((1 2 3)(4 5 6)(7 8 9)))




-- 
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