[racket] Destructuring-bind for Regex

From: Galler (lzgaller at optonline.net)
Date: Fri Jan 4 15:37:58 EST 2013

Thanks Sam. That's a very elegant solution.

Could you possibly briefly elaborate on how the parentheses in the 
regular expression make the destructuring work?

R./
Zack

On Fri, Jan 4, 2013 at 3:19 PM, Sam Tobin-Hochstadt wrote:

> How about this:
>
> (match "This is a 40.2 Song about Japan"
>   [(regexp #px"([\\D]*)([\\d]+\\.[\\d]+)([\\D]*)" (list _ x y z))
>    (list x y z)])
> ;; produces
> '("This is a " "40.2" " Song about Japan")
>
> The `_` is ignoring the first result of `regexp-match`, which is the 
> full match.
>
> Sam
>
> On Fri, Jan 4, 2013 at 2:50 PM, Galler <lzgaller at optonline.net> wrote:
>> Hello,
>>
>> Is there a destructuring-bind for regular expressions?
>>
>> Something along the lines of the purely fictional function
>> "with-destructuring-regex", below:
>>
>> (with-destructuring-regex ([(list #px"[\\D]*"  #px"[\\d]+\\.[\\d]+"
>> #px"[\\D]*") "This is a 40.2 Song about Japan" (x y z)])
>>                          (values x y z))
>>
>> ;->
>> ;"This is a "
>> ;"40.2"
>> ;"Song about Japan"
>>
>> This seems very much like something Danny would have implemented at 
>> some
>> point in time.
>>
>>  If the answer is no, I'll just go ahead and code it and share 
>> results, if
>> of interest.
>>
>> Thanks much.
>>
>> Zack
>> ____________________
>>  Racket Users list:
>>  http://lists.racket-lang.org/users

Posted on the users mailing list.