Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Fikes mfikes

View GitHub Profile
View keys-vals.md

The following works in Clojure:

(keys (filter (comp odd? val) {:a 1 :b 2 :c 3}))

The docstrings for keys and vals don't indicate that you can do this. Is this accidential or intentional?

I vaguely recall Alex Miller indicating at some point that this capability was deemed useful and is intentionally allowed. Yes, this is an appeal to authority, but nevertheless, it makes a fairly convincing argument.

View README.md

Self-hosted:

$ plk
ClojureScript 1.10.597
cljs.user=> (require '[foo.core :refer [defnmy]])
nil
cljs.user=> (defnmy FOO clojure.string/lower-case [x]
       #_=>   (inc x))
#'cljs.user/foo
View android3.txt
/Users/mfikes/test-krell/AwesomeProject/node_modules/react-native/scripts/launchPackager.command; exit
Last login: Fri Apr 17 17:24:32 on ttys005
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Mikes-iMac:~ mfikes$ /Users/mfikes/test-krell/AwesomeProject/node_modules/react-native/scripts/launchPackager.command; exit
###### ######
### #### #### ###
View android2.txt
Mikes-iMac:AwesomeProject mfikes$ clj -Srepro -m krell.main -co build.edn -r
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[1] AwesomeProject sdm845
[R] Refresh
Choice: 1
View metro.txt
Last login: Fri Apr 17 17:07:01 on ttys002
/Users/mfikes/test-krell/AwesomeProject/node_modules/react-native/scripts/launchPackager.command ; exit;
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Mikes-iMac:~ mfikes$ /Users/mfikes/test-krell/AwesomeProject/node_modules/react-native/scripts/launchPackager.command ; exit;
@mfikes
mfikes / ESP32-REPL.md
Last active Sep 20, 2020
ClojureScript REPL into ESP32
View ESP32-REPL.md

To set up a REPL that has cljs.core available, we need to re-partition the ESP32 and allocate more memory in Espruino for "JsVars".

The default Espruino bootloader.bin, pre-built variants of partitions_esprinuo.bin and rebuilt espruino_esp32.bin, and the ClojureScript runtime core.bin are also available here.

bootloader.bin gets flashed to 0x1000, partitions_espruino.bin gets flashed to 0x8000, and espruino_esp32.bin gets flashed to 0x10000 as per a usual ESP32 Espruino setup, and we put the ClojureScript runtime at 0x2C0000:

View ESP32-wrover-cljs-advanced.md

Loading :advanced Code into an Unmodified WROVER running Espruino

You can load ClojureScript :advanced code directly into an ESP32 WROVER running Espruino for execution upon boot, by creating a binary and flashing it to the JavaScript "boot ROM" area. This has the same effect as when loading code via the Espruino Web IDE, in the "Direct to Flash (execute code at boot)" mode, but flashing is much quicker and more reliable.

Note: To do this, you'll need an ESP32 WROVER with SPI PSRAM, as opposed to just a WROOM, as the ClojureScript in this example uses more RAM than is available in the WROOM.

Create :advanced Code

Here is a small program that uses enough to pull in data structures, etc, leading to nearly 100 KiB:

View main-dce.js
function $cljs$core$Reduced$$($val$jscomp$52$$) {
this.$val$ = $val$jscomp$52$$;
this.$cljs$lang$protocol_mask$partition0$$ = 32768;
this.$cljs$lang$protocol_mask$partition1$$ = 0;
}
$cljs$core$Reduced$$.prototype.$cljs$core$IDeref$_deref$arity$1$ = function() {
return this.$val$;
};
@mfikes
mfikes / yes.md
Created Nov 23, 2019
Running ClojureScript on Espruino
View yes.md

With src/foo/core.cljs:

(ns foo.core)

(defn calculate []
 (let [xform (comp (map inc) (filter odd?) (take 123))]
   (transduce xform + (iterate inc 0))))

(js/print (calculate))
View optimize.md

Note we are using :static-fns, and also note we are using master to get inferrence for implements? CLJS-3140.

At its core is an (arguably internal) optimization surrounding the notion of ^not-native, which is also effectively enabled if a value is tagged with a protocol type.

Note that compiler enables inference for implements? but not satisfies? because the later would break things.

And, if a user type hints with a protocol type, while the user code is arguably correct, it would provoke the same bug surrounding satisfies?.

$ clj -Sdeps '{:deps {org.clojure/clojurescript {:git/url "https://github.com/clojure/clojurescript" :sha "b38ded99dc0967a48824d55ea644bee86b4eae5b"}}}' -m cljs.main -co '{:static-fns true}' -re node -r
You can’t perform that action at this time.