Ah, very nice. Do I infer correctly that the predicates are greedy 
left-to-right?


#lang racket
(require match-string rackunit)

(define (no-digits x) (regexp-match #px"^\\D+$" x))

(check-equal?
 (match "foo42.3bar"
   [(string-append (? no-digits) (? string->number x) rest) x]
   [else 'no])
 "42.3")



On Mar 17, 2016, at 8:45 PM, Alex Knauth <alexan...@knauth.org> wrote:

> There's a string-append match expander for that here, although it's pretty 
> slow right now.
> http://docs.racket-lang.org/match-string/index.html
> 
> Alex Knauth
> 
>> On Mar 17, 2016, at 7:17 PM, Matthew Butterick <m...@mbtype.com> wrote:
>> 
>> Racket's `match` is not far from this. In fact maybe I shouldn't be thinking 
>> in terms of hacking regexps, but rather making a new match expander. For 
>> instance, you can destructure a list like so:
>> 
>> (match '("foo" "-42.3" "bar")
>>  [(list a (? string->number b) c) 'yay]
>>  [else 'boo])
>> 
>> So it would extend logically to this pseudocode:
>> 
>> (match "foo-42.3bar"
>>  [(string-append a (? string->number b) c) 'yay]
>>  [else 'boo])
> 

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