Re: how to launch repl and switch to specific namespace programmatically

413 views
Skip to first unread message

stone

unread,
Dec 13, 2012, 1:11:46 PM12/13/12
to clo...@googlegroups.com

seems that the repl start up namespace is hard coded in RT:

https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L437

static void doInit() throws ClassNotFoundException, IOException{
load("clojure/core");

Var.pushThreadBindings(
RT.mapUniqueKeys(CURRENT_NS, CURRENT_NS.deref(),
WARN_ON_REFLECTION, WARN_ON_REFLECTION.deref()
,RT.UNCHECKED_MATH, RT.UNCHECKED_MATH.deref()));
try {
Symbol USER = Symbol.intern("user");
Symbol CLOJURE = Symbol.intern("clojure.core");

Var in_ns = var("clojure.core", "in-ns");
Var refer = var("clojure.core", "refer");
in_ns.invoke(USER);
refer.invoke(CLOJURE);
maybeLoadResourceScript("user.clj");
}
finally {
Var.popThreadBindings();
}
}



On Friday, December 14, 2012 1:25:44 AM UTC+8, stone wrote:
I tried the following way:

java -Xmx1G -cp $CLASSPATH clojure.main -i src/my-repl/repl.clj -r

where src/repl/repl.clj is :







(ns my-repl.repl)

(def my-var "hi") 
(in-ns 'my-repl.repl)

but after clojure repl launched, I am always in the default user namespace not 'my-repl.repl'.
How to achieve this so I can use my-var directly after repl launching ?

Thanks,
Stone
 

juan.facorro

unread,
Dec 13, 2012, 1:15:36 PM12/13/12
to clo...@googlegroups.com
The following code will start a repl in the my-repl.repl namespace:

(ns my-repl.repl
(:require [clojure.main]))

(def my-var "hi")
(clojure.main/repl)

So you'll be able to acces the vars defined in it.

my-repl.repl=> my-var
"hi"

Cheers,

Juan

juan.facorro

unread,
Dec 13, 2012, 1:19:21 PM12/13/12
to clo...@googlegroups.com
I forgot to add the modified command line for this to work as described:

$ java -Xmx1G -cp $CLASSPATH clojure.main src/my-repl/repl.clj

Juan

Stone

unread,
Dec 13, 2012, 9:59:11 PM12/13/12
to clo...@googlegroups.com
cool. it works great. Thanks!


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply all
Reply to author
Forward
0 new messages