Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/4d94ad33f1d3460d3b12 to your computer and use it in GitHub Desktop.
Save mfikes/4d94ad33f1d3460d3b12 to your computer and use it in GitHub Desktop.
CLJS REPL Gaps

When you start up a CLJS REPL based on cljs.repl, things are much improved compared to their state prior to the beginning of 2015. But, there are a few gaps relative to the experience you get when you start up lein repl (and are dropped into REPLy).

Some of these things may or may not be appropriate for consideration in the base cljs.repl, but I'd like to at least enumerate the differences. If you know of one, feel free to comment and I can add to the list here:

  • Auto-completion (Type (ma and then hit tab to see list, type (mapc and hit tab and it will complete to (mapcat.)
  • Interruptible eval (Ctrl-C a long-running eval)
  • Break out of multi-line edit (e.g., type (map, hit return and then ctrl-c to get back to prompt)
  • Paste really long lines (longer than tty buffer size)
  • Line editing and history (rlwrap)
  • Evaluating ns form doesn't result in the availability of symbols already established in the JavaScript environment. (Compare: If you lein repl :connect host:port to an nREPL server that has already loaded a namespace, then ns will reflect this.)

Note: It is more appropriate to compare basic ClojureScript REPLs to what you get if you download Clojure and then do java -jar clojure-1.6.0.jar, and in that case ClojureScript is pretty much at parity with Clojure.

@borkdude
Copy link

borkdude commented Jun 8, 2015

When I go into a namespace, I can't refer to vars that have been aliased by the namespace declaration.
Example:

https://github.com/borkdude/lein2boot

Start the server: lein repl + (start-server)
Start figwheel: lein figwheel and wait until main.js is compiled
Open browser, REPL appears in figwheel

mborkent@MacBook-Pro-van-Michiel /tmp/lein2boot (master) $ lein figwheel
Figwheel: Starting server at http://localhost:3449
Focusing on build ids: dev
Compiling "out/public/main.js" from ["src-cljs" "src-cljs-dev"]...
Successfully compiled "out/public/main.js" in 10.995 seconds.
Started Figwheel autobuilder

Launching ClojureScript REPL for build: dev
Figwheel Controls:
          (stop-autobuild)                ;; stops Figwheel autobuilder
          (start-autobuild [id ...])      ;; starts autobuilder focused on optional ids
          (switch-to-build id ...)        ;; switches autobuilder to different build
          (reset-autobuild)               ;; stops, cleans, and starts autobuilder
          (build-once [id ...])           ;; builds source one time
          (clean-builds [id ..])          ;; deletes compiled cljs target files
          (fig-status)                    ;; displays current state of system
          (add-dep [org.om/om "0.8.1"]) ;; add a dependency. very experimental
  Switch REPL build focus:
          :cljs/quit                      ;; allows you to switch REPL to another build
    Docs: (doc function-name-here)
    Exit: Control+C or :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Prompt will show when figwheel connects to your application
To quit, type: :cljs/quit
cljs.user=> (ns animals.crud)

animals.crud=> (s/validate {:foo s/Str} {:foo "test"})
WARNING: No such namespace: s, could not locate s.cljs or s.cljc at line 1 <cljs repl>
WARNING: Use of undeclared Var s/validate at line 1 <cljs repl>
WARNING: No such namespace: s, could not locate s.cljs or s.cljc at line 1 <cljs repl>
WARNING: Use of undeclared Var s/Str at line 1 <cljs repl>
#<ReferenceError: s is not defined>
animals.crud=>

@mfikes
Copy link
Author

mfikes commented Jun 8, 2015

@borkdude That's no different than the behavior you get in the Clojure REPL produced by lein repl, right? What you need to do instead is require the namespace and then go into the namespace using in-ns:

Prompt will show when figwheel connects to your application
To quit, type: :cljs/quit
cljs.user=> (require 'animals.crud)
nil
cljs.user=> (in-ns 'animals.crud)
nil
animals.crud=> (s/validate {:foo s/Str} {:foo "test"})
{:foo "test"}
animals.crud=>

(Correction: @borkdude rightfully points out that for Clojure, ns works if the process has already loaded the namespace.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment