【文章标题】:Schemy Lisp En DOS

【文章正文】: Schemy LISP en DOS About SLED (Schemy Lisp en DOS) is a purely symbolic LISP (LISt Processor) with functionality (largely) inspired by Scheme. Originally derived from the fantastic Kilo LISP, but reduced by some features (such as macros), and enhanced with others, SLED can be classified as an Ur-Lisp and runs on a DOS (Disk Operating System) such as FreeDOS or MS-DOS, as well as on DOS-emulators like DOSBox, DOSBox-X, or DOSBox-Staging. For an overview of provided symbols, special forms, builtin functions, and standard library see the index. Get SLED: Overall, SLED is a LISP for DOS. SLED(Schemy Lisp en DOS)是一个纯粹符号化的LISP(列表处理器),其功能(主要)受Scheme启发。最初源自出色的Kilo LISP,但削减了部分特性(如宏)并增强了其他功能,SLED可归类为原始Lisp,可运行于FreeDOS或MS-DOS等磁盘操作系统,也支持DOSBox、DOSBox-X或DOSBox-Staging等模拟器。查看索引可了解提供的符号、特殊形式、内置函数和标准库概况。获取SLED: 总体而言,SLED是专为DOS设计的LISP。

Data There are two fundamental data types: Pairs and Atoms (not-pairs). Atoms come in three variants: Symbols, Closures (functions), and some Special Symbols. 数据 包含两种基本数据类型:点对(Pairs)和原子(Atoms,非点对)。原子有三种变体:符号(Symbols)、闭包(Closures,即函数)和特殊符号(Special Symbols)。

Symbols Symbols are unique names and consist of any combination of maximum 16 of the following characters: a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0 - . ? _

where . cannot be the leading character.

Additionally, any printable ASCII character can be part of a symbol when prefixed with the escape character \ (backslash), with the exception of (, ), ’, and $.

This\ is\ a\ sym! Furthermore, uppercase letters are accepted but converted to lowercase unless the character is escaped. 符号 符号是唯一名称,由最多16个下列字符组成: a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0 - . ? _ 其中.不能作为首字符。 此外,任何可打印ASCII字符在添加转义字符\(反斜杠)前缀后均可成为符号组成部分,但排除(、)、‘和$。 例如:This\ is\ a\ sym! 另需注意:大写字母会被接受但转为小写,除非该字符被转义。

Special Symbols There are some predefined special symbols managed by SLED, for example nil which means “empty list”. See the index for details. 特殊符号 SLED管理着若干预定义特殊符号,例如表示”空列表”的nil。详见索引。

Quote A quote means “do not evaluate”. Via the quote special form a symbol is registered:

(quote sym)

For convenience the ’ short form syntax may be used:

‘sym Essentially quoting declares something as data instead of code. 引用 引号表示”不执行求值”。通过quote特殊形式可注册符号: (quote sym) 为方便起见,可使用’简写语法: ‘sym 本质上,引用将内容声明为数据而非代码。

Pairs Pairs consist of a head and a tail, each holding either an atom or another pair. A pair can be created as data using the . (dot):

‘(a . x)

or as result of the cons builtin function:

(cons ‘a ‘x) Pair elements (head and tail) are immutable. 点对 点对由头部(head)和尾部(tail)组成,每个部分可包含原子或另一个点对。可通过.(点号)创建点对数据: ‘(a . x) 或通过cons内置函数生成: (cons ‘a ‘x) 点对元素(头尾)不可变。

Lists A list is a sequence of pairs where each tail points to a distinct other pair except one (the last) whose tail is the nil value, which is equivalent to (). Here are some lists:

nil ’() ‘(a . nil) ‘(a . (b . nil)) A list can be created as data also by: ‘(a b)

or as result of the (standard library) list function:

(list ‘a ‘b) 列表 列表是点对序列,其中每个尾部指向另一个不同点对,除了最后一个点对的尾部为nil值(等价于())。示例如下: nil ’() ‘(a . nil) ‘(a . (b . nil)) 也可通过以下方式创建列表数据: ‘(a b) 或通过(标准库)list函数生成: (list ‘a ‘b)

Improper List An improper list does not terminate by nil, for example:

(a . (b . (c . d))) 非规范列表 非规范列表不以nil结尾,例如: (a . (b . (c . d)))

Association List An association list is a list where each element is a pair (association): ((a . x) (b . y) (c . z)) The head part of such a pair element is called key and the tail is called value. 关联列表 关联列表是每个元素均为点对(关联)的列表: ((a . x) (b . y) (c . z)) 此类点对的头部称为键(key),尾部称为值(value)。

S-Expressions A symbolic expression (S-expression) is a data structure defined as: An S-expression is either an atom or a pair of S-expressions. In Lisp, Scheme, and in particular in SLED, S-expressions are used for data as well as source code. S表达式 符号表达式(S-expression)定义为:一个S表达式可以是原子或S表达式点对。在Lisp、Scheme特别是SLED中,S表达式既用于数据也表示源代码。

Numbers The SLED system does not feature numeric types. Yet natural numbers (non-negative integers) can be emulated using lists: ’() ; zero ‘(nil) ; one ‘(nil nil) ; two ‘(nil nil nil) ; three

These are tally numerals, so cardinality represents the magnitude, which is similar to von Neumann ordinals. The functions inc, dec, and zero? facilitate with counting tasks. 数字 SLED系统不支持数值类型。但可通过列表模拟自然数(非负整数): ’() ; 零 ‘(nil) ; 一 ‘(nil nil) ; 二 ‘(nil nil nil) ; 三 此为计数数字,基数表示量级,类似冯·诺伊曼序数。inc、dec和zero?函数辅助计数操作。

Code In LISP, unquoted data is evaluated as code. 代码 在LISP中,未引用的数据会被作为代码求值。

Expressions Expressions can be evaluated, like:

  • Bindings
  • Functions
  • Special Forms 表达式 表达式可被求值,例如:
  • 绑定(Bindings)
  • 函数(Functions)
  • 特殊形式(Special Forms)

Bindings A binding links a symbol to some data payload, and is created via the define special form:

(define a ‘x) 绑定 绑定将符号与数据载荷关联,通过define特殊形式创建: (define a ‘x)

Closures Closures are functions together with an environment, and result from the lambda special form:

(define fun (lambda (arg1 arg2) (print arg1) (print arg2))) 闭包 闭包是函数与环境的结合体,由lambda特殊形式生成: (define fun (lambda (arg1 arg2) (print arg1) (print arg2)))

Function Application The first element of an unquoted list is interpreted as an expression that evaluates to a function and the remaining elements as arguments to that function: (fun arg1 arg2) The function evaluation is eager; so first, the argument expressions are evaluated, then the function application is using the evaluated arguments. 函数应用 未引用列表的首元素被解释为求值为函数的表达式,其余元素作为该函数的参数: (fun arg1 arg2) 函数采用急切求值:先对参数表达式求值,再使用求值后的参数进行函数应用。

Arguments Arguments are evaluated and passed as a list of values to a function. This means the function parameters can be set up in various ways: (lambda x …) ; x is a list (lambda (x y) …) ; destructured list with elements x and y (lambda (x y . z) …) ; z is a list (which is by default nil)

Optional arguments can be passed as a list, like z above. 参数 参数经求值后作为值列表传递给函数。这意味着函数参数可通过多种方式设置: (lambda x …) ; x是列表 (lambda (x y) …) ; 解构列表元素x和y (lambda (x y . z) …) ; z是列表(默认为nil) 可选参数可作为列表传递,如上文的z。

Recursion LISPs rely on recursion instead of iteration. Recursion refers to a functi 递归 LISP依赖递归而非迭代。递归指的是函…(原文截断)

🔗 知识库双向关联