[racket] unwrapping a list

From: Erik Silkensen (eriksilkensen at gmail.com)
Date: Mon Jun 11 15:30:02 EDT 2012

You could use match or match-let, e.g.,

(match-let ([(list year month day) (regexp-split #rx"/" "2012/06/06")])
  …)

http://docs.racket-lang.org/reference/match.html

On Jun 11, 2012, at 8:24 PM, Jordan Schatz wrote:

> 
> Is there a way to unwrap or explode a list? I don't see it in the docs, but it
> seems like it would be a common thing.
> 
> This is what I want to do:
> 
> (define-values (year month day)
>  (regexp-split #rx"/" "2012/06/06"))
> 
> But regexp-split returns a list, not values, so I'd like to "unwrap" the list
> and just have the values...
> 
> I can do it manually:
> (define tmp (regexp-split #rx"/" "2012/06/06"))
> (define year (first tmp))
> (define month (second tmp))
> (define day (third tmp))
> 
> But thats ugly.
> 
> Being able to 
> (let ([year month day (regexp-split #rx"/" "2012/06/06")])
>  )
> Would be handy too...
> 
> - Jordan
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.