Skip to content

Instantly share code, notes, and snippets.

@apropos-cast
Last active March 17, 2021 20:00
Show Gist options
  • Save apropos-cast/810beaf9353e014de339172c9bda0444 to your computer and use it in GitHub Desktop.
Save apropos-cast/810beaf9353e014de339172c9bda0444 to your computer and use it in GitHub Desktop.
Apropos March 10, 2021

Show Notes

Topics

Follow-up on tagged literals from last episode

Tagged Literal type (added Clojure 1.8, 2018): https://insideclojure.org/2018/06/21/tagged-literal/

(set! *default-data-reader-fn* tagged-literal)

Malli

https://github.com/metosin/malli

Update on Grokking Simplicity (Eric's book)

Dynamically implementing protocols

REPL Time!!

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}

Where to join us

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

@uwo
Copy link

uwo commented Mar 17, 2021

Love the show. Two concerns:

  1. Spec is ultimately aimed at fine-grained dependencies. It frustrates me when whole conversations go on without that being said.
  2. Rich has said mea culpa. It's the point of his talk "Maybe Not".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment