Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize cell? and fix docstrings #44

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch appeared to be unused

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))
(instance? Cell 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