[racket] for/hash and for/list: adding nothing, adding more than one thing
Thanks everyone for the useful feedback. I'll check out all three options.
:-)
On Fri, Mar 22, 2013 at 12:23 PM, Pierpaolo Bernardi <olopierpa at gmail.com>wrote:
> On Thu, Mar 21, 2013 at 11:55 PM, Tim Nelson <tbnelson at gmail.com> wrote:
> > Dear All,
> >
> > I've recently started hacking Racket again, and am loving the for/*
> > constructs.
> > Awesome stuff. However, I have two questions about for/hash.
> >
> > (1) How can I *not* add a hash entry for a given iteration?
> >
> > When I use for/list, can I abuse the nature of empty and append* (I
> cringe
> > as I write this):
> >
> > (append* (for/list ([i '(1 2 3 4 5)])
> > (cond [(even? i) (list (* i 100))]
> > [else empty])))
> >
> > Surely there is a better way to do this for for/list, and a way in
> general
> > for for/hash?
> >
> > (2) How can I add multiple entries (that is, >1 key-value pair) in a
> given
> > iteration?
> >
> > Again, using for/list I can cheat via append*:
> >
> > (append* (for/list ([i '(1 2 3 4 5)])
> > (list (* i 100) (* i 200))))
> >
> > What's the right way to do this in for/hash?
>
> To both of the questions, the answer is for/fold!
>
> Cheers
> P.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130325/81237b72/attachment.html>