This file contains 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 metasimple.simple-editor.core | |
(:require | |
[clojure.string :as str])) | |
(defn- process-op-append | |
[{:keys [text] :as ed-state} | |
{:keys [op-type arg]}] | |
(-> ed-state | |
(update :text str arg) | |
(update :undo-history conj {:op-type op-type :text text}))) |
This file contains 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 metasimple.huffman.core | |
(:require | |
[clojure.pprint :as pp] | |
[clojure.string :as str])) | |
(defn- sorted-frequencies-map | |
[s] | |
(reduce (fn [fm c] | |
(update fm c (fnil inc 0))) | |
(array-map) |
This file contains 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 '[clara.rules :as r]) | |
(require '[clara.rules.accumulators :as acc]) | |
(defrecord ExternalFact [id code]) | |
(defrecord DerivedFact [ids]) | |
(r/defrule match-and-remove-it | |
{:salience 1000000} | |
[?fact <- ExternalFact (= ?id id) (= code "a")] | |
=> |
This file contains 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
(defrecord PrevFetchedItems [item-ids]) | |
(defrecord ToFetch [items]) | |
(r/defrule find-items-to-fetch | |
[PrevFetchedItems (= ?item-ids item-ids)] | |
[?items <- (acc/all) :from [Item (not (contains? ?items id))]] | |
=> | |
(r/insert! (->ToFetch ?items))) | |
(r/defquery get-items-to-fetch [] |
This file contains 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
;; Usually the solution is to reframe the problem you have in a way that avoids the logical contradiction, | |
;; ie. 'not B => B' | |
;; and continue to use the default inserts (not unconditional type) that participate in truth maintenance | |
;; To avoid a rule like this: | |
(r/defrule b-contradiction | |
[A] | |
[:not [B]] | |
=> | |
(r/insert! (->B)) |
This file contains 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
#error { | |
:cause "Unable to resolve symbol: bar in this context" | |
:via | |
[{:type clojure.lang.ExceptionInfo | |
:message "failed compiling file:src/example/foo.cljs" | |
:data {:file #object[java.io.File 0x2766fb87 "src/example/foo.cljs"]} | |
:at [clojure.core$ex_info invokeStatic "core.clj" 4739]} | |
{:type clojure.lang.ExceptionInfo | |
:message "java.lang.RuntimeException: Unable to resolve symbol: bar in this context, compiling:(*thing*:6:9) at line 6 src/example/foo.cljs" | |
:data {:file "src/example/foo.cljs", :line 6, :column 1, :tag :cljs/analysis-error} |
This file contains 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
;;;; Dealing with jumping cursors on controlled input (a classic React/Reagent problem). | |
;;;; For rationale see | |
;;;; https://github.com/reagent-project/reagent/issues/265#issuecomment-397895508 | |
;;;; & | |
;;;; https://github.com/reagent-project/reagent/blob/e53be656073af9209c4fe8bc9119635953311d42/examples/material-ui/src/example/core.cljs#L34 | |
;; In the ns header... | |
(:require [reagent.core :as r] | |
[reagent.impl.template :as template]) |
This file contains 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 '[clara.rules :as r]) | |
;;;; Define 3 rules, where the "priority" order is r1, r2, r3, where the highest priority is first | |
;;;; and the rest is in descending order of priority. | |
;;;; :type :rule/result "syntetic" fact is used to hold the final changes that can be queried out | |
;;;; from a session after `r/fire-rules` via `r/query` on the `find-results` query. | |
;;;; A namespace qualified keyword is used to avoid collision with externally given :type of | |
;;;; "real" facts. |
This file contains 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
;;;; Fressian dependency used in these examples | |
;; [org.clojure/data.fressian "0.2.1"] | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;;; Using only `org.clojure/data.fressian` | |
(require '[clojure.data.fressian :as fres]) | |
(defn serde-obj |
This file contains 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 clara.rules.durability | |
"Experimental namespace. This may change non-passively without warning. | |
Support for persisting Clara sessions to an external store. | |
See the serialize-session-state function to retrieve the full state of a session as a data structure that can | |
be easily serialized via EDN or Fressian. Sessions can then be recovered with the restore-session-state function. | |
TODO: diff support is pending -- functions for obtaining a diff of state from a previous point, allowing for a write-ahead log." | |
(:require [clara.rules :refer :all] |
NewerOlder