concept time in category clojure

This is an excerpt from Manning's book Clojure: The Essential Reference.
The keyboard requires time and dedication to operate correctly. There are endless discussions on the best keyboard layout for programmers, for example to speed up typing [1].
(defn titles [doc] ; #1 (some->> doc ; #2 (re-seq #"<title>(.+?)</title>") ; #3 (map peek))) ; #4 (titles nil) ;; nil (titles "<html><head>Document without a title</head></html>") ;; nil (titles "<html><head> <title>Once upon a time</title> <title>Kingston upon Thames</title> </head></html>") ;; ("Once upon a time" "Kingston upon Thames")
Clojure equality is designed to be intuitive most of the time (without requiring a specific knowledge of types) with a few corner cases that are going to be illustrated in this chapter. Compared to Object Oriented Programming, functional programming puts less emphasis on container objects and their need for a custom implementation of equality (and hashing as a consequence). Clojure, on the other hand, offers analogous custom data structures called records (created with “defrecord”) which come with a built-in equality based on attributes.

This is an excerpt from Manning's book Clojure in Action, Second Edition.
4For those already familiar with Clojure, note that we use the term variable loosely at this point to introduce Clojure’s unique handling of values, identities, and underlying state and how those all change over time. We’ll cover the specifics of Clojure’s concurrency constructs in a later section using Clojure’s precise terminology.
Functional languages are often judged by their functional “purity,” or strict adherence to the theoretical underpinnings of functional programming language design. On the one hand, Clojure’s default use patterns encourage pure functional programming: immutable data structures, higher-order functions and recursion that take the place of imperative loops, and even a choice between lazy or eager evaluation of collections. On the other hand, Clojure is pragmatic. Even though most problems can be solved using immutable data structures and functional programming patterns, certain tasks are more clearly modeled with mutable state and a more imperative approach. Clojure provides constructs with well-defined semantics for sharing state and changing it over time as we’ve just described. In addition, Clojure also doesn’t require the developer to annotate code that causes side-effects, whether they be changes to state, printing to the screen, or network I/O, as some “purer” functional programming languages require.
This leads us to the end of the discussion on anaphora. It’s a useful technique at times, even though it breaks hygiene because it involves variable capture. As mentioned, you have to be careful while using it, but when you do, it can result in code that’s more readable than it would be otherwise.

This is an excerpt from Manning's book The Joy of Clojure, Second Edition.
It can be hard at times to tease apart these concepts in your mind, but accomplishing it can bring remarkable clarity and a sense of power and flexibility that’s worth the effort. With all these different concepts at your disposal, it’s important that the code and data you work with express this variety in a consistent way.
The first important term to define is time. Simply put, time refers to the relative moments when events occur. Over time, the properties associated with an entity—both static and changing, singular or composite—will form a concrescence (Whitehead 1929), or, in other words, its identity. It follows that at any given time, a snapshot can be taken of an entity’s properties, defining its state. This notion of state is an immutable one because it’s not defined as a mutation in the entity itself, but only as a manifestation of its properties at a given moment in time. Imagine a child’s flip book, as shown in figure 1.7, to understand the terms fully.
Figure 1.7. The Runner. A child’s flip book serves to illustrate Clojure’s notions of state, time, and identity. The book itself represents the identity. Whenever you wish to show a change in the illustration, you draw another picture and add it to the end of your flip book. The act of flipping the pages therefore represents the states over time of the image within. Stopping at any given page and observing the particular picture represents the state of the Runner at that moment in time.
![]()
It’s important to note that in the canon of object-oriented programming (OOP), there’s no clear distinction between state and identity. In other words, these two ideas are conflated into what’s commonly referred to as mutable state. The classical object-oriented model allows unrestrained mutation of object properties without a willingness to preserve historical states. Clojure’s implementation attempts to draw a clear separation between an object’s state and identity as they relate to time. To state the difference from Clojure’s model in terms of the aforementioned flip book, the mutable state model is different, as shown in figure 1.8.
Figure 1.8. The Mutable Runner. Modeling state change with mutation requires that you stock up on erasers. Your book becomes a single page: in order to model changes, you must physically erase and redraw the parts of the picture requiring change. Using this model, you should see that mutation destroys all notion of time, and state and identity become one.
![]()
Listing 13.6. Web Audio functions in ClojureScript
(ns joy.music) (defn soft-attack #1 "Return a gain node that goes from silent at time <delay> up to <volume> in 50 milliseconds, then ramps back down to silent after <duration>" [ctx {:keys [volume delay duration]}] (let [node (.createGainNode ctx)] (doto (.-gain node) (.linearRampToValueAtTime 0 delay) (.linearRampToValueAtTime volume (+ delay 0.05)) #2 (.linearRampToValueAtTime 0 (+ delay duration))) node)) (defn sine-tone #3 "Return an oscillator that plays starting at <delay> for <duration> seconds" [ctx {:keys [cent delay duration]}] (let [node (.createOscillator ctx)] (set! (-> node .-frequency .-value) 440) (set! (-> node .-detune .-value) (- cent 900)) #4 (.noteOn node delay) (.noteOff node (+ delay duration)) node)) (defn connect-to #5 "Connect the output of node1 to the input of node2, returning node2" [node1 node2] (.connect node1 node2) node2) (defn woo #6 "Play a 'woo' sound; sounds a bit like a glass harp." [ctx note] (let [linger 1.5 note (update-in note [:duration] * linger)] (-> (sine-tone ctx note) (connect-to (soft-attack ctx note))))) (def make-once (memoize (fn [ctor] (new ctor)))) (defn play! #7 "Kick off playing a sequence of notes. note-fn must take two arguments, an AudioContext object and a map representing one note to play. It must return an AudioNode object that will play that note." [note-fn notes] (if-let [ctor (or (.-AudioContext js/window) (.-webkitAudioContext js/window))] (let [ctx (make-once ctor) compressor (.createDynamicsCompressor ctx)] #8 (let [now (.-currentTime ctx)] (doseq [note notes] (-> (note-fn ctx (update-in note [:delay] + now)) (connect-to compressor)))) (connect-to compressor (.-destination ctx))) (js/alert "Sorry, this browser doesn't support AudioContext"))) #1 – 1 Create and configure a gain node #2 – 2 Set the max volume of the gain node #3 – 3 Create and configure an oscillator node #4 – 4 Set the cent of the oscillator #5 – 5 Connect two nodes #6 – 6 Create and connect nodes to play a note #7 – 7 Play notes using a note fn #8 – 8 Protect your speakers and ears !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[]"} !@%STYLE%@!