Public Vars

Back

assoc-in (clj)

(source)

function

(assoc-in m [k & ks] v)
Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value and returns a new nested structure. If any levels do not exist, hash-maps will be created.

Examples

noprompt/meander
(ns multimethods
  (:refer-clojure :exclude [defmethod defmulti])
  (:require
   #?(:clj [clojure.core :as clj] :cljs [cljs.core :as cljs])
   [meander.epsilon :as m]))

(defmacro defmethod
  [mf [& lhr] & body]
  (swap! cache_ assoc-in [mf lhr] body)
  (let [ptrns (get @cache_ mf)]
    `(-set-fn ~(with-meta mf {:tag `MultiMeanderFn})
              (fn [& ~'argsv]
                (m/match ~'argsv
                  ~@(loop [[[l r] & more] ptrns xs []]
                      (if l
                        (recur more (conj xs l (cons `do r)))
                        xs)))))))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

cc/assoc-in [(t/Nilable (t/Associative t/Any t/Any)) t/AnySeqable t/Any :-> t/Any]
juxt/jig
(ns jig.mqtt
  (:require
   jig
   [clojurewerkz.machine-head.client :as mh]
   [clojure.core.async :refer (chan >!! close!)]
   [clojure.tools.logging :refer :all])
  (:import (jig Lifecycle)))

(deftype MqttSubscriber [config]
  Lifecycle
  (init [_ system]
    (let [ch (chan (or (:channel-size config) 100))]
      (assoc-in system [:jig/channels (:channel config)] ch)))
  (start [_ system]
    (let [ch (get-in system [:jig/channels (:channel config)])]
      (infof "MQTT, client is %s, topics are %s" (::machine-head-client system) (:topics config))
      (mh/subscribe
       (::machine-head-client system)
       (:topics config)
       (fn [topic meta payload]
         (infof "Received message on topic %s: %s" topic (String. payload))
         (>!! ch {:topic topic :meta meta :payload payload}))))
    system)
  (stop [_ system]
    (let [client (::machine-head-client system)]
      (mh/unsubscribe client (:topics config)))
    (close! (get-in system [:jig/channels (:channel config)]))
    (update-in system [:jig/channels] dissoc (:channel config))))
re-path/studio
(ns renderer.tools.edit
  (:require
   [clojure.core.matrix :as mat]
   [renderer.element.handlers :as element.h]
   [renderer.handlers :as handlers]
   [renderer.history.handlers :as history]
   [renderer.tools.base :as tools]
   [renderer.utils.pointer :as pointer]))

(defmethod tools/drag :edit
  [{:keys [adjusted-pointer-offset adjusted-pointer-pos clicked-element] :as db} e]
  (let [pointer-offset (mat/sub adjusted-pointer-pos adjusted-pointer-offset)
        db (history/swap db)
        element-key (:element clicked-element)
        pointer-offset (if (contains? (:modifiers e) :ctrl)
                         (pointer/lock-direction pointer-offset)
                         pointer-offset)]
    (if element-key
      (assoc-in db
                (conj (element.h/path db) element-key)
                (tools/edit (element.h/element db element-key)
                            pointer-offset
                            (:key clicked-element)))
      db)))
Cnly/clj-latex
(ns dptab
  (:require [clojure.core.matrix :as m]
            [clj-latex.core :as l]))

(println
 (l/render-latex
   (:documentclass 'article)
   (:usepackage 'tikz)
   (:usepackage 'amsmath)
   (:newcommand :rn [2]
                (list
                  (:tikz ["remember picture", "baseline=(#1.base)"])
                  (:node ["inner sep=0"]) "(#1) {$#2$};"))
   ('document
     (let [[rows cols] [8 8]
           g (fn [i j] (if (= i j)
                         1
                         -1))
           tab (loop [tab (vec (repeat rows (vec (repeat cols 0))))
                      ijs (drop 1 (for [i (range rows)
                                        j (range cols)]
                                    [i j]))]
                 (if-let [[i j] (first ijs)]
                   (let [get-in-tab #(get-in tab %& ##-Inf)
                         v-top (+ (get-in-tab (dec i) j) -3)
                         v-left (+ (get-in-tab i (dec j)) -3)
                         v-topleft (+ (get-in-tab (dec i) (dec j)) (g i j))]
                     (recur (assoc-in tab [i j] (max v-top v-left v-topleft))
                            (next ijs)))
                   tab))
           tab (m/emap-indexed (fn [[i j] elem]
                                 (format "\\rn{%d%d}{%s}" i j elem)) tab)]
       (list
         (l/matrix 'matrix tab)
         ('tikzpicture [['overlay, "remember picture"]]
                       (for [i (range (- rows 1))]
                         (list (:draw ['->]) (format "(%d%d)--(%d%d);" i i (inc i) (inc i))))))))))