编程范型 | 多范型: 面向对象, 过程式 |
---|---|
设计者 | 芭芭拉·利斯科夫和她的学生 |
实作者 | 麻省理工学院 |
发行时间 | 1975年 |
稳定版本 | |
型态系统 | 强类型 |
网站 | www |
主要实作产品 | |
Native CLU,[1]Portable CLU,[2]clu2c[3] | |
受启发于 | |
ALGOL 60, Lisp, Simula | |
施影响于 | |
Ada, Argus, C++, Lua, Python[4], Ruby, Sather, Swift[5] |
CLU是在1974年到1975年由麻省理工学院(MIT)的芭芭拉·利斯科夫和她的学生创造的一门编程语言。虽然它没有被广泛使用,但它引入了许多现在广泛使用的特性,并被视为面向对象编程发展的重要一步。
主要贡献包括抽象数据类型[6]、传共享调用、迭代器、多值返回(并行赋值形式)、参数化类型和可变类型。值得注意的是它使用了具有构造器和方法的类,但没有继承。
聚簇
CLU的语法基于了ALGOL,这是多数新语言设计的起点。关键增补是“聚簇”(cluster)概念,它是CLU的类型扩展系统和语言名字的根源(CLUster)[7]。聚簇一般对应于面向对象语言中“类”的概念。例如,下面是CLU用来实现复数的语法:
complex_number = cluster is add, subtract, multiply, ... rep = record [ real_part: real, imag_part: real ] add = proc ... end add; subtract = proc ... end subtract; multiply = proc ... end multiply; ... end complex_number;
聚簇是一个模块,它封装了除了那些在is
子句中显式命名的成员之外的所有成员。这些成员对应于现在面向对象语言中一个类的公开成员。聚簇还定义了可以在聚簇之外引用名字的一个类型(在这个案例中是complex_number
),但是它的表示类型(这里的rep
)对于外部客户是隐藏的。
聚簇名字是全局的,不提供名字空间机制来组织聚簇,也不允许它们在其他聚簇内部被“局部”创建。
CLU不进行隐式类型转换。在聚簇中,显式类型转换up
和down
在抽象类型和表示之间进行变更。有一个全体类型any
,和一个过程force[]
来检查一个对象是否是一个特定类型。对象可以是可变的或不可变的,后者是基础类型,比如整数、布尔值、字符和字符串[7]。
其他特征
CLU类型系统的另一个关键特征是迭代器,它一个接一个的、顺序的从一个搜集返回对象[7]。迭代器提供了一致的应用编程接口(API),而不管所用于的是什么数据。因此给complex_number
的一个搜集的迭代器可以用与integer
的数组相同的方式调用。CLU迭代器的显著特征是它们被实现为协程,每个值都是通过yield
语句提供给调用者的。像CLU中这样的迭代器,现在是很多现代语言比如C#、Ruby和Python的常见特征,然而它们近来经常被称为生成器。下面是迭代器的例子:
% 产生从1到n的奇数 odds = iter(n:int) yields int i:int i = 1 while i < n do yield i i := i + 2 end end odds for i:int in odds(13) do print int$unparse(i) || "\n" end
CLU还包括了异常处理,它参考了在其他语言中的各种尝试;异常使用signal
引发,并通过except
处理。不同于具有异常处理的多数其他语言,异常不会被隐式的沿着调用链重新发起。不同之处还有,在CLU中异常被当作是正常执行流程的一部分,并作为“正常”而有效的一种类型安全的方式,用来退出循环或从函数返回;它允许用except when
直接指定在其他条件适用时的返回值。既未捕获也未显式的重新发起的异常,被立即转换成特殊失败异常,这典型的会终止程序。
CLU经常被引证为具有类型安全的可变类型的第一个语言,在这里叫作oneof
,早于ML语言拥有的叫做代数数据类型的标签联合。
CLU中最后一个显著特征是并行赋值(多赋值),这里多于一个变量可以出现在赋值算符的左侧。例如,书写x,y := y,x
将交换x
和y
的值。以相同的方式,函数可以返回多个值,比如x,y,z := f(t)
。并行赋值(但未包括多返回值),在CLU之前已经出现在CPL(1963年)之中,叫作“同时赋值”[8],然而确是CLU使之流行,并被引证为对后来语言中出现的并行赋值有直接的影响。
在CLU程序中所有对象都存活在堆中,而内存管理是自动化的。
CLU支持参数化类型的用户定义数据抽象。它是提供类型安全限定的参数化类型的第一个语言,它使用where
子句结构,来表达在实际类型实际参数上的约束。
影响
CLU的异常处理机制影响了后来的语言如C++和Java[10]。
Sather、Python和C#所包含的迭代器,最早出现在CLU中。
Perl和Lua采用的多赋值和从函数调用返回多个值来自CLU[11]。
Python和Ruby从它引入了传共享调用、yield
语句[12]和多赋值[13]。
参考资料
- ↑ 1.0 1.1 Curtis, Dorothy. CLU home page. Programming Methodology Group, Computer Science and Artificial Intelligence Laboratory. Massachusetts Institute of Technology. 2009-11-06 [2016-05-26].
- ↑ 2.0 2.1 Curtis, Dorothy. Index of /pub/pclu. Programming Methodology Group, Computer Science and Artificial Intelligence Laboratory. Massachusetts Institute of Technology. 2009-11-06 [2016-05-26].
- ↑ Ushijima, Tetsu. clu2c. clu2c. woodsheep.jp. [2016-05-26].
- ↑ Lundh, Fredrik. Call By Object. effbot.org. [21 November 2017].
replace "CLU" with "Python", "record" with "instance", and "procedure" with "function or method", and you get a pretty accurate description of Python's object model.
- ↑ Lattner, Chris. Chris Lattner's Homepage. Chris Lattner. 2014-06-03 [2014-06-03].
The Swift language is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list.
- ↑ Liskov, Barbara; Zilles, Stephen. Proceedings of the ACM SIGPLAN symposium on Very high level languages: 50–59. 1974. doi:10.1145/800233.807045.
|chapter=
被忽略 (帮助) - ↑ 7.0 7.1 7.2 Liskov, B.; Snyder, A.; Atkinson, R.; Schaffert, C. Abstraction mechanisms in CLU (PDF). Communications of the ACM. August 1977, 20 (8): 564–576. doi:10.1145/359763.359789.
- ↑ Barron, D. W.; Buxton, J. N.; Hartley, D. F.; Nixon, E.; Strachey, C. The main features of CPL. Computer Journal. 1963, 6 (2): 134–143. doi:10.1093/comjnl/6.2.134.
- ↑ Stroustrup, Bjarne. The C++ Programming Language (Third Edition and Special Edition). Bjarne Stroustrup's homepage. 2004-09-08 [2020-09-21].
- ↑ Bruce Eckel's MindView, Inc: Does Java need Checked Exceptions?. Mindview.net. [2011-12-15].
- ↑ Ierusalimschy, R.; De Figueiredo, L. H.; Celes, W. Proceedings of the third ACM SIGPLAN conference on History of programming languages – HOPL III (PDF): 2–1–2–26. 2007 [2020-09-21]. ISBN 978-1-59593-766-7. doi:10.1145/1238844.1238846.
|chapter=
被忽略 (帮助) - ↑ Ruby's Roots and Matz's Leadership. Appfolio Engineering. 2019-11-08 [2019-11-15].
Matz feels that blocks are the greatest invention of Ruby (I agree.) He got the idea from a 1970s language called CLU from MIT, which called them 'iterators'...
- ↑ Functional Programming HOWTO — Python 3.8.3 documentation. docs.python.org. [2020-05-25].
外部链接
- 官方网站
- A History of CLU (pdf)
- clu2c: a program to compile CLU code to C
- Dictionary of Programming Languages
- CLU comparison at '99 bottles of beer' multi-language demo algorithm site