Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax of require in the ClojureScript REPL

This is certainly trivial, but I could not find it anywhere. I am trying to start fiddling with ClojureScript. I was able to get to a ClojureScript REPL with ClojureScript One.

I can connect with a browser and execute some simple DOM queries and manipulations there. Now I would like to start saving some useful functions into modules and load them as needed. This is where I get stuck.

If I try something like

(require 'project.dom)

I get the exception FileNotFoundException Could not locate project/dom__init.class or project/dom.clj on classpath. I indeed have only project/dom.cljs, as I saw all ClojureScript files in the example use this extension.

If I try to rename it to project.clj, I get a complaint about the missing namespace js. Of course I use that namespace quite a lot in the module.

What is the proper way to write a simple ClojureScript file that can work with the browser, and load it from the REPL? Anything that will make able to run this simple example will do:

(ns ^{:doc "A module for selecting elements from the DOM."}
  project.dom)

(defn get
  [selector]
  (.querySelectorAll js/document selector))
like image 923
Andrea Avatar asked Mar 23 '12 21:03

Andrea


People also ask

What is ClojureScript REPL?

ClojureScript Built-in REPLs. ClojureScript is a variant of the Clojure language, which compiles (or "transpiles") to JavaScript code. That way you can write Clojure code, but run it anywhere JavaScript is available.

How do I start ClojureScript project?

run lein new ... or get a project set up any way you like (an essential setup is just a project. clj and a source file) cd into project; run npm init and set up the npm part. run npm install -D shadow-cljs react react-dom and leave npm land.


1 Answers

It turns out that

(load-namespace 'project.dom)

works, but require is not implemented yet

like image 67
Andrea Avatar answered Sep 29 '22 19:09

Andrea