Skip to content

Instantly share code, notes, and snippets.

View mfikes's full-sized avatar

Mike Fikes mfikes

View GitHub Profile
@mfikes
mfikes / README.md
Last active November 20, 2018 09:41

:npm-deps can be placed in deps.cljs to establish an upstream NPM dependency.

Example use:

$ clj -Sdeps '{:deps {github-mfikes/gist-0ba48578175d8aa0afd4834f33107bb8 {:git/url "https://gist.github.com/mfikes/0ba48578175d8aa0afd4834f33107bb8" :sha "a4563fa41ac25ee9fafcab21fd4afe4c1a1f1697"}}}' -m cljs.main -co '{:npm-deps {} :install-deps true}' -d out -re node -r
ClojureScript 1.10.439
cljs.user=> (require 'pad)
nil
cljs.user=> (pad/left "abc" 10)
Clojure 1.10.0-beta5
user=> (ns foo.core)
nil
foo.core=> (def ^:private a 3)
#'foo.core/a
foo.core=> (defmacro access-a [] `(+ foo.core/a 3))
#'foo.core/access-a
foo.core=> (access-a)
6
foo.core=> (in-ns 'user)

JVM ClojureScript

$ clj -m cljs.main -re node -r
ClojureScript 1.10.439
cljs.user=> (require 'clojure.spec.test.alpha)
nil
cljs.user=> (require 'spec-mac.core)
nil
cljs.user=> (spec-mac.core/my-macro `str {})
(ns my-test.core
(:require
[cljs.spec.alpha :as s]
[cljs.spec.test.alpha :as stest]))
(defmacro instrument-without [exclude-syms]
`(stest/instrument '[~@(apply disj
(#?(:clj s/speced-vars
:cljs cljs.spec.alpha$macros/speced-vars))
(eval exclude-syms))]))
@mfikes
mfikes / patch.cljc
Last active November 3, 2018 02:39
Patching check
(ns repro.patch)
#?(:cljs (defn checkable-syms*
([]
(checkable-syms* nil))
([opts]
(reduce into #{}
[(filter js/cljs.spec.test.alpha$macros.fn_spec_name_QMARK_ (keys @js/cljs.spec.alpha$macros.registry_ref))
(keys (:spec opts))]))))
@mfikes
mfikes / clojurescript-types.md
Last active November 1, 2018 16:47
Understanding ClojureScript types

In progress - an explanation of the ClojureScript type system

The main idea is that a type can either be reprsented by a symbol, like number or string, or a set, like #{number string}. The latter means that the value set includes all numbers and strings.

These type symbols are the same ones used in tag meta, as in ^number, which expands to {:tag number}

The type of the value nil is the symbol clj-nil (as opposed to (symbol "nil"))

If you see nil as a type, this means the type wasn't infered.

(defn- get-arity-dispatch [f n]
(case n
0 (.-cljs$core$IFn$_invoke$arity$0 f)
1 (.-cljs$core$IFn$_invoke$arity$1 f)
2 (.-cljs$core$IFn$_invoke$arity$2 f)
3 (.-cljs$core$IFn$_invoke$arity$3 f)
4 (.-cljs$core$IFn$_invoke$arity$4 f)
5 (.-cljs$core$IFn$_invoke$arity$5 f)
6 (.-cljs$core$IFn$_invoke$arity$6 f)
7 (.-cljs$core$IFn$_invoke$arity$7 f)
@mfikes
mfikes / eval-fn.md
Last active October 19, 2018 17:15

src/foo/core.clj:

(ns foo.core)

(defn my-fn [] 1)

(defmacro bar [f] 
 ((eval f)))
$ jstack 97709
2018-10-13 13:26:33
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.172-b11 mixed mode):
"Attach Listener" #156 daemon prio=9 os_prio=31 tid=0x00007ff1d4a14000 nid=0x9f0b waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"clojure-agent-send-off-pool-1" #14 prio=5 os_prio=31 tid=0x00007ff1d4963800 nid=0x4003 waiting on condition [0x000070000cd57000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
@mfikes
mfikes / README.md
Last active February 24, 2024 13:43
Playing with BigInt in ClojureScript

Usage

Fire up a REPL using any of the following forms.

Node

clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:git/url "https://github.com/mfikes/clojurescript" :sha "ed1e7373a9ecd8b52084dc438e6c21d23dba47ca"}}}' -m cljs.main -re node