Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot "use" in clojurescript repl

I type the following at the Clojurescript namespace.

cljs.user> (use '[clojure.zip :only [insert-child]])

WARNING: Use of undeclared Var cljs.user/use at line 1 
"Error evaluating:" (use (quote [clojure.zip :only [insert-child]])) :as "cljs.user.use.call(null,cljs.core.vec([\"\\uFDD1'clojure.zip\",\"\\uFDD0'only\",cljs.core.vec([\"\\uFDD1'insert-child\"])]));\n"
#<TypeError: Cannot call method 'call' of undefined>
TypeError: Cannot call method 'call' of undefined
    at eval (eval at <anonymous> (http://localhost:3000/main.js:32728:147), <anonymous>:1:85)
    at eval (eval at <anonymous> (http://localhost:3000/main.js:32728:147), <anonymous>:6:3)
    at http://localhost:3000/main.js:32728:142
    at evaluate_javascript (http://localhost:3000/main.js:32741:4)
    at Object.callback (http://localhost:3000/main.js:32806:138)
    at goog.messaging.AbstractChannel.deliver (http://localhost:3000/main.js:31059:13)
    at goog.net.xpc.CrossPageChannel.deliver_ (http://localhost:3000/main.js:32164:14)
    at Function.goog.net.xpc.NativeMessagingTransport.messageReceived_ (http://localhost:3000/main.js:31732:13)
    at goog.events.Listener.handleEvent (http://localhost:3000/main.js:22590:26)
    at Object.goog.events.fireListener (http://localhost:3000/main.js:22924:21)
nil

It seems to be stating that the 'use' method does not exist in the cljs.user namespace. This kind of makes sense to me, as Clojurescript itself cannot evaluate Clojure expressions. However, I know that Clojurescript has a clojure.zip namespace, I have used clojure.zip in the namespace declaration as (:use [clojure.zip :only [insert-child]]).

How do I use the Clojurescript version of clojure.zip in the Clojurescript repl?

like image 660
Stephen Cagle Avatar asked Oct 14 '12 03:10

Stephen Cagle


People also ask

What is Clojure REPL?

What is a REPL? A Clojure REPL (standing for Read-Eval-Print Loop) is a programming environment which enables the programmer to interact with a running Clojure program and modify it, by evaluating one code expression at a time.


1 Answers

Because ClojureScript namespaces are implemented completely differently than Clojure, ClojureScript does not support the use or require forms directly.

Instead, you must use the ns macro. To use clojure.zip in the cljs.user namespace, then, just do the following:

(ns cljs.user (:use [clojure.zip :only [insert-child]]))

Note that the forms supported in the ClojureScript version of ns are a subset of those supported in Clojure; specifically, :use clauses must specify an :only form, and the :require clause must specify an :as form.

like image 75
levand Avatar answered Oct 12 '22 23:10

levand