为有抱负的Lisp新手设置一个工作的Common Lisp环境 [英] Setting up a working Common Lisp environment for the aspiring Lisp newbie

查看:119
本文介绍了为有抱负的Lisp新手设置一个工作的Common Lisp环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直是UNIX系统管理员很长一段时间,除了通过shell脚本自动执行任务,还有一些轻巧的PHP工作以及一些简单的C程序,我从来没有做过太多的编程方式。我最近决定放宽我的想法,学习Common Lisp。



我已经到了Touretzky的温柔介绍的中途,刚刚到达了我的一章/ O,我想在阅读本书和练习之后,将打字输入到REPL中。问题是,我找不到一个体面的howto /教程获得一个体面的工作环境。



我已经安装了emacs(本身是一个艰难的变化,因为我使用vi近20年),SLIME和几个CL实现。然而,这些作品中的任何一个的文件是巨大的,永远不会试图穿过这三个。我已经撇去了几本免费的在线CL书籍,所有这些书籍都与环境无关,假设您将输入内容到REPL或加载源文件。



它如果我可以找到一个体面的介绍来为Common Lisp设置一个Emacs环境,让我在一个窗口中以Lisp模式编辑(功能和变量自动完成在这里真的很好),那么真的会让这个体验更加愉快,参见评估单个表达式(输出和返回值)在另一个中的结果,以及能够告诉整个缓冲区进行评估和运行,而我在某处看到结果。



任何和所有指针将不胜感激。



编辑:我的平台是FreeBSD / amd64,我更喜欢开源解决方案。 b $ b

解决方案

我们假设你有emacs运行,并从
CVS检出SLIME并安装它。任何Linux发行版都应该很容易 apt-get install emacs slime 为我做。 (您还应该安装SBCL,最好的Common Lisp实现。)



开箱即用的SLIME不会太多,所以需要
配置。配置emacs在你的〜/ .emacs 文件中完成。
访问该文件( C-x C-f〜/ .emacs)。我有这样的东西,
加载各种各样的东西:

 (eval-after-loadslime 
'(progn
(setq slime-lisp-implementation
'((sbcl(/ usr / bin / sbcl))
(ecl(/ usr / bin / ecl))
(clisp(/ usr / bin / clisp))))
(slime-setup'(
slime-asdf
slime-autodoc
slime-editing-commands
slime-fancy-inspector
slime-fontifying-fu
slime-fuzzy
slime-indentation
slime-mdot-fu
slime-package-fu
slime-references
slime-repl
slime-sbcl-exts
slime-scratch
slime-xref-browser
) )
(slime-autodoc-mode)
(setq slime-c omplete-symbol * -fancy t)
(setq slime-complete-symbol-function
'slime-fuzzy-complete-symbol))

(require'slime)

如果您的网站目录中没有安装SLIME,您将
还要在这些行之前添加:

 (add-to-list'load-path〜/ elisp / slime / )
(add-to-list'load-path〜/ elisp / slime / contrib)

(当然,将这些路径更改到正确的位置。)



关键部分是slime-setup,它加载了各种可选的
模块,包括REPL。 (我也考虑到花式缩进,
和autodoc必需)。



无论如何,您可以将其加载到运行的emacs中,使用 Mx
eval-buffer
,或者将点放在每个sexp中,然后按
CMx 。 (您也可以指向sexp的结尾,然后按 Cx
Ce
。有几种方法来评估Emacs中的Emacs Lisp,
但是这不是学习CL的真正关系。)



在这一点上,您应该可以键入 Mx slime 并被带到
你的REPL。在此之前,您的lisp将被加载,SLIME将
告诉它编译Swank(SLIME的CL端),您将看到
发生。这只会发生一次,但是,下一次SLIME将会更快地启动



在REPL中,您可以键入Common Lisp命令并查看
他们的评价。按TAB完成任务将会出现一个
的可能的完成窗口;这是智能完成,所以键入
像d-b这样的东西将会出现一个包含
destructuring-bind的列表。很有帮助。 M- /还将完成您已经在Emacs内部键入的符号
;另一个伟大的时间
保护。 (这在Emacs,BTW,无处不在,被称为动态
缩写扩展。)



早些时候,你说REPL很无聊,所以让我们打开一个真实文件
C-x C-f test.lisp 。毫不奇怪,这将打开一个
缓冲区编辑test.lisp,当您首次保存
文件( C-x C-s )时将创建。这个Lisp文件知道SLIME,所以你输入的任何
可以很容易地被运行的Lisp验证。选项卡完成,
类检查,交互式测试等都可用。



作为示例,键入类似于(+ 1 2),然后按 Cx Ce 。 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $这可以让您在将
键入文件时,测试单个表达式。



下一步是编写一个完整的函数,也许是:

 (defun my-1 +(x)
(+ x 1))
/ pre>

您可以通过多种方式将此函数加载到运行的Lisp中;
我通常使用 C-M-x 。您现在可以更改回REPL缓冲区
Cx b * slime-repl sbcl * 或类似),并键入(my-1 + 42)并查看
结果 43 打印。



另一个将函数导入运行的Lisp的方法是编译
并使用 Cc Ck 加载整个文件。



无论如何,这是使用SLIME和Emacs的基础。有
显然有更多的功能可用,但这应该给你
一个Lisp编程与SLIME的味道。最后一件事我会提到,
Emacs主要是自我记录的,所以如果你想了解更多,Emacs
可以帮助你。在您的Lisp缓冲区中,您可以键入 C-h m 以获取
一个完整的命令列表,您可以在编辑Lisp时使用。您可以点击
链接以获取有关每个功能的更多信息。



玩得开心!


I've been a UNIX sysadmin for a long time, and aside from automating tasks with shell scripting, some light PHP work, and a few simple C programs, I've never done much in the way of programming. I recently decided to stretch my mind a bit and learn Common Lisp.

I'm half-way through Touretzky's "Gentle Intro" and, having just reached the chapter on I/O, I'm wanting to get beyond typing stuff into the REPL as I walk through the book and the exercises. The problem is that I can't find a decent howto/tutorial on getting a decent, working environment.

I've installed emacs (which in itself is a tough change, as I've used vi for almost 20 years), SLIME, and several CL implementations. However, the documentation for any one of these pieces is enormous, nevermind trying to wade through all three. I have skimmed several free online CL books and all of them are agnostic to the environment, assuming that you'll be typing stuff into the REPL or loading source files.

It would really make this experience much more enjoyable if I could find a decent intro to setting up an Emacs environment for Common Lisp that allows me to edit in Lisp mode in one window (function and variable auto-completion would be really nice here), see the results of evaluating single expressions (both output and return value) in another, as well as be able to tell the whole buffer to be evaluated and "run" while I see the results somewhere.

Any and all pointers would be greatly appreciated.

EDIT: My platform is FreeBSD/amd64, and I prefer open source solutions.

解决方案

Let's assume you have emacs running and have checked out SLIME from CVS and installed it. This should be easy with any Linux distro; apt-get install emacs slime does it for me. (You should also install SBCL, the best Common Lisp implementation.)

SLIME out of the box doesn't do much anymore, so it needs configuration. Configuring emacs is done in your ~/.emacs file. Visit that file (C-x C-f ~/.emacs). I have something like this, which loads a variety of goodies:

(eval-after-load "slime"
  '(progn
     (setq slime-lisp-implementations
           '((sbcl ("/usr/bin/sbcl"))
             (ecl ("/usr/bin/ecl"))
             (clisp ("/usr/bin/clisp"))))
     (slime-setup '(
                    slime-asdf
                    slime-autodoc
                    slime-editing-commands
                    slime-fancy-inspector
                    slime-fontifying-fu
                    slime-fuzzy
                    slime-indentation
                    slime-mdot-fu
                    slime-package-fu
                    slime-references
                    slime-repl
                    slime-sbcl-exts
                    slime-scratch
                    slime-xref-browser
                    ))
     (slime-autodoc-mode)
     (setq slime-complete-symbol*-fancy t)
     (setq slime-complete-symbol-function
  'slime-fuzzy-complete-symbol)))

(require 'slime)

If you don't have SLIME installed in your "site directory", you'll also want to add this before those lines:

(add-to-list 'load-path "~/elisp/slime/")
(add-to-list 'load-path "~/elisp/slime/contrib")

(Change the these paths to the correct location, of course.)

The key part is the slime-setup, this loads a variety of optional modules, including the REPL. (I also consider the fancy indentation, and autodoc essential.)

Anyway, you can load this into your running emacs with M-x eval-buffer, or by putting the point inside each sexp and pressing C-M-x. (You can also point to the end of the sexp and press C-x C-e. There are a variety of ways to evaluate Emacs Lisp in Emacs, but that is not really relevant to learning CL.)

At this point, you should be able to type M-x slime and be taken to your REPL. Before that happens, your lisp will be loaded, SLIME will tell it to compile Swank (the CL side of SLIME), and you will see that happen. This only happens once, though, next time SLIME will start up faster.

At the REPL, you can type Common Lisp commands and see the result of their evaluation. Pressing TAB to complete something will bring up a window of possible completions; this is smart completion, so typing something like "d-b" will bring up a list containing "destructuring-bind". Very helpful. M-/ will also complete symbols that you have already typed somewhere inside Emacs; another great time saver. (This works everywhere in Emacs, BTW, and is called "dynamic abbreviation expansion".)

Earlier you said the REPL was boring, so let's open a real file. Press C-x C-f test.lisp. Not surprisingly, this will open up a buffer editing test.lisp, which will be created when you first save the file (C-x C-s). This Lisp file is aware of SLIME, so anything you type can easily be validated by the running Lisp. Tab completion, class inspection, interactive testing, etc. are all available.

As an example, type something like (+ 1 2) and press C-x C-e. You will see the result, as evaluated by the running Lisp, at the bottom of the window. This lets you test individual expressions as you type them into the file.

The next step is to write a full function, perhaps:

(defun my-1+ (x)
    (+ x 1))

You can load this function into the running Lisp in a variety of ways; I usually use C-M-x. You can now change back to the REPL buffer (C-x b *slime-repl sbcl* or similar) and type (my-1+ 42) and see the result 43 printed.

Another way to bring the functions into the running Lisp is to compile and load the whole file with C-c C-k.

Anyway, that's the basics of using SLIME and Emacs. There are obviously many more features available, but this should give you a taste of Lisp programming with SLIME. One last thing I'll mention, Emacs is largely self-documenting, so if you want to learn more, Emacs can help you. While in your Lisp buffer, you can type C-h m to get a full list of commands you can use while editing Lisp. You can click the links to get more information about each function.

Have fun!

这篇关于为有抱负的Lisp新手设置一个工作的Common Lisp环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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