如何在leiningen repl中预加载clojure文件? [英] How does one pre-load a clojure file in the leiningen repl?

查看:396
本文介绍了如何在leiningen repl中预加载clojure文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些clojure函数,我想在启动Clojure REPL时预先加载。

I have some clojure functions that I would like pre-loaded when I start the clojure REPL. The functions aren't much use unless you are using them within the context of a REPL.

如果它有帮助,我通常使用leiningen为我开始一个clojure REPL。

If it helps, I generally use leiningen to start a clojure REPL for me.

如何告诉clojure(或leiningen,如果它不能通过平面clojure)预加载clojure文件包含这些定义为我?

How can I tell clojure (or leiningen, if it's not available through flat clojure) to pre-load a clojure file containing these definitions for me?

推荐答案

有几种方法可以在 leiningen示例项目
我最喜欢的方法之一就是把你想要的代码在默认的repl命名空间中

There are several ways to do this described in the leiningen sample project one of my favorite methods is so put the code you want in the default repl namespace into

/path/to/project/dev/user.clj:

/path/to/project/dev/user.clj:

(ns user)
(def foo 42)

并在project.clj文件中添加一行:

and add a line like this into the project.clj file:

(defproject hello "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]]
  :source-paths ["dev"])

这清楚地表明这是为dev,同时仍然将其加载到默认命名空间。

This makes it clear that this is for dev while still getting it loaded into the default namespace.

当您运行 nrepl-jack-in 形式emacs或lein repl时,在您的代码加载时用 user> 命名空间欢迎:

When you run nrepl-jack-in form emacs or "lein repl" form the shell, you should be greeted with a user> namespace with your code loaded:

; nREPL 0.1.6
user> foo
42

这篇关于如何在leiningen repl中预加载clojure文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆