Skip to content

Instantly share code, notes, and snippets.

(require '[clojure.string :as str])
(defn parse-line [line]
(let [line (str/replace line #"[\\]\s*(\n\s*|$)" "")]
(when-not (str/blank? line)
(let [[k v] (str/split line #"=" 2)]
[(str/trim k) (when-not (str/blank? v) (str/trim v))]))))
(defn parse [text]
(let [lines (str/split text #"(?<![\s\\])\s*\n")]
(ns pie-a-la-mode)
;; Concurrency example from The Pragmatic Programmers. Waiters check if there's
;; enough pie and ice cream before they sell an order, but if they don't
;; coordinate it's still possible to sell more than we have.
;;
;; The below code should return either :ok or :not-available for a given order.
;; If we oversell, then it will throw an exception.
;;
;; How would you change this to ensure that that doesn't happen?