I am reading the book sicp recently , and the code in the book is scheme
implemented using. When I read it before, I used Dr.Racket
it to complete the writing exercise, but I think it is better to do it in one step and use the emacs+lisp
interpreter to do it faster.
install emacs
Just click on the official tutorial and click me to view it. The above explanation is very clear. Basically, the installation methods of different systems are similar. After downloading, click to run, it is still very simple.
Install the lisp interpreter
There are countless versions of lisp. I use it here Racket
, because I have it on my computer before, Dr.Racket
so I don't need to download it. If you don't have it, you can click the Racket download address and select the version of the appropriate system to download. Of course, you can also choose other The implementation version of the lisp dialect, such as the Petite Chez Scheme download address . After downloading, unzip it.
After downloading, you can get some programs like this
Then set the folder path where the above interpreter is located to the system path (windows=environment variable, mac/linux= $path
), and then click on the terminal racket --version
to check whether the setting is successful. If the following message appears, you are successful.
Install some necessary and effective plugins
We need to install a few simple plugins to help us write and run code efficiently.
Set plugin source
Similar to linux installation software, here we set MELPA
the installation source, so that we can install the code with one click, which is very convenient.
In view of the slow speed of foreign access, we use domestic mirror sources here, and we would like to thank those who have been maintaining free software, otherwise the setting and configuration of these tools would be so easy and convenient :)
emacs
All the configuration in ~/.emacs
this file is in this file. For Windows, it is in the personal directory folder of the C drive. We can make some custom configurations for emacs by editing this file. Open the .emacs file and add the following configuration to the end of the file to set up our plugin installation source.
;; melpa 安装源
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://elpa.emacs-china.org/melpa/")
t)
(package-initialize)
This makes it easy to install plugins.
Install Racket-mode
Racket-mode
It's very easy to use, execute the code, highlight, prompt, anyway, I think everything is OK, so I'll install it below.
Use the following command M-x package-install <ret> racket-mode
, M represents alt
the meaning of the key combination, which ret
represents the carriage return, so the command is actually
alt+x
Open command mode- Enter
package-install
(you can use the space bar/tab to prompt), press Enter - Then enter the name of the plugin to be installed
racket-mode
, press Enter to confirm, and wait for the installation to complete.
Well, it's simple.
After the installation is complete, .emacs
add the configuration of the following code to the configuration file configuration file
;;racket配置,设置解释器,自动补全,代码执行等
(require 'racket-mode)
(setq racket-racket-program "racket")
(setq racket-raco-program "raco")
(add-hook 'racket-mode-hook
(lambda ()
(define-key racket-mode-map (kbd "C-x C-j") 'racket-run)))
(setq tab-always-indent 'complete)
Install ParEdit
ParEdit
It is a plugin that allows you to edit lisp semi-structured, such as automatic completion of parentheses, transfer of s-expressions, extraction, etc. It is still very convenient.
You can also use M-x package-install <ret> paredit-mode
to install.
The specific usage method is not the focus of this article, you can refer to the following articles
Hello World
After all settings are completed, we create a new file ( ctrl+x 回车 i 回车 输入文件名
) and enter the following code
#! /usr/bin/env racket
#lang racket
(displayln "Hello World!")
Then use to F5
execute the S-expression, and successfully print out Hello World
At this point, the installation Emacs
and setting racket
of the environment are completed.