Skip to content

Commit 723c036

Browse files
self-hosted core.match fork w/ macro rewritten seems to work
1 parent 3b89de8 commit 723c036

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

features/core.match/deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{:deps
2-
{org.clojure/core.match {:mvn/version "1.1.0"}}}
2+
{viebel/abbinare {:mvn/version "1.10.597"}}}

features/core.match/src/nbb/impl/core_match.cljs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
(ns nbb.impl.core-match
2-
{:no-doc true}
3-
(:require [cljs.core.match :as match]
4-
[nbb.core :as nbb]
5-
[sci.core :as sci]))
2+
(:require [sci.core :as sci]
3+
;; self-hostable core.match (e.g. abbinare)
4+
[cljs.core.match :as m]
5+
[nbb.core :as nbb]))
6+
7+
(def m-ns (sci/create-ns 'cljs.core.match nil))
8+
9+
;; SCI macro: first two args are &form and &env
10+
;; Macro is mostly a copy of https://github.com/clojure/core.match/blob/753e8a30de9c487ceba8ff7d39435bf87edff505/src/main/clojure/cljs/core/match.clj#L19-L32
11+
(defn ^:sci/macro match
12+
[_&form _&env vars & clauses]
13+
(let [[vars clauses]
14+
(if (vector? vars)
15+
[vars clauses]
16+
[(vector vars)
17+
(mapcat (fn [[c a]]
18+
[(if (not= c :else) (vector c) c) a])
19+
(partition 2 clauses))])]
20+
;; Unlike original macro, this one doesn't have a *clojurescript* binding. Dunno if it's needed
21+
(binding [m/*line* (-> _&form meta :line)
22+
m/*locals* (dissoc (:locals _&env) '_)
23+
m/*warned* (atom false)]
24+
(m/clj-form vars clauses))))
625

7-
(def core-ns (sci/create-ns 'cljs.core.match nil))
826
(def core-namespace
9-
{'match (sci/copy-var match/match core-ns)})
27+
{'match (sci/copy-var match m-ns)
28+
'backtrack (sci/copy-var m/backtrack m-ns)})
1029

1130
(def config {:namespaces {'cljs.core.match core-namespace}})
1231

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@logseq/nbb-logseq",
3-
"version": "1.2.173-feat-db-v25",
3+
"version": "1.2.173-feat-db-v27",
44
"type": "module",
55
"main": "index.mjs",
66
"bin": {

0 commit comments

Comments
 (0)