On Tuesday, November 15, 2016 at 11:53:37 AM UTC-5, johnbclements wrote: > > On Nov 15, 2016, at 8:30 AM, Brian Adkins <lojicdot...@gmail.com> wrote: > > > > I'm working on a simple chess engine in Racket as a learning exercise. I > > initially wrote this function: > > > > (define (valid-queen-moves board idx is-opposite-color?) > > (append (valid-bishop-moves board idx is-opposite-color?) > > (valid-rook-moves board idx is-opposite-color?))) > > I personally find this first one the most readable. > > If you don’t like it, you could always bundle the arguments together into > something called state, so that it reads: > > (define (valid-queen-moves state) > (append (valid-bishop-moves state) > (valid-rook-moves state)))
That's a good point, and takes care of one of my original objects, but I'm not sure it's as clear for indicating that baz simply combines the results of foo & bar, for example: (define valid-queen-moves (juxt valid-bishop-moves valid-rook-moves)) "juxt" is probably still not the best name, but better than my "unionify" which isn't even technically a union with respect to sets :) > > … > > but honestly, I think that the way you wrote it at first is probably the > best. IMHO. > > John Clements > > > > > I didn't like the redundancy, so I re-wrote as: > > > > (define (valid-queen-moves board idx is-opposite-color?) > > (append-map (λ (f) (apply f (list board idx is-opposite-color?))) > > (list valid-bishop-moves valid-rook-moves))) > > > > I thought that was still ugly, so I re-wrote as: > > > > (define (valid-queen-moves . args) > > (append-map (λ (f) (apply f args)) > > (list valid-bishop-moves valid-rook-moves))) > > > > And it was at this point that I finally though, "This has to be a solved > > problem already", but my initial searching turned up empty, so I wrote this: > > > > (define (unionify . functions) > > (λ args (append-map (λ (f) (apply f args)) functions))) > > > > (define valid-queen-moves (unionify valid-bishop-moves valid-rook-moves)) > > > > unionify is a *terrible* name, but my question is whether this higher order > > function already exists in the standard Racket library? I came close to > > writing flat-map before I found append-map, so I don't want to reinvent > > another wheel needlessly. > > > > Brian > > > > -- > > 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.