Skip to content

Commit

Permalink
use feature expressions .cljc with latest clojure, replacing cljx
Browse files Browse the repository at this point in the history
  • Loading branch information
floybix committed Apr 13, 2015
1 parent 60d1578 commit 162e6ac
Show file tree
Hide file tree
Showing 31 changed files with 91 additions and 138 deletions.
7 changes: 0 additions & 7 deletions dev/user.clj
@@ -1,10 +1,3 @@
;; Clojure loads user.clj long before cljx is loaded.
;; This hack is only necessary within the comportex project --
;; other comportex consumers never see the cljx files.
(require '[cljx.repl-middleware :as cljx])
(reset! @#'cljx/cljx-load-rules {:clj cljx.rules/clj-rules})
@@#'cljx/install-cljx-load

(ns user
(:require org.nfrac.comportex.repl))

Expand Down
50 changes: 11 additions & 39 deletions project.clj
Expand Up @@ -3,51 +3,23 @@
:url "http://github.com/nupic-community/comportex/"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:source-paths ["src/cljx"]
:test-paths ["target/test-classes"]
:dependencies [[org.clojure/clojure "1.6.0"]
:dependencies [[org.clojure/clojure "1.7.0-beta1"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[com.cemerick/pprng "0.0.2"]
[clj-http "1.0.1"]
[cljs-http "0.1.19"]
[com.cemerick/pprng "0.0.3"]
[clj-http "1.1.0"]
[cljs-http "0.1.30"]
[cljs-uuid "0.0.4"]]

:jar-exclusions [#"\.cljx"]
:jvm-opts ^:replace ["-server" "-Xmx2500m"]

:cljx {:builds [{:source-paths ["src/cljx"]
:output-path "target/classes"
:rules :clj}

{:source-paths ["src/cljx"]
:output-path "target/classes"
:rules :cljs}

{:source-paths ["test/cljx"]
:output-path "target/test-classes"
:rules :clj}

{:source-paths ["test/cljx"]
:output-path "target/test-classes"
:rules :cljs}]}

:cljsbuild {:builds [{:source-paths ["target/classes"
"target/test-classes"]
:jar true
:cljsbuild {:builds [{:jar true
:compiler {:output-to "target/testable.js"
:optimizations :advanced}}]}

:profiles {:dev {:dependencies [[org.clojure/clojurescript "0.0-2234"]
:profiles {:dev {:dependencies [[org.clojure/clojurescript "0.0-3196"]
[criterium "0.4.3"]]
:plugins [[com.keminglabs/cljx "0.5.0"]
[lein-cljsbuild "1.0.3"]
[com.cemerick/clojurescript.test "0.3.1"]
[com.cemerick/austin "0.1.4"]
[lein-marginalia "0.8.0"]]

:auto-clean false

:aliases {"install" ["do" "clean,"
"cljx" "once,"
"install"]}}
:repl {:source-paths ["dev"]}})
:plugins [[lein-cljsbuild "1.0.5"]
[com.cemerick/clojurescript.test "0.3.3"]
[com.cemerick/austin "0.1.6"]
[lein-marginalia "0.8.0"]]}
:repl {:source-paths ["dev" "src"]}})
Expand Up @@ -20,15 +20,15 @@
;; Created 23 June 2009


(ns
(ns
^{:author "Jeffrey Straszheim",
:doc "Basic graph theory algorithms"}
org.nfrac.comportex.algo-graph
(:require [clojure.set :refer [union]]))


(defrecord DirectedGraph
[nodes neighbors])
[nodes neighbors])

(defn directed-graph
"`nodes` - The nodes of the graph, a collection.
Expand Down Expand Up @@ -103,8 +103,8 @@
(directed-graph
(:nodes g)
(fn [n] (force (nbs n))))))


;; Strongly Connected Components

(defn- post-ordered-visit
Expand All @@ -116,7 +116,7 @@
[(conj visited n) acc]
(get-neighbors g n))]
[v2 (conj acc2 n)])))

(defn post-ordered-nodes
"Return a sequence of indexes of a post-ordered walk of the graph."
[g]
Expand Down Expand Up @@ -170,7 +170,7 @@
self-recursive."
[g]
(filter (partial recursive-component? g) (scc g)))


;; Dependency Lists

Expand All @@ -181,15 +181,13 @@
[data fun max equal]
(let [step (fn step [data idx]
(when (and idx (= 0 idx))
(throw (#+clj Exception.
#+cljs js/Error.
"Fixed point overflow")))
(assert false "Fixed point overflow"))
(let [new-data (fun data)]
(if (equal data new-data)
new-data
(recur new-data (and idx (dec idx))))))]
(step data max)))

(defn- fold-into-sets
[priorities]
(let [max (inc (apply max 0 (vals priorities)))
Expand All @@ -198,7 +196,7 @@
(reduce step
(vec (replicate max #{}))
priorities)))

(defn dependency-list
"Similar to a topological sort, this returns a vector of sets. The
set of nodes at index 0 are independent. The set at index 1 depend
Expand All @@ -215,7 +213,7 @@
(inc (count (:nodes g)))
=)]
(fold-into-sets counts)))

(defn stratification-list
"Similar to dependency-list (see doc), except two graphs are
provided. The first is as dependency-list. The second (which may
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -307,7 +307,7 @@
(topology/make-topology (conj (:column-dimensions spec)
(:depth spec)))))

#+cljs (def pmap map)
#?(:cljs (def pmap map))

(defrecord RegionNetwork
[ff-deps fb-deps strata inputs regions uuid->id]
Expand Down
Expand Up @@ -4,10 +4,10 @@
[org.nfrac.comportex.encoders :as enc]
[org.nfrac.comportex.util :as util]
[clojure.string :as str]
#+clj [clj-http.client :as http]
#+cljs [cljs-http.client :as http]
#+cljs [cljs.core.async :refer [<!]])
#+cljs (:require-macros [cljs.core.async.macros :refer [go]]))
#?(:clj [clj-http.client :as http]
:cljs [cljs-http.client :as http])
#?(:cljs [cljs.core.async :refer [<!]]))
#?(:cljs (:require-macros [cljs.core.async.macros :refer [go]])))

(def base-uri "http://api.cortical.io/rest")
(def query-params {:retina_name "en_associative"})
Expand All @@ -22,8 +22,7 @@
{:query-params query-params
:content-type "application/json"
:as :json
#+clj :form-params
#+cljs :json-params {:term term}
#?(:clj :form-params, :cljs :json-params) {:term term}
:with-credentials? false
:throw-exceptions false
:headers {"api-key" api-key}}))
Expand All @@ -36,8 +35,7 @@
:max_results max-n)
:content-type "application/json"
:as :json
#+clj :form-params
#+cljs :json-params {:positions (sort bits)}
#?(:clj :form-params, :cljs :json-params) {:positions (sort bits)}
:with-credentials? false
:throw-exceptions false
:headers {"api-key" api-key}}))
Expand Down Expand Up @@ -91,13 +89,13 @@
(do (println "cortical.io lookup of term failed:" term)
(println result)
(random-sdr))))]
#+clj ;; clj - synchronous
(let [result (request-fingerprint api-key term)]
(swap! cache ?assoc term (handle result)))
#+cljs ;; cljs - asynchronous
(go
(let [result (<! (request-fingerprint api-key term))]
(swap! cache ?assoc term (handle result))))))
#?(:clj ;; clj - synchronous
(let [result (request-fingerprint api-key term)]
(swap! cache ?assoc term (handle result)))
:cljs ;; cljs - asynchronous
(go
(let [result (<! (request-fingerprint api-key term))]
(swap! cache ?assoc term (handle result)))))))

(defn get-fingerprint
"Looks up a fingerprint for the term, being a set of active indices,
Expand Down Expand Up @@ -166,9 +164,10 @@
(assoc :value (get item :term))))))
(take n))
(println result)))]
#+clj ;; clj - synchronous
(handle (request-similar-terms api-key bits n))
#+cljs ;; cljs - asynchronous
{:channel
(go
(handle (<! (request-similar-terms api-key bits n))))})))))))))
#?(:clj ;; clj - synchronous
(handle (request-similar-terms api-key bits n))
:cljs ;; cljs - asynchronous
{:channel
(go
(handle (<! (request-similar-terms api-key bits n))))}))
))))))))
File renamed without changes.
Expand Up @@ -4,9 +4,9 @@
[org.nfrac.comportex.cells :as cells]
[org.nfrac.comportex.encoders :as enc]
[org.nfrac.comportex.util :as util :refer [round abs]]
#+clj [clojure.core.async :refer [<! >! go]]
#+cljs [cljs.core.async :refer [<! >!]])
#+cljs (:require-macros [cljs.core.async.macros :refer [go]]))
#?(:clj [clojure.core.async :refer [<! >! go]]
:cljs [cljs.core.async :refer [<! >!]]))
#?(:cljs (:require-macros [cljs.core.async.macros :refer [go]])))

(def input-dim [1000])
(def on-bits 100)
Expand Down Expand Up @@ -114,7 +114,7 @@
learn-value (+ reward (* q-discount Qt-st+1))
adjust (* q-alpha (- learn-value Qt-st))
up? (pos? adjust)]
(->
(->
(p/layer-learn lyr)
(assoc :proximal-sg
(reduce (fn [psg col]
Expand Down Expand Up @@ -187,7 +187,7 @@
(def world-c (async/chan))
(def model (atom (make-model)))
(def steps-c (async/chan))

(feed-world-c-with-actions! steps-c world-c model)

(def inv (<!! world-c))
Expand All @@ -198,5 +198,5 @@
(get-in @model [:regions :action :layer-3 :state :Q-val])
(get-in @model [:regions :action :layer-3 :state :Q-info])
(get-in @model [:regions :action :layer-3 :state :active-cols])

)
Expand Up @@ -5,9 +5,9 @@
[org.nfrac.comportex.encoders :as enc]
[org.nfrac.comportex.util :as util :refer [round abs]]
[org.nfrac.comportex.demos.q-learning-1d :refer [q-learn]]
#+clj [clojure.core.async :refer [<! >! go]]
#+cljs [cljs.core.async :refer [<! >!]])
#+cljs (:require-macros [cljs.core.async.macros :refer [go]]))
#?(:clj [clojure.core.async :refer [<! >! go]]
:cljs [cljs.core.async :refer [<! >!]]))
#?(:cljs (:require-macros [cljs.core.async.macros :refer [go]])))

(def input-dim [40 40])
(def on-bits 160)
Expand Down Expand Up @@ -171,7 +171,7 @@
(def world-c (async/chan))
(def model (atom (make-model)))
(def steps-c (async/chan))

(feed-world-c-with-actions! steps-c world-c model)

(def inv (<!! world-c))
Expand All @@ -182,5 +182,5 @@
(get-in @model [:regions :action :layer-3 :state :Q-val])
(get-in @model [:regions :action :layer-3 :state :Q-info])
(get-in @model [:regions :action :layer-3 :state :active-cols])

)
File renamed without changes.
Expand Up @@ -138,7 +138,7 @@ Chifung has no tail.

(defn n-region-model
([n]
(n-region-model input-text 3 n spec))
(n-region-model input-text n spec))
([text n spec]
(let [inp (core/sensory-input (make-block-encoder text))]
(core/regions-in-series core/sensory-region inp n spec))))
File renamed without changes.
Expand Up @@ -63,8 +63,8 @@
(defn inhibits-exc
"Threshold excitation level at which a cell with excitation `x`
inhibits a neighbour cell at a distance `dist` columns away."
#+clj ^double [^double x ^double dist ^double max-dist ^double base-dist]
#+cljs [x dist max-dist base-dist]
#?(:clj ^double [^double x ^double dist ^double max-dist ^double base-dist]
:cljs [x dist max-dist base-dist])
(let [z (- 1.0 (/ (max 0.0 (- dist base-dist))
(- max-dist base-dist)))]
(* x z)))
Expand Down
File renamed without changes.
@@ -1,13 +1,12 @@
(ns org.nfrac.comportex.repl
"Optional REPL tweaks"
(:require #+clj [clojure.pprint :as pprint]
[org.nfrac.comportex.cells
#+cljs :refer #+cljs [LayerOfCells]]
[org.nfrac.comportex.synapses
#+cljs :refer #+cljs [SynapseGraph]])
#+clj
(:import [org.nfrac.comportex.cells LayerOfCells]
[org.nfrac.comportex.synapses SynapseGraph]))
#?(:clj (:require [clojure.pprint :as pprint]
[org.nfrac.comportex.cells]
[org.nfrac.comportex.synapses])
:cljs (:require [org.nfrac.comportex.cells :refer [LayerOfCells]]
[org.nfrac.comportex.synapses :refer [SynapseGraph]]))
#?(:clj (:import [org.nfrac.comportex.cells LayerOfCells]
[org.nfrac.comportex.synapses SynapseGraph])))

;;; ## Truncate large data structures

Expand All @@ -23,8 +22,9 @@

(def ^:dynamic *truncated-print-length* 3)

(def print-methods [#+clj print-method
#+clj pprint/simple-dispatch])
(def print-methods #?(:clj [print-method
pprint/simple-dispatch]
:cljs []))

(def should-truncate {LayerOfCells
[:boosts :active-duty-cycles :overlap-duty-cycles],
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -27,11 +27,11 @@

(defn set-seed!
[seed]
#+cljs
:not-implemented
#+clj
(alter-var-root (var RNG)
(fn [_] (rng/rng seed))))
#?(:cljs
:not-implemented
:clj
(alter-var-root (var RNG)
(fn [_] (rng/rng seed)))))

(defn rand
([]
Expand Down Expand Up @@ -213,8 +213,8 @@
(mapcat #(map (partial + %) %2) offs others)))))

(def empty-queue
#+cljs cljs.core.PersistentQueue.EMPTY
#+clj clojure.lang.PersistentQueue/EMPTY)
#?(:cljs cljs.core.PersistentQueue.EMPTY
:clj clojure.lang.PersistentQueue/EMPTY))

(defn keep-history-middleware
"Returns a function that adds a metadata key `meta-key` to its
Expand Down

0 comments on commit 162e6ac

Please sign in to comment.