Ramin Honary on Nostr: Can you pattern match an alist as associative data structure (not taking an order ...
Can you pattern match an alist as associative data structure (not taking an order into account)?
No, it doesn’t seem like you can, at least not without writing your own loop to do it. Also it does not allow you to assign a complex pattern to a variable the way Haskell does, which is a little sad.
(let loop ((alist alist) (collect '()))
(match alist
(() (reverse collect)
(((#:one . ,n) ,more ...) (loop more (cons (cons #:one n) collect)))
(((#:two . ,n) ,more ...) (loop more (cons (cons #:two n) collect)))
(((#:three . ,n) ,more ...) (loop more (cons (cons #:three n) collect)))
))
nprofile1qy2hwumn8ghj7un9d3shjtnddaehgu3wwp6kyqpqzglpd69ltamxe7nnm6rdfleu8amgg3sn24n8rvdey6avckmeax8qsejrff (nprofile…jrff)