Skip to content

Commit

Permalink
Merge pull request #44 from borkdude/master
Browse files Browse the repository at this point in the history
Optimize cell? and fix docstrings
  • Loading branch information
mynomoto authored Oct 30, 2023
2 parents ea9f0bb + 15f607b commit dbd3f89
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
22 changes: 10 additions & 12 deletions src/javelin/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
[clojure.walk :refer [prewalk]]
[clojure.pprint :as p]
[cljs.analyzer :as a]
[clojure.java.io :as io]
[clojure.string :as s]))
[clojure.set :as set]))

(declare walk)

Expand Down Expand Up @@ -48,7 +47,7 @@
[bindings]
(let [syms1 (set (extract-syms bindings))
syms2 (set (extract-syms bindings))]
(seq (clojure.set/intersection syms1 syms2))))
(seq (set/intersection syms1 syms2))))

(defn bind-syms
"Given a binding form, returns a seq of the symbols that will be bound.
Expand Down Expand Up @@ -108,7 +107,6 @@
empty?* #(= 0 (count %))
dot? #(= '. (first %))
try? #(= 'try (first %))
catch? #(= 'catch (first %))
finally? #(= 'finally (first %))
binding1? #(contains? '#{let* loop*} (first %))
binding2? #(= 'letfn* (first %))
Expand Down Expand Up @@ -170,14 +168,14 @@
(let [fname (when (symbol? (first arities)) [(first arities)])
arities (if fname (rest arities) arities)
arities (if (vector? (first arities)) [arities] arities)
local (if fname (conj local (first fname)) local)]
(let [mkarity (fn [[bindings & body]]
(let [local (into local (remove #(= '& %) bindings))]
(to-list `([~@bindings] ~@(map #(walk % local) body)))))
arities (map mkarity arities)]
(to-list `(~sym ~@fname ~@arities)))))

(defn walk-passthru [x local]
local (if fname (conj local (first fname)) local)
mkarity (fn [[bindings & body]]
(let [local (into local (remove #(= '& %) bindings))]
(to-list `([~@bindings] ~@(map #(walk % local) body)))))
arities (map mkarity arities)]
(to-list `(~sym ~@fname ~@arities))))

(defn walk-passthru [x _local]
(with-let* [s (gensym)] (swap! *pass* assoc s x)))

(defn walk-dot [[sym obj meth & more] local]
Expand Down
13 changes: 6 additions & 7 deletions src/javelin/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

(ns javelin.core
(:require-macros [javelin.core])
(:require [goog.array :as garray]
[goog.object :as gobj]))
(:require [goog.array :as garray]))

;; helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down Expand Up @@ -145,26 +144,26 @@
(defn cell?
"Returns c if c is a Cell, nil otherwise."
[c]
(when (= (type c) Cell) c))
(when (instance? Cell c) c))

(defn formula?
[c]
"Returns c if c is a formula cell, nil otherwise."
[c]
(when (and (cell? c) (.-thunk c)) c))

(defn lens?
[c]
"Returns c if c is a lens, nil otherwise."
[c]
(when (and (cell? c) (.-update c)) c))

(defn input?
[c]
"Returns c if c is an input cell, nil otherwise."
[c]
(when (and (cell? c) (not (formula? c))) c))

(defn constant?
[c]
"Returns c if c is a constant formula cell, nil otherwise."
[c]
(when (and (cell? c) (.-constant c)) c))

(defn set-cell!
Expand Down
9 changes: 4 additions & 5 deletions src/javelin/core_clj.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns javelin.core-clj
(:refer-clojure :exclude [accessor])
(:require
[riddley.compiler :refer [locals]]
[riddley.walk :refer [walk-exprs]]
[clojure.data.priority-map :refer [priority-map]]))

Expand Down Expand Up @@ -84,11 +83,11 @@
(let [hoist (atom [])
local #(symbol (name %))
core? #(= "clojure.core" (namespace %))
skip? #(or
(not (contains? &env %))
(contains? specials %)
skip? #(or
(not (contains? &env %))
(contains? specials %)
(core? %))
walk! #(do (if-not (skip? %)
walk! #(do (if-not (skip? %)
(do (swap! hoist conj %) (local %))
%))
walked (walk-exprs symbol? walk! expr)
Expand Down

0 comments on commit dbd3f89

Please sign in to comment.