<html><head></head><body>Hi Jordan,<br>
<br>
The simplest change I see to your code...<br>
<br>
(define-values (year month day)<br>
(regexp-split #rx"/" "2012/06/06"))<br>
<br>
...is this:<br>
<br>
(define-values (year month day)<br>
(apply values (regexp-split #rx"/" "2012/06/06")))<br>
<br>
Best,<br>
jmj <br>
-- <br>
Sent from my Android phone with K-9 Mail.<br><br><div class="gmail_quote">users-request@racket-lang.org wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre style="white-space: pre-wrap; word-wrap:break-word; font-family: monospace">Send users mailing list submissions to<br />        users@racket-lang.org<br /><br />To subscribe or unsubscribe via the World Wide Web, visit<br />        <a href="http://lists.racket-lang.org/users/listinfo">http://lists.racket-lang.org/users/listinfo</a><br />or, via email, send a message with subject or body 'help' to<br />        users-request@racket-lang.org<br /><br />You can reach the person managing the list at<br />        users-owner@racket-lang.org<br /><br />When replying, please edit your Subject line so it is more specific<br />than "Re: Contents of users digest..."<br /><br /><br />[Racket Users list:<br /> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a>]<br /><br /><br />Today's Topics:<br /><br /> 1. Re: Feature request: multiple keys in sort (Eli Barzilay)<br /> 2. Re: Feature request: multiple keys in sort (Robby Findler)<br /> 3. unwrapping a list (Jordan Schatz)<br />
4. Re: unwrapping a list (Erik Silkensen)<br /> 5. Re: unwrapping a list (Eli Barzilay)<br /> 6. Re: unwrapping a list (Neil Van Dyke)<br /><br /><br /><hr /><br /><br />Message: 1<br />Date: Mon, 11 Jun 2012 14:58:47 -0400<br />From: Eli Barzilay <eli@barzilay.org><br />To: Robby Findler <robby@eecs.northwestern.edu><br />Cc: Harry Spier <vasishtha.spier@gmail.com>,        racket List<br />        <users@racket-lang.org><br />Subject: Re: [racket] Feature request: multiple keys in sort<br />Message-ID: <20438.16359.371830.465004@winooski.ccs.neu.edu><br />Content-Type: text/plain; charset=utf-8<br /><br />[Setting followups to the dev list.]<br /><br />20 minutes ago, Robby Findler wrote:<br />> On Mon, Jun 11, 2012 at 11:37 AM, Eli Barzilay <eli@barzilay.org> wrote:<br />> > So the bottom line is that there's no need to extend `sort' for<br />> > this kind of functionality. ?What would be nice to have though, is<br />> > such a
comparison combinator -- and the only reason there's<br />> > nothing that comes pre-packaged is that I didn't see something<br />> > that sticks out as the right api for it. ?(See srfi-67 for a very<br />> > complete discussion, and a post that I'll send to the dev list<br />> > soon.)<br />> <br />> I'm not sure I buy this conclusion here: the reason to put it into<br />> sort (or somewhere) would be a) convenience and b) maintainability<br />> (since this comes up fairly often at least in my own experience and<br />> having something short to read to know what is going on is<br />> preferable to having to read a bunch of code to figure out what is<br />> going on). No?<br /><br />What I meant is that there is no need to extend `sort' itself -- but<br />there is definitely a place for having such a comparison combinator.<br />The only question is what kind of combinator... and because I didn't<br />(and still don't) have a good answer
for that question, I didn't<br />implement it. To make it even clearer -- if, for some reason, the<br />code that I wrote in the previous post is universally accepted as the<br />perfect tool, then there's no doubt that it should be added. (But I<br />think that it suffers from a bunch of problems.)<br /><br /><br />And another appendix that I should have added: things get more<br />complicated in the presence of `#:cache-keys?'. If there's just this<br />kind of a combinator, and you need to precompute a number of keys,<br />then you end up with some amount of boilerplate -- something like:<br /><br /> (sort some-list<br /> (<... smaller1? car smaller2? cadr ...)<br /> #:key (? (x) (list (compute-key1 x) (compute-key1 x) ...))<br /> #:cache-keys? #t)<br /><br />This means that the combinator is not as useful, since you need to<br />split the code: instead of specifying `smaller1?' and `compute-key1'<br />together, you need to split them to two places,
and you need to decide<br />on the intermediate representation for the tuples. A solution for<br />this particular case does require an extension to `sort'. However, it<br />seems to me like a relatively rare case, and the benefits of such an<br />extension should be weighed against the more complicated interface<br />that `sort' will have, and the fact that with baking this into `sort'<br />we're losing the ability to conveniently add additional kinds of<br />combinators.<br /><br />(This is also related to the other post that I'll do.)<br /><br />-- <br /> ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:<br /> <a href="http://barzilay.org">http://barzilay.org</a>/ Maze is Life!<br /><br /><br /><br /><hr /><br /><br />Message: 2<br />Date: Mon, 11 Jun 2012 14:03:00 -0500<br />From: Robby Findler <robby@eecs.northwestern.edu><br />To: dev@racket-lang.org<br />Cc: Harry Spier
<vasishtha.spier@gmail.com>,        racket List<br />        <users@racket-lang.org><br />Subject: Re: [racket] Feature request: multiple keys in sort<br />Message-ID:<br />        <CAL3TdON0Hhs+RkepxMkX_2=5s3WbjXUybYmbAV5evJ0SqvPymg@mail.gmail.com><br />Content-Type: text/plain; charset=UTF-8<br /><br />How about this: until you find the perfect way to do this, we just add<br />two new optional keyword arguments to sort that deal with two levels<br />of key/sorts? eg:<br /><br />(sort lst < #:key first #:key2 second)<br /><br />would mean to sort by < for both keys, treating the first position in<br />the list as the main one and the second as a secondary one. And then<br />we could also have another keyword for specifying a different sorting<br />predicate for the second key, too.<br /><br />That would actually cover all of the cases that I think I've seen in practice.<br /><br />Robby<br /><br />On Mon, Jun 11, 2012 at 1:58 PM, Eli Barzilay <eli@barzilay.org> wrote:<br
/>> [Setting followups to the dev list.]<br />><br />> 20 minutes ago, Robby Findler wrote:<br />>> On Mon, Jun 11, 2012 at 11:37 AM, Eli Barzilay <eli@barzilay.org> wrote:<br />>> > So the bottom line is that there's no need to extend `sort' for<br />>> > this kind of functionality. ?What would be nice to have though, is<br />>> > such a comparison combinator -- and the only reason there's<br />>> > nothing that comes pre-packaged is that I didn't see something<br />>> > that sticks out as the right api for it. ?(See srfi-67 for a very<br />>> > complete discussion, and a post that I'll send to the dev list<br />>> > soon.)<br />>><br />>> I'm not sure I buy this conclusion here: the reason to put it into<br />>> sort (or somewhere) would be a) convenience and b) maintainability<br />>> (since this comes up fairly often at least in my own experience and<br />>> having
something short to read to know what is going on is<br />>> preferable to having to read a bunch of code to figure out what is<br />>> going on). No?<br />><br />> What I meant is that there is no need to extend `sort' itself -- but<br />> there is definitely a place for having such a comparison combinator.<br />> The only question is what kind of combinator... and because I didn't<br />> (and still don't) have a good answer for that question, I didn't<br />> implement it. ?To make it even clearer -- if, for some reason, the<br />> code that I wrote in the previous post is universally accepted as the<br />> perfect tool, then there's no doubt that it should be added. ?(But I<br />> think that it suffers from a bunch of problems.)<br />><br />><br />> And another appendix that I should have added: things get more<br />> complicated in the presence of `#:cache-keys?'. ?If there's just this<br />> kind of a combinator, and you need
to precompute a number of keys,<br />> then you end up with some amount of boilerplate -- something like:<br />><br />> ?(sort some-list<br />> ? ? ? ?(<... smaller1? car smaller2? cadr ...)<br />> ? ? ? ?#:key (? (x) (list (compute-key1 x) (compute-key1 x) ...))<br />> ? ? ? ?#:cache-keys? #t)<br />><br />> This means that the combinator is not as useful, since you need to<br />> split the code: instead of specifying `smaller1?' and `compute-key1'<br />> together, you need to split them to two places, and you need to decide<br />> on the intermediate representation for the tuples. ?A solution for<br />> this particular case does require an extension to `sort'. ?However, it<br />> seems to me like a relatively rare case, and the benefits of such an<br />> extension should be weighed against the more complicated interface<br />> that `sort' will have, and the fact that with baking this into `sort'<br />> we're losing the ability to
conveniently add additional kinds of<br />> combinators.<br />><br />> (This is also related to the other post that I'll do.)<br />><br />> --<br />> ? ? ? ? ?((lambda (x) (x x)) (lambda (x) (x x))) ? ? ? ? ?Eli Barzilay:<br />> ? ? ? ? ? ? ? ? ? ?<a href="http://barzilay.org">http://barzilay.org</a>/ ? ? ? ? ? ? ? ? ? Maze is Life!<br /><br /><br /><br /><hr /><br /><br />Message: 3<br />Date: Mon, 11 Jun 2012 13:24:40 -0600<br />From: Jordan Schatz <jordan@noionlabs.com><br />To: Racket Users <users@racket-lang.org><br />Subject: [racket] unwrapping a list<br />Message-ID: <871ull6493.fsf@noionlabs.com><br />Content-Type: text/plain<br /><br /><br />Is there a way to unwrap or explode a list? I don't see it in the docs, but it<br />seems like it would be a common thing.<br /><br />This is what I want to do:<br /><br />(define-values (year month day)<br /> (regexp-split #rx"/" "2012/06/06"))<br /><br />But regexp-split returns a list, not
values, so I'd like to "unwrap" the list<br />and just have the values...<br /><br />I can do it manually:<br />(define tmp (regexp-split #rx"/" "2012/06/06"))<br />(define year (first tmp))<br />(define month (second tmp))<br />(define day (third tmp))<br /><br />But thats ugly.<br /><br />Being able to <br />(let ([year month day (regexp-split #rx"/" "2012/06/06")])<br /> )<br />Would be handy too...<br /><br />- Jordan<br /><br /><br /><br /><hr /><br /><br />Message: 4<br />Date: Mon, 11 Jun 2012 20:30:02 +0100<br />From: Erik Silkensen <eriksilkensen@gmail.com><br />To: Jordan Schatz <jordan@noionlabs.com><br />Cc: Racket Users <users@racket-lang.org><br />Subject: Re: [racket] unwrapping a list<br />Message-ID: <C9584DBF-9AC9-4167-B467-B9BBCA173A10@gmail.com><br />Content-Type: text/plain; charset=windows-1252<br /><br />You could use match or match-let, e.g.,<br /><br />(match-let ([(list year month day) (regexp-split #rx"/" "2012/06/06")])<br />
?)<br /><br /><a href="http://docs.racket-lang.org/reference/match.html">http://docs.racket-lang.org/reference/match.html</a><br /><br />On Jun 11, 2012, at 8:24 PM, Jordan Schatz wrote:<br /><br />> <br />> Is there a way to unwrap or explode a list? I don't see it in the docs, but it<br />> seems like it would be a common thing.<br />> <br />> This is what I want to do:<br />> <br />> (define-values (year month day)<br />> (regexp-split #rx"/" "2012/06/06"))<br />> <br />> But regexp-split returns a list, not values, so I'd like to "unwrap" the list<br />> and just have the values...<br />> <br />> I can do it manually:<br />> (define tmp (regexp-split #rx"/" "2012/06/06"))<br />> (define year (first tmp))<br />> (define month (second tmp))<br />> (define day (third tmp))<br />> <br />> But thats ugly.<br />> <br />> Being able to <br />> (let ([year month day (regexp-split #rx"/" "2012/06/06")])<br />> )<br
/>> Would be handy too...<br />> <br />> - Jordan<br />> <br />> ____________________<br />> Racket Users list:<br />> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br /><br /><br /><br /><br /><hr /><br /><br />Message: 5<br />Date: Mon, 11 Jun 2012 15:30:16 -0400<br />From: Eli Barzilay <eli@barzilay.org><br />To: Jordan Schatz <jordan@noionlabs.com><br />Cc: Racket Users <users@racket-lang.org><br />Subject: Re: [racket] unwrapping a list<br />Message-ID: <20438.18248.302505.269345@winooski.ccs.neu.edu><br />Content-Type: text/plain; charset=us-ascii<br /><br />A few minutes ago, Jordan Schatz wrote:<br />> <br />> Is there a way to unwrap or explode a list? I don't see it in the<br />> docs, but it seems like it would be a common thing.<br />> <br />> This is what I want to do:<br />> <br />> (define-values (year month day)<br />> (regexp-split #rx"/" "2012/06/06"))<br
/>> <br />> But regexp-split returns a list, not values, so I'd like to "unwrap"<br />> the list and just have the values...<br /><br /> (match-define (list year month day)<br /> (regexp-split #rx"/" "2012/06/06"))<br /><br />> (let ([year month day (regexp-split #rx"/" "2012/06/06")])<br />> )<br />> Would be handy too...<br /><br /> (match-let ([(list year month date)<br /> (regexp-split #rx"/" "2012/06/06")])<br /> year)<br /><br />-- <br /> ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:<br /> <a href="http://barzilay.org">http://barzilay.org</a>/ Maze is Life!<br /><br /><br /><hr /><br /><br />Message: 6<br />Date: Mon, 11 Jun 2012 15:30:49 -0400<br />From: Neil Van Dyke <neil@neilvandyke.org><br />To: Jordan Schatz <jordan@noionlabs.com><br />Cc: Racket Users <users@racket-lang.org><br />Subject: Re: [racket] unwrapping a list<br />Message-ID:
<4FD64769.7070505@neilvandyke.org><br />Content-Type: text/plain; charset=UTF-8; format=flowed<br /><br />(apply (lambda (year month day)<br /> (printf "Year: ~S Month: ~S Day: ~S\n"<br /> year<br /> month<br /> day))<br /> (regexp-split #rx"/" "2012/06/06"))<br /><br />Neil V.<br /><br /><br /><br />End of users Digest, Vol 82, Issue 38<br />*************************************<br /></pre></blockquote></div></body></html>