On Thu, Mar 2, 2017 at 11:22 AM, David Christiansen < da...@davidchristiansen.dk> wrote:
> > Not with map, which requires equal-length arguments. > > > > You could do the slightly less ugly: > > > > (map > > foo > > lst-A > > lst-B > > (range (length lst-A))) > > Why not do it this way? > > (struct foo (a b c)) > (define lst-A '(a b)) > (define lst-B '(d e)) > (for/list ([a (in-list lst-A)] > [b (in-list lst-B)] > [n (in-naturals)]) > (foo a b n)) > > This seems to be the nicest of the lot. > > /David I could, it's just extremely more verbose and therefore obfuscates what's actually going on as compared to the 'map' form. The issue with streams and sequences not being iterable in some cases has tripped me up several times. I confess I don't understand the design decisions behind them. Can someone ELI5 for me about what exactly they are and why they work the way they do / aren't interchangeable? From a naive perspective it seems like it would be possible to make them work smoothly together by adding a "cond: choose the right iterator func based on the type" under the hood. Something like the following, except this is probably very slow and I'd need to figure out the appropriate generation for the '(choose-iter sourceN)' lines: (define-syntax relaxed-map (syntax-case stx () [(_ func source1 source2 ...) (let () (define (choose-iter x) (cond [(list? x) (list list-ref x)] [(stream? x) (list stream-ref x)] [(sequence? x) (list sequence-ref x)])) (for/list ((i (in-range (add1 (min (map length source1 source2 ...)))))) (list ((choose-iter source1) source1 i) ((choose-iter source2) source2 i) ...)))])) ;; This won't actually generate the 'choose-iter' lines properly > > > -- > 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. > -- 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.