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
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
> 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
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
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
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
6 matches
Mail list logo