You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

#lang racket
(provide (all-defined-out))
(define (zip l1 l2)
(match (list l1 l2)
[(list l1 '()) l1]
[(list '() l2) l2]
[(list (cons l1 l1-rest) (cons l2 l2-rest))
(cons l1 (cons l2 (zip l1-rest l2-rest)))]))
(define (read-csv path)
(with-input-from-file path
(lambda ()
(let* ([comma-split (curryr string-split ",")]
[keys (map string->symbol (comma-split (read-line)))]
[hash-line (lambda(line) (apply hash (zip keys line)))])
(map (compose hash-line comma-split) (port->lines))))))
;; turn a list of hashmaps into a hashmap of hashmaps keyed on inner key k
(define (listmap->mapmap listmap k)
(for/fold ([mapmap (hash)])
([h listmap])
(let* ([mapmap-list (flatten (hash->list mapmap))]
[primary-value (hash-ref h k)]
[hash-list (cons primary-value (cons h mapmap-list))])
(apply hash hash-list))))
(define (make-obj get-props set-props methods)
(lambda (msg . args)
(match args
[(list p)
#:when (member p get-props)
"get-prop"]
[(list p v)
#:when (member p set-props)
"set-prop"]
[(cons p args)
#:when (member p methods)
"method call"])))