现在的位置: 首页 > 综合 > 正文

SICP—-MIT-Sheme 基本使用

2019年03月02日 ⁄ 综合 ⁄ 共 4400字 ⁄ 字号 评论关闭
文章目录

整理自网络,供查阅使用.

命令行交互模式

在交互式执行方式下,系统(启动后)将在一个窗口显示版本信息,最后是提示符:

1 ]=>

键入的程序代码将显示在提示符之后。

此时系统执行 read-evaluation-print 循环(读入-求值-打印循环,REPL),可以键入符合 Scheme 语法要求的表达式(程序),要求系统对其求值。表达式中可以任意换行。一旦系统读到一个完整的表达式,就会对它求值(计算),并打印出求得的值。

Scheme 不区分标识符中的大写和小写,define 和 DEFINE,Define 同样对待。

启动后的提示符 1 ]=> 中的数字 1 表示当前系统运行在第一层“读入-求值-打印循环”。如果求值中出错,系统将进入更高层次的“读入-求值-打印循环”,也是系统的出错处理循环。在出错循环中仍然可以像在第一层循环一样使用 Scheme 系统,还可以做一些其他事情(参看 Scheme 文档)

退出一层或多层“读入-求值-打印循环”:

可以用 Ctrl-u 组合键退出一层求值循环,用 Ctrl-g 退到第一层循环。

中断执行:

  • 组合键 Ctrl-g:杀掉正在进行的求值并回到第一层 REPL
  • 组合键 Ctrl-x:杀掉正在进行的求值并回到当前 REPL
  • 组合键 Ctrl-u:杀掉正在进行的求值并回到上一层 REPL
  • 组合键 Ctrl-b:暂停当前求值进入断点 REPL。可以用 (continue) 唤醒中断的执行

Edwin模式

概述

Edwin 是 MIT Scheme 系统的一个窗口式的编辑使用前端。其功能和使用方式都像著名编辑器 EMACS,使用方面的进一步细节可以参考 EMACS。本页简单介绍 Edwin 的使用。

启动 Edwin 实际上是先启动 Scheme 系统再启动一个 Edwin 前端。Edwin 是一个用 Scheme 写的交互式编辑器。其特点是支持 Scheme 表达式的编辑和求值。

介绍 Edwin 的文档里常提到 buffer,这个概念类似于一般多窗口编辑器的编辑区。

两种不同执行模式

在 Edwin 执行时,一个编辑区(称为一个 buffer)可能处于两种不同的运行模式:

Edwin 模式
也就是编辑 Scheme 文件的模式。如果装入一个 .scm 文件,相应的 Edwin 的这个编辑区处于 Edwin 模式。在这种模式下可以编写 Scheme 程序,也可以对表达式求值。正常求出的值显示在最下面交互行,但不会显示出错信息,也不能进入调试系统
特殊的 REPL 模式
这时可以看到窗口下面状态条中显示 (REPL: lesten)。这时系统处于正常的 Scheme 交互模式,所有输出都显示在编辑器的窗口里,只不过是在 Edwin 里执行。在这种情况下可以看到所有系统输出(包括出错信息),也可以进入 debuger(是一个用 Scheme 写的交互式程序,它启动后打开另一个窗口)。
任何时候都可以用 M-x repl 回到或打开一个 REPL buffer。

启动 Edwin 后编辑器处于支持输入和求值 REPL 的模式。窗口下方黑条显示:

--**-Ediwin: *Scheme*    (REPL: Listen) ----All----

表示 Edwin 的模式,这时 Scheme 正在 REPL (Read-Evaluation-Print-Loop,读入-求值-打印循环) 中等待输入。上部大区域是交互窗口,可以在这里输入表达式并要求求值。

建议大家在编辑模式下编写程序(函数的定义,所需基本数据的定义等),检查无误后(例如,函数能正常定义了)保存,然后在 REPL 模式里装入(用 Scheme 语言的 load,见使用简介)并做各种试验和调试(输入并求值各种具体计算表达式)。

记号:

C-x,C-c 等表示按住 Ctrl 键的同时按 x 或 c 键;

M-p 等表示在按住 Meta 键的同时按 p键。在 PC 键盘上没有 Meta 键,可以直接用 Alt 键加上 p 键,或者先按 Esc 键再按 p 键。

帮助信息

在 Edwin 里按 Ctrl-h t,它会装入一个 tutorial 文件,其中讲述了各种常用命令。在 Windows 的 Scheme 程序菜单里的 Documentation 包含大量与 Scheme 有关的信息。

网上可以找到许多相关信息。下面是一些有用链接:
http://www.cnblogs.com/Henrya2/archive/2009/02/21/1395615.html
http://blog.csdn.net/msnlogo/archive/2009/04/05/4050176.aspx
http://www.blogjava.net/zhenyu/archive/2006/10/17/75657.html
http://harry.javaeye.com/blog/446418

退出系统

C-x z (表示按 Ctrl-x 后按 z 键):从 Edwin 中退到 Scheme 的命令交互状态。此时 Edwin 挂起,可用 (edit) 唤醒挂起的 Edwin,回到挂起前的状态。

C-x c :停止 Edwin 并回到 Scheme 的命令交互状态。

C-x C-z:停止 Edwin 并挂起 Scheme 系统。再次启动 Scheme 将唤醒挂起的 Scheme 系统,回到挂起前的系统状态。

C-x C-c:停止 Edwin 和 Scheme 系统。

求值 (exit) 退出 Scheme 系统。

简单编辑和执行

光标移动可以通过普通移光标键,或通过鼠标点击。用 Delete 或 Backspace 键删除字符。

在正常输入过程中,每次输入右括号 "(",环境将自动闪烁对应的左括号 ")"。

对于多行输入的表达式,换行后按 C-i,系统能将光标自动对齐到合适位置。对于各种复杂的 Scheme 表达式,例如 let, cond, 等等,Edwin 都定义了很好的对齐方式。

求值表达式的方式:将编辑光标(反色小块)移到表达式后面,按键 C-x C-e 。

被求值的表达式将由另一个线程求值,在求值过程中我们仍然可以做编辑工作。

C-c C-x 或 C-c C-u,用于杀掉正在进行的求值。

C-c C-b 中断当前求值,进入断点状态。

翻页等命令:

C-v:向下翻一屏   M-v:向上翻一屏
C-a:移动到行首   C-e:移动到行尾

两个常用操作

在 REPL 模式下,所有输入的历史都有记录。这使我们可以很方便地再次使用曾经输入过的表达式。 M-p 反向枚举曾经输入的表达式,M-n 正向枚举这些表达式。

这里列出了 Edwin 的常用命令(英文)

这里列出了 EMACS 的一些常用命令(中文,在 Edwin 里都可用)

调试

如果正在进行的求值出错,系统将给出一些错误信息,并询问是否启动调试器(debuger)。回答 y 要求系统启动调试器,显示出一个新的调试器窗口;回答 n 回到原求值循环。

(这部分内容将进一步建设)

编辑技术

其他

Edwin 前端是一个功能强大的编辑器,允许用 Scheme 对其功能进行任意的扩充。这方面情况与 EMACS 类似,只是这里用的扩充语言是 MIT Scheme(EMACS 用的是 EMACS Lisp)。请参考 MIT Scheme 文档和 EMACS 文档。

常用命

how to use the Edwin

1, if there is no META or EDIT key, Alt is that key.

2, to end the session, C-x C-c.

3, C-v, to the next screen

4, C-g will quit what it was doing and allow you to enter it in again from scratch.

5, C-k kill from the current cursor position to end of line

6, whenever you kill something bigger than a character, Emacs saves it for you. to yank it back, use C-y.

7, C-x C-e to evaluate the expression.

8, you are now in the tutorial screem.
  Type: C-x b *scheme* to get into an evaluation buffer.
  Type: M(Alt)-p to access the history of *scheme*.
  Type: C-x b tutorial to go back to the tutorial screem.
 
9, undo: C-x u, it undo the last command.

10, File: C-x C-f filename  -->  enter into the "finding buffer" to find a file.
                                if the file exits, it find the file, if not
                                exits,create a file named filename.       
         C-x C-f C-g  --> cancel the "finding buffer" without doing anything.
         C-x C-s   -->  Save the file.
 
11, buffer:  C-x C-b:  if you find a new file with C-x C-f in the             
            Edwin,the first file remains in the Edwin,Type C-x C-b
            to find them (it shows a list of all the buffers now in
            the Edwin). Any text you see in the Edwin, has to be
            in some buffer.   if you have edited a file or something
            and go to another file without saving the first one, the
            changes would not save, unless you reback to the first
            file, and C-x C-s. There is a way to save all the changed
            file, that is C-x s. the command goes through the list
            of buffers, and saves every changed buffer.

12, C-x 1   remove the document from the screem.

13, C-s     find a word or string, type C-s,and then, type in the word,
            once, you would find the
            word, again, you will find the next occurrece of the
            word you have typed in. type in C-g, you will go back to the
            first place where you press "C-s".
14, C-x 1   display only one window.

15, C-h ?   tell you what kinds of help you can get.

16, C-h c + command: tell you the basic intro to the command.
                     to get more information, use C-h k + command.
                     to get info of a function, use C-h f + function

抱歉!评论已关闭.