What is Nostr?
Ramin Honary /
npub1053…uwdv
2024-12-12 08:36:04
in reply to nevent1q…m9d7

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)
Author Public Key
npub1053m9ka5kf6r3rlcr3kmstaswqk2ewqduv2dvtjtud3p38r0dxvqepuwdv