Skip to content

Instantly share code, notes, and snippets.

View leontastic's full-sized avatar

Leon Li leontastic

View GitHub Profile
@leontastic
leontastic / assoc-clone.rkt
Last active January 3, 2016 17:49
Clone of Racket assoc built-in function, except uses equal? instead of is-equal?, and returns an error instead of #f if the element does not exist. See here: http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._assoc%29%29
; find-assoc: Any AL -> (listof Any)
; (find-assoc id al) produces the first element of al whose *car* is equal to id.
(define (find-assoc id al)
(first (filter (lambda (x) (equal? (first x) id)) al)))