On Tuesday, November 15, 2016 at 12:50:49 PM UTC-5, Brian Adkins wrote:
> 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 :)


Another question is whether or not to flatten the list of results lists or not. 
It seems a bit cleaner to not flatten, and let the caller do so, but I thought 
I read somewhere that there may be a performance advantage to "append-map" vs. 
calling each of them separately.

-- 
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.

Reply via email to