Plankalkül
| 编程范型 | 过程式 |
|---|---|
| 设计者 | Konrad Zuse |
| 发行时间 | 1948年 – 概念首次发表 |
| 当前版本 | |
| 网站 | {{URL|example.com|可选的显示文本}}Module:EditAtWikidata第29行Lua错误:attempt to index field 'wikibase' (a nil value) |
| 主要实作产品 | |
| Plankalkül-Compiler(柏林自由大学于2000年实现[1]) | |
| 影响语言 | |
| Superplan, ALGOL 58[2] | |
Plankalkül(德语发音:[ˈplaːnkalkyːl])是康拉德·楚泽在1942至1945年间,出于工程目的而设计的一种编程语言。它是第一种为计算机设计的高级编程语言。
“Kalkül”在德语中意为形式系统。如希尔伯特演绎系统原本名为“Hilbert-Kalkül”那样,“Plankalkül”指用于规划(planning)的形式系统[3]。
描述[编辑]
Plankalkül可比较于APL和关系代数。它包括赋值语句、子例程、条件语句、迭代、浮点算术、阵列、层级记录结构、断言、例外处理和其他高级特征比如目标导向执行。Plankalkül提供了叫做“广义图”(verallgemeinerter Graph)的数据结构,它可以被用来表示几何结构[4]。
Plankalkül的很多特征重现于后来的编程语言之中;一个例外是其特质性的使用占据多行的表示法。
Plankalkül的一些特征[5]:
数据类型[编辑]
在Plankalkül中唯一的原始数据类型是单一的“是否值”(德语:Ja-Nein-Werte)即布尔值。它被指称为标识符 <math>S0</math>。所有进一步的数据类型都是合成的,并且从原始类型通过“阵列”和“记录”的方式建造而成[6]。
所以8位序列(这在现代计算中被当作字节)被指称为<math>8 \times S0</math>,而大小为 <math>m</math>乘<math>n</math>的布尔阵列,被描述为<math>m \times n \times S0</math>。还存在更短的表示法,可以将<math>n \times S0</math>替代为<math>S1 \cdot n</math>,它叫做“n位是否值序列”(德语:n-stellige Folge von Ja-Nein-Werten)[6]。
类型<math>S0</math>有两个可能的值<math>0</math>和<math>L</math>。所以4位序列可以写为例如<math>L00L</math>,但是在这样的一个序列表示一个数的情况下,编程者可以使用十进制表示法的<math>9</math>[6]。
Zuse还定义了<math>S2</math>为<math>2 \times \sigma</math>(或写为<math>2 \sigma</math>)即有序对(德语:Angabenpaar);<math>S3</math>为<math>m \times \sigma</math>即列表(德语:Liste),在元素数量不定时写为<math>\Box \times \sigma</math>;<math>S4</math>为<math>m \times 2\sigma</math>即有序对列表(德语:Paarliste),在元素数量不定时写为<math>\Box \times 2\sigma</math>。两个组件(component,德语:Glieder)<math>\sigma</math>和<math>\tau</math>的结构(德语:Struktur)被写为<math>(\sigma, \tau)</math>[6]。
Plankalkül中类型(德语:Art)构成自3个元素:结构(德语:Struktur),语用意义(德语:Typ),和可能的限制(德语:Beschränkung)[6]。用户定义的类型被标示为字母<math>A</math>连带编号,比如<math>A1</math>,即第一个用户定义的类型。
例子[编辑]
Zuse使用了来自象棋理论的很多例子[6]:
| <math>A1</math> | <math>S1 \cdot 3</math> | 棋盘的坐标(它的大小为<math>8 \times 8</math>所以<math>3</math>位就足够了)。 |
| <math>A2</math> | <math>2 \times A1</math> | 棋盘的方格(例如<math>L00, 00L</math>指称代数记谱法中的e2)。 |
| <math>A3</math> | <math>S1 \cdot 4</math> | 棋子(例如<math>00L0</math>指称白王)。 |
| <math>A4</math> | <math>(A2, A3)</math> | 棋盘上的棋子(例如<math>L00, 00L; 00L0</math>指称白王在e2中)。 |
| <math>A5</math> | <math>64 \times A3</math> | 棋盘(棋子位置,描述64的方格都包含哪个棋子)。 |
| <math>A10</math> | <math>(A5, S0, S1 \cdot 4, A2)</math> | 游戏状态(<math>A5</math>指称棋盘,<math>S0</math>指称行棋玩家,<math>S1 \cdot 4</math>指称王车易位的可能性(<math>2</math>位给白棋<math>2</math>位给黒棋),<math>A2</math>指称关于哪个单元格有可能吃过路兵)。 |
标识符[编辑]
标识符(德语:Bezeichnungen)是字母字符连带编号[6]。针对变量有如下标识符种类[7]:
- 输入值(德语:Eingabewerte, Variablen),标记以字母<math>V</math>。
- 中介值,临时值(德语:Zwischenwerte),标记以字母<math>Z</math>。
- 常值(德语:Constanten),标记以字母<math>C</math>。
- 输出值(德语:Resultatwerte),标记以字母<math>R</math>。
特定的某种变量由写在种类之下的编号来标示[6],例如:<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix}</math>,<math>\begin{smallmatrix} Z \\ 2 \end{smallmatrix}</math>,<math>\begin{smallmatrix} C \\ 31 \end{smallmatrix}</math>等等。
程序和子例程都被表达为过程(德语:Rechenpläne),它被标记以字母<math>P</math>,跟随着一个程序编号(德语:Nummer),或者以点号分隔的程序组编号与程序编号。例如:<math>P12</math>、<math>P3 \cdot 7</math>[6]。
子例程<math>P17</math>的输出值保存在变量<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>中,其他子例程能在标识符<math>\begin{smallmatrix} R17 \\ 0 \end{smallmatrix}</math>之下获得到它,而读取这个变量的值还意味着调用有关的子例程[6]。
按索引访问元素[编辑]
Plankalkül允许使用组件(component)索引(德语:Komponenten-Index)访问变量的单独元素。例如,当一个程序接收输入于具有类型<math>A10</math>(游戏状态)的变量<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix}</math>之中,那么<math>\begin{smallmatrix} V \\ 0 \\ 0 \end{smallmatrix}</math>给出棋盘状态,<math>\begin{smallmatrix} V \\ 0 \\ 0 \cdot i \end{smallmatrix}</math>给出在编号<math>i</math>方格中的棋子,而<math>\begin{smallmatrix} V \\ 0 \\ 0 \cdot i \cdot j \end{smallmatrix}</math>给出这个棋子的位编号<math>j</math>[6]。
在现代编程语言中,这可以用描述为表示法类似于V0[0]、V0[0][i]、V0[0][i][j](尽管访问单一的位在现代编程语言中典型的使用位掩码)。
语法[编辑]
由于变量的索引是垂直书写的,逻辑上一行的Plankalkül指令要求占据4或3物理行来书写。
第一行包含变量种类,第二行标记以<math>V</math>(德语:Variablen-Index)包含变量编号,第三行标记以<math>K</math>(德语:Komponenten-Index)包含组件索引,而第四行标记以<math>S</math>(德语:Struktur-Index)是类型描述。类型不是必需的,但是Zuse评说到这能帮助阅读和理解程序[6]。
在<math>S</math>行中类型<math>S</math>前缀可以去掉,例如[6]:
<math>S \; \left| \; S1 \cdot n \quad m \times S1 \cdot n \quad S0 \quad S1 \quad \sigma \right. </math>,可以简写为<math> \ S \; \left| \; 1 \cdot n \quad m \times 1 \cdot n \quad 0 \quad 1 \quad \sigma \right. </math>。
进一步的类型<math>A</math>前缀也可以去掉,例如:
<math>S \; \left| \; A1 \quad A2 \quad S0 \quad A3\ \quad \sigma \right. </math>,可以简写为<math> \ A \; \left| \; 1 \quad 2 \quad 0 \quad 3\ \quad \sigma \right. </math>。<math>A0</math>同义于<math>S0</math>。
变量的索引的例子:
l}
& V \\
V & 3 \\
K & \\
S & m \times 2 \times 1 \cdot n
\end{array}</math>
|
变量<math>\begin{smallmatrix} V \\ 3 \end{smallmatrix}</math>,它是<math>m</math>个有序对的类型<math>S1 \cdot n</math>的值的列表。 |
l}
& V \\
V & 3 \\
S & m \times 2 \times 1 \cdot n
\end{array}</math>
|
<math>K</math>行在其为空时可以越过。因此这个表达式含义同于前者。 |
l}
& V \\
V & 3 \\
K & i \cdot 0 \cdot 7 \\
S & 0
\end{array}</math>
|
变量<math>\begin{smallmatrix} V \\ 3 \end{smallmatrix}</math>的第<math>i+1</math>个有序对的第<math>1</math>(索引<math>0</math>)组件的第<math>8</math>(索引<math>7</math>)位,它拥有布尔类型<math>S0</math>。 |
索引可以不只是常值。变量可以被用作其他变量的索引,而这被标记为折线,它展示变量的值将在哪个组件索引中使用:
| 使用变量作为其他变量的索引,出自第二版的Plankalül表示法。 | 变量<math>\begin{smallmatrix} V \\ 3 \end{smallmatrix}</math>的第<math>\begin{smallmatrix} Z \\ 5 \end{smallmatrix}</math>个元素。等价于在很多现代语言中的表达式V3[Z5][6]。
|
赋值运算[编辑]
Zuse在他的演算中介入了赋值算子,这个概念未知于他之前的数学中。他将其标记为<math>\Rightarrow</math>,并称其为产生符号(德语:Ergibt-Zeichen)。使用赋值的概念是在数学和计算机科学之间的关键差异[8]。
例如下列表达式:
lll}
& Z &+& 1 & \Rightarrow& Z\\
V & 1 & & & & 1\\
S & 1 \cdot n& & 1 \cdot n & & 1 \cdot n \\
\end{array}</math>
|
向整数中间值<math>\begin{smallmatrix} Z \\ 1 \end{smallmatrix}</math>增加数量<math>1</math>。 |
lll}
& (V &,& V) & \Rightarrow& R\\
V & \;\, 0 & & 1 & & 0\\
S & \;\, \sigma & & \sigma & & 2 \sigma \\
\end{array}</math>
|
将值<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix}</math>和<math>\begin{smallmatrix} V \\ 1 \end{smallmatrix}</math>合成为<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math> 所指称的合成值。 |
有人宣称Konrad Zuse最初使用图元File:Ergibt-Zeichen.png作为赋值的符号,并在Heinz Rutishauser的影响下开始使用<math>\Rightarrow</math>[6]。Knuth和Pardo相信Zuse总是写为<math>\Rightarrow</math>,而File:Ergibt-Zeichen.png是»Über den allgemeinen Plankalkül als Mittel zur Formulierung schematisch-kombinativer Aufgaben«的出版商在1948年介入的[8]。在Zürich的ALGOL 58会议中,欧洲与会者提议使用Zuse介入的赋值符号,而美国代表团坚持采用:=[6]。
存储赋值结果的变量(左值)被写在赋值算子的右侧[8]。对一个变量的第一次赋值被认为是对它的初始化声明[6]。
赋值算子的左侧被用作表达式(德语:Ausdrücke),它定义哪个值将被赋值到这个变量。表达式可以使用算术算子、布尔算子和比较算子(<math>=</math>,<math>\neq</math>,<math>\leq</math>等等)[6]。
控制流程[编辑]
布尔值被表示为整数,“否”(<math>\mathrm{nein}</math>)为<math>0</math>,而“是”(<math>\mathrm{ja}</math>)为<math>1</math>。条件控制流程采用守卫语句<math>\,\mathcal{A} \dot{\rightarrow} \mathcal{X}\,</math>的形式,这里的加点箭头叫做“条件符号”(德语:Bedingt-Zeichen),它指示在<math>\mathcal{A}</math>为“是”的条件下执行块<math>\mathcal{X}</math>。迭代算子具有如下形式:
- <math>\begin{matrix} W \\ \\ \\ \end{matrix} \begin{bmatrix} \mathcal{A} \dot{\rightarrow} \mathcal{X} \\ \mathcal{B} \dot{\rightarrow} \mathcal{Y} \\ \vdots \end{bmatrix}</math>
这里的<math>W</math>表示“重复规划”(德语:Wiederholungsplan),它重复直到所有守卫成为“否”[9]。
算子<math>\mu x(x \in l \and R(x))</math>和<math>\lambda x(x \in l \land R(x))</math>意图用在迭代运算之中,<math>\mu x</math>对变量<math>l</math>进行递增索引的遍历,而<math>\lambda x</math>对其进行递减索引的遍历,找出其符合特定条件<math>R()</math>的下一个(含第一个)元素<math>x</math>。典型用法是将在局部变量<math>x</math>中的符合条件元素赋值到中间变量之中,然后在用竖杠<math>\left| \right. </math>分隔出的后续语句之中,在前面语句成功找到符合条件的元素之时对此中间变量做进一步处理。
术语[编辑]
Zuse称呼一个单一的程序为“计算规划”(德语:Rechenplan)。他设想其所称谓的“规划组装设备”(德语:Planfertigungsgerät),能自动的将一个程序的数学公式转换成机器可读的打孔电影胶片,这是在今天称为翻译器或编译器的某种东西[5]。
例子[编辑]
下面的例子程序计算整数的阶乘:
<math> \begin{align} & \quad P1.1 \\ &\; \, \begin{array}{r}
\\
V \\
K \\
A \\
\end{array} \left| \; \begin{array}{lll}
R(V) & \Rightarrow& R\\
\, \quad 0 & & 0 \\
& & \\
\quad 10 & & 10 \\
\end{array} \right. \\
& \; \, \begin{array}{r}
\\
V \\
K \\
A \\
\end{array} \left| \; \begin{array}{lll}
1 & \Rightarrow& R\\
& & 0 \\
& & \\
10 & & 10 \\
\end{array} \right. \left| \; \begin{array}{lll}
V + 1 & \Rightarrow& Z\\
0 & & 0 \\
& & \\
10 \; \; \; 10 & & 10 \\
\end{array} \right. \\
&\; \, \begin{array}{r}
\\
V \\
K \\
A \\
\end{array} \left| \; \begin{array}{l} W2(Z) \\ \quad \quad 0 \\ \\ \quad \quad 10 \end{array} \left [ \begin{array}{l}
i > 0 & \dot{\rightarrow} \\ \\ \\ 10 \; \; 10 & \\ \end{array} \left[ \begin{array}{lll}
R \times i & \Rightarrow & R\\ 0 & & 0 \\ & & \\ 10 \; \; \; 10 & & 10 \end{array} \right] \right] \right.
\end{align} </math>
这里的Zuse定义的用户类型<math>A10</math>表示全部整数。第一行包含“边界概要”(德语:Randauszug),它定义程序<math>P1.1</math>接受一个变元(实际参数),即叫做<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix}</math>的一个整数,并返回叫做<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>的一个整数。这个程序将<math>1</math>赋值到<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>,将<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix} + 1</math>赋值到<math>\begin{smallmatrix} Z \\ 0 \end{smallmatrix}</math>。接着迭代算子<math>W2</math>执行重复运算,将从<math>\begin{smallmatrix} Z \\ 0 \end{smallmatrix} - 1</math>递减至<math>0</math>的值,依次赋值到局部变量<math>i</math>,这里将大于<math>0</math>的<math>i</math>值累乘至<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>。当重复结束之时,值<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>就包含了变元的阶乘。
Zuse还定义了用户类型<math>A8</math>表示自然数,<math>A9</math>表示非负整数,<math>A11</math>表示非负分数,<math>A12</math>表示全部分数,<math>A13</math>表示复数。迭代算子<math>W0</math>、<math>W1</math>和<math>W2</math>接受一个非负整数<math>n</math>,<math>W0</math>只重复<math>n</math>次而不赋值局部变量,<math>W1</math>重复时将从<math>0</math>递增至<math>n-1</math>的值赋值给局部变量<math>i</math>;迭代算子<math>W3</math>、<math>W4</math>和<math>W5</math>接受两个非负整数<math>(n,m)</math>并赋值到局部变量<math>i</math>,<math>W3</math>在<math>n<m</math>时从<math>n</math>递增至<math>m-1</math>,<math>W4</math>在<math>n>m</math>时从<math>n</math>递减至<math>m+1</math>,<math>W5</math>在<math>n<m</math>时从<math>n</math>递增至<math>m-1</math>而在<math>n>m</math>时从<math>n</math>递减至<math>m+1</math>。使用<math>W4(\begin{smallmatrix} V \\ 0 \end{smallmatrix}, 0)</math>,可以省略<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix} + 1</math>的初始值设置,和<math>i > 0</math>的守卫条件判断。
引用[编辑]
- ^ Rojas, Raúl; Göktekin, Cüneyt; Friedland, Gerald; Krüger, Mike; Scharf, Ludmila; Kuniß, Denis; Langmack, Olaf. Konrad Zuses Plankalkül — Seine Genese und eine moderne Implementierung (PDF). Hellige, Hans Dieter (编). Geschichten der Informatik. Visionen, Paradigmen, Leitmotive. Teil 3: Leitideen und Paradigmen in der Entwicklung der Programmiersprachen und der Programmierung 1. Berlin / Heidelberg, Germany: Springer-Verlag. January 2004: 215–235 [2–4]. ISBN 978-3-642-62208-3. doi:10.1007/978-3-642-18631-8_9. (原始内容 (PDF)存档于2006-05-01) (Deutsch). (21 [24] pages)
- ^ Rojas, Raúl; Hashagen, Ulf. The First Computers: History and Architectures. MIT Press. 2002: 292 [2013-10-25]. ISBN 978-0-26268137-7.
- ^ Zenil, Héctor (编). A Computable Universe: Understanding and Exploring Nature As Computation - with a Foreword by Sir Roger Penrose. Singapore: World Scientific Publishing Company. 2012: 791.
- ^ Giloi, Wolfgang K., Konrad Zuses Plankalkül als Vorläufer moderner Programmiermodelle, November 1990 (Deutsch)
- ^ 5.0 5.1 Hellige, Hans Dieter (编). 写于Bremen, Germany. Geschichten der Informatik. Visionen, Paradigmen, Leitmotive 1. Berlin / Heidelberg, Germany: Springer-Verlag. January 2004: 45, 56, 89, 104–105, 113, 152, 216–217. ISBN 978-3-540-00217-8. doi:10.1007/978-3-642-18631-8. ISBN 3-540-00217-0 (Deutsch). (xii+514 pages)
- ^ 6.00 6.01 6.02 6.03 6.04 6.05 6.06 6.07 6.08 6.09 6.10 6.11 6.12 6.13 6.14 6.15 6.16 6.17 Bauer, Friedrich L.; Wössner, Hans. The "Plankalkül" of Konrad Zuse: A Forerunner of Today's Programming Languages (PDF). Communications of the ACM. 1972, 15 (7): 678–685. S2CID 17681101. doi:10.1145/361454.361515. (原始内容 (PDF)存档于2009-02-20) (English). (HTML (页面存档备份,存于互联网档案馆))
- ^ Zuse, Konrad. Rojas, Raúl; Wagner, G.; Scharf, Ludmila; Schöttker-Söhl [Schötke-Suhl], Susanne , 编. Der Plankalkül (In der Fassung von 1945) (Manuscript). Konrad Zuse Internet Archive. 1946: 10, 45 [2023-11-01]. ZIA ID: 0233. (原始内容存档 (PDF)于2015-04-16) (Deutsch). (1+1+180 pages)
- ^ 8.0 8.1 8.2 Knuth, Donald Ervin; Pardo, Luis Isidoro Trabb. The Early Development of Programming Languages (PDF). Stanford University, Computer Science Department: 8, 9, 14, 15. August 1976 [2017-12-28]. (原始内容 (PDF)存档于2017-09-12).
- ^ Rojas, Raúl. Plankalkül (PDF). Encyclopedia of computers and computer history. Chicago / London: Fitzroy Dearborn Publishers: 634. 2001 [26 May 2023]. ISBN 1-57958235-4. (原始内容存档 (PDF)于2023-07-26).
延伸阅读[编辑]
- Zuse, Konrad. Ansätze einer Theorie des allgemeinen Rechnens unter besonderer Berücksichtigung des Aussagenkalküls und dessen Anwendung auf Relaisschaltungen [Inception of a universal theory of computation with special consideration of the propositional calculus and its application to relay circuits] (unpublished manuscript). 1943. Zuse Papers 045/018 (Deutsch).
- Zuse, Konrad. 写于Hopferau bei Füssen, Germany. Über den allgemeinen Plankalkül als Mittel zur Formulierung schematisch-kombinativer Aufgaben. Archiv der Mathematik (Karlsruhe / Stuttgart / Basel, Germany: Birkhäuser Verlag). 1948-12-06, 1 (6): 441–449. ISSN 0003-889X. doi:10.1007/BF02038459. eISSN 1420-8938 (Deutsch). (9 pages)
- Rojas, Raúl; Göktekin, Cüneyt; Friedland, Gerald; Krüger, Mike; Kuniß, Denis; Langmack, Olaf. Plankalkül: The First High-Level Programming Language and its Implementation (PDF). Berlin, Germany: Institut für Informatik, Freie Universität Berlin & Feinarbeit.de. February 2000. Technical Report B-3/2000. (原始内容存档于2006-05-01) (English).[1] (22 pages)
- Bruines, Bram. Plankalkül (PDF) (Thesis). 2010-01-08 [2023-11-02]. (原始内容存档 (PDF)于2023-11-02). (24 pages)
外部链接[编辑]
- Plankalkül-Programme. Konrad Zuse Internet Archive. 2014-08-21 [2017-10-04]. (原始内容存档于2014-08-21) (Deutsch及English). (NB. Plankalkül Java applets and documents.)
Module:Authority_control第183行Lua错误:attempt to index field 'wikibase' (a nil value)