On Thu, Mar 17, 2016 at 4:17 PM, Matthew Butterick <m...@mbtype.com> wrote:
> > On Mar 17, 2016, at 2:05 PM, Andrew Gwozdziewycz <apg...@gmail.com> wrote: > > I am imagining an API that utilizes SCSH style regexes but allows you to > do something like this (fictional): > > (define-values (area prefix line) (sre-match (: (= digits 3) (_? "-") (= > digits 3) (_? "-") (= digits 3)))) > > > > 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]) > Yup! Exactly. I really had `match` in mind. I'm not sure why you wouldn't use regexes underneath though. As you have it, you'd be forced to call `string->number` on every subsequence, where as constructing a regex with grouping seemingly does this in effectively 1 pass (with possible back tracking of course). Still, the idea is extremely solid, and I would use such a thing constantly. -- 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.