Tagged Literal type (added Clojure 1.8, 2018): https://insideclojure.org/2018/06/21/tagged-literal/
(set! *default-data-reader-fn* tagged-literal)
https://github.com/metosin/malli
- Link: https://lispcast.com/gs
- Tweet from @puredanger (Alex Miller): https://twitter.com/puredanger/status/1368949555945893890
- Link from Tommi Reiman: https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L295-L308
Pattern matching
When describing rhyming patterns, poets use letters to define patterns, like this:
Roses are red A
Violets are blue B
Sugar is sweet C
and so are you B
This poem has an ABCB rhyming structure because the B lines rhyme and A and C do not.
We'll use this same naming scheme but use equality instead of rhyming. Write a function that takes a sequence of values and a pattern string. It returns a a map of letters to values if the pattern matches, and nil
if it does not.
Examples:
(pattern [1 2 1 2] "ABAB") ;=> {\A 1 \B 2}
(pattern [1 2 3 2] "ABCB") ;=> {\A 1 \B 2 \C 3}
(pattern [1 2 3 4] "ABAB") ;=> nil
(pattern [1 1 1 1] "A") ;=> nil (wrong number of elements)
(pattern [1 1 1 1] "ABCD") ;=> {\A 1 \B 1 \C 1 \D 1}
(pattern [1 4 2 1] "ADCA") ;=> {\A 1 \D 4 \C 2}
Discord - Join if you want to watch us live or chat! https://discord.com/invite/hGNnK8N
Recording and playback on YouTube - https://www.youtube.com/channel/UC1UxEQuBvfLJgWR5tk_XIXA
Follow us on Twitter for updates - https://twitter.com/AproposClj
Love the show. Two concerns: