This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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")] |