Re: [racket-users] right abstraction for this?

2015-06-18 Thread Geoffrey Knauth
Just the thing I need today for a Racket web-powered table of database info, thanks all. --Geoff On Thursday, June 11, 2015 at 1:55:35 PM UTC-4, Greg Hendershott wrote: > IIUC in SQL this would simply be: > > SELECT student, AVG(rating) > FROM scores > GROUP BY student > > Apparently a DSL for

Re: [racket-users] right abstraction for this?

2015-06-11 Thread Vincent St-Amour
As Greg points out, it was directly inspired by SQL's `group-by`. I've found it really handy when thinking about data in a relational way. Anyone opposed to moving it to `racket/list`? That would make it more discoverable? Vincent At Thu, 11 Jun 2015 11:17:26 -0700, 'John Clements' via users-r

Re: [racket-users] right abstraction for this?

2015-06-11 Thread 'John Clements' via users-redirect
> On Jun 11, 2015, at 10:19 AM, Stephen Chang wrote: > > Would any of the functions in unstable/list help? For example, Ah, ‘group-by’ is very nice, yes. Looks like that was Vincent’s? Many thanks, Vincent! John -- You received this message because you are subscribed to the Google Groups

Re: [racket-users] right abstraction for this?

2015-06-11 Thread Greg Hendershott
IIUC in SQL this would simply be: SELECT student, AVG(rating) FROM scores GROUP BY student Apparently a DSL for querying tables can be handy. :) The Racket equivalent for the special case of a 2-column table (a hash-table) could be something like: (define (sql-ish-aggregate-group-by f xs) (f

Re: [racket-users] right abstraction for this?

2015-06-11 Thread Stephen Chang
Would any of the functions in unstable/list help? For example, #lang racket (require unstable/list) (define (gather lst) (for/hash ([g (group-by car lst)]) (values (caar g) (append-map cdr g (gather '((a c) (a d) (b e) (b f))) ; => '#hash((a . (c d)) (b . (e f))) On Thu, Jun 11, 2015

[racket-users] right abstraction for this?

2015-06-11 Thread 'John Clements' via users-redirect
I write this kind of code all the darn time: ;; take (listof (list a b)) into (hashof a (listof b)) (define (gather l) (for/fold ([ht (make-hash)]) ([pr l]) (hash-set ht (first pr) (cons (second pr) (hash-ref ht (first pr) empty) ;; gather t