英文:
Why do I need to evaluate defpackage for a new REPL?
问题
I use ADSF to organise my projects.
(asdf:defsystem :sender
:version "0.1.4"
:serial t
:depends-on (:cl-json :dexador :clsql :clsql-sqlite3)
:components ((:file "packages")
(:file "validation")
(:file "sender")))
But when I open a new repl (slime, emacs), I have to go to the packages.lisp file and evaluate the form before I can change the repl to that package with (in-package :sender)
.
Is there a way to make the slime repl remember my packages?
My current thinking is that I need to "run" adsf to load all my files. If so, how?
UPDATE:
Actually, I need to compile all the files manually before I can actively use them in the repl. I believe I am using asdf incorrectly.
英文:
I use ADSF to organise my projects.
(asdf:defsystem :sender
:version "0.1.4"
:serial t
:depends-on (:cl-json :dexador :clsql :clsql-sqlite3)
:components ((:file "packages")
(:file "validation")
(:file "sender")))
But when I open a new repl (slime, emacs), I have to go to the packages.lisp file and evaluate the form before I can change the repl to that package with (in-package :sender)
.
Is there a way to make the slime repl remember my packages?
My current thinking is that I need to "run" adsf to load all my files. If so, how?
UPDATE:
Actually, I need to compile all the files manually before I can actively use them in the repl. I believe I am using asdf incorrectly.
答案1
得分: 2
从一个.asd系统定义中,步骤如下:
- 编译.asd文件,以便你的Lisp图像知道该系统
C-c C-k
或以编程方式:(asdf:load-asd "system")
。
- 以某种方式LOAD它:
(ql:quickload "system")
以安装依赖项- 或者
(asdf:load-system "system")
,但如果你的项目有未知的依赖项,它将失败,Quicklisp会下载它们。 - 避免在asdf系统中使用
cl:load
,load-asd / load-system会执行更复杂的操作。
- 或者
- 在REPL上使用它。在packages.lisp文件中定义的包应该可用,因为这个文件在.asd文件中声明过。
你可以将内容添加到你的~/.sbclrc
(或者对于其他实现类似的文件)。在这里,我告诉ASDF项目位于哪里,所以我可以在手动编译.asd之前使用quickload
加载它:
(pushnew "/home/vince/projets/ciel/" asdf:*central-registry* :test #'equal)
这是一种不再被ASDF文档鼓励的“旧”方式。
或者简单地为你的项目创建一个符号链接到~/quicklisp/local-projects/
或~/common-lisp/
。
我不会在初始化文件中使用"load-system"加载我的项目,因为那是一个副作用,有时会在我不想要的时候出现(比如构建一个图像:如果这涉及读取我的初始化文件,那么它会在其中包含一个不需要的系统)。
保存一个具有大量依赖项的核心图像很酷。可以使用sbcl --core …
来使用它。优点是当加载所有项目和依赖项需要几秒钟时,它会在REPL中立即启动。
英文:
From a .asd system definition, the steps would be:
- compile the .asd file, so that you Lisp image knows about the system
C-c C-k
or programmatically:(asdf:load-asd "system")
.
- LOAD it somehow:
(ql:quickload "system")
to install dependencies- or
(asdf:load-system "system")
, but it will fail if your project has unknown dependencies, Quicklisp would download them. - avoid using
cl:load
for asdf systems, load-asd / load-system will do more complex stuff.
- or
- use it on the REPL. The package that was defined in a packages.lisp file should be available, because this file was declared in the .asd.
You can add stuff to your ~/.sbclrc
(or similar for other implementations). Here I tell ASDF where a project lives, so I can quickload
it without manually compiling the .asd before:
(pushnew "/home/vince/projets/ciel/" asdf:*central-registry* :test #'equal)
This is an "old" style not encouraged anymore by the ASDF documentation.
Or simply create a symlink for your project to ~/quicklisp/local-projects/
or ~/common-lisp/
.
I wouldn't "load-system" my project in the init file, because that's a side effect that would show sometimes when I don't want it (like building an image: if that involves reading my init file, I'd have an unwanted system in it).
Saving a core image with a ton of dependencies is cool. Use it with sbcl --core …
. The advantage is that it starts up instantly in the REPL, when loading all projects and dependencies would take a few seconds.
答案2
得分: 1
指针
概述
一个 系统 是一个描述一个 库(或 应用程序)的对象,包括:名称、版本、文件 和 子系统 的列表,以及它所依赖的其他系统的列表。还有更多。
如果你想让Lisp知道某个系统,那么我们需要手动执行它的defsystem表单,或者自动找到它。这只会使系统定义被识别。
如果你想加载系统的文件,那么你需要加载该系统。如果你想编译系统的文件,那么你需要编译该系统。
因此,如果你想使用一个包(它是一个 命名空间 ),那么你需要运行DEFPACKAGE表单。如果该表单在一个系统的组成部分中描述,那么你需要加载该系统。
-
ASDF :Common Lisp的流行构建系统
-
系统 -> 库,应用程序。它是一组文件和依赖项。
-
系统定义 -> 不是系统本身,而是对它的描述。使用DEFSYSTEM来描述一个系统。
-
系统操作 -> 像load-system,compile-system和其他操作。
-
系统注册表 -> 通常我们希望ASDF通过名称来查找系统。请参阅ASDF的手册或教程。
-
Lisp文件 -> 一些可以编译或加载的文件
-
fasl文件 -> 一些已编译的文件,可以加载
-
包 -> 符号的命名空间,这实际上是Common Lisp的内置功能
-
Quicklisp -> 带有精选的Common Lisp库/应用程序的库管理器。这些库可以通过互联网加载。请注意,从互联网加载外部代码时几乎没有安全性。
使用系统、其组件和依赖项
如果你想使用一个系统,首先需要加载它。可以手动或自动加载。
这种加载可以自动完成:
-
例如,在Lisp的初始化文件中,你可以加载所有你想要/需要的系统。或者编写一个加载所有所需系统的函数。
-
保存一个镜像。一些Lisp支持保存镜像。因此,可以加载所有有趣的系统,然后保存一个镜像。如果稍后启动该镜像,所有这些系统已经在内存中。(副问题:加载更新版本)
英文:
Pointers
Overview
A system is an object which describes a library (or an application) which consists of: a name, a version, a list of files and subsystems, and a list of other systems it depends on. There is more.
If you want to have Lisp know a certain system, then we need to execute its defsystem form either manually or find it automatically. That ONLY makes the system definition known.
If you want to load the system's files, then you need to LOAD the SYSTEM. If you want to compile the system's files files, the you need to COMPILE the system.
So, if you want to use a package (which is a namespace), then you need to run the DEFPACKAGE form. If that form is describe in a file which is component of a system, then you need to load that system.
-
ASDF : a popular build system for Common Lisp
-
system -> library, application. It is a bunch of files and dependencies.
-
system definition -> not the system itself, but a description of it. Use DEFSYSTEM to describe a system
-
system operations -> like load-system, compile-system and others.
-
system registry -> Typically we want ASDF to find the systems by name. See the manual or a tutorial for ASDF.
-
lisp file -> some file we can compile or load
-
fasl file -> some compiled file we can load
-
package -> a namespace for symbols, that's actually a built-in feature for Common Lisp
-
Quicklisp -> a library manager with a selection of curated Common Lisp libraries/applications. The libraries can be loaded over the Internet. Be aware that there is little to no security when loading foreign code from the Internet.
Use a system, its components and dependencies
If you want to use a system you need to load it first. Manually or automatically.
That loading can be done automatically:
-
For example in an init-file for your Lisp you can load all systems you want/need. Alternative write a function which loads all systems you want.
-
saving an image. Some Lisps support saving an image. Thus one can load all interesting systems and then save an image. If one starts that image later, all those systems are already in memory. (side problem: getting newer versions loaded)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论