Can an embedded swank-clojure repl access the program it is embedded in?

做~自己de王妃 提交于 2019-12-04 12:56:45

let-bound locals are lexically scoped, thus swank.swank/start-repl won't be affected by a let form wrapped around the call to it. However, the running REPL will be able to require / use any Clojure namespaces on your application's classpath (or use in-ns to switch the REPL's namespace to one of those) and to import any Java classes on the classpath, allowing you to do a number of very useful things, such as redefining functions, examining and changing the contents of any Refs / Atoms / other things of interest held in Vars, calling functions / Java methods etc.

Note that you probably shouldn't (:use swank.swank) in your ns form; (:require swank.swank) instead. The difference is that the former pulls in all swank.swank's public Vars into your namespace, while the latter doesn't (use = require + refer, see (doc use) etc. for details). You seem to use namespace-qualified symbols to access Swank's Vars, so you might not even have to change the rest of your code, and require avoids cluttering up your namespace. Alternatively, (:use [swank.swank :only [start-repl]]); this pulls in just the start-repl Var, which you could then use directly, without the swank.swank/ bit.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!