跳至內容

ISWIM

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書
ISWIM
編程範型指令式, 函數式
設計者Peter J. Landin
釋出時間1966年,​60年前​(1966
範疇詞法
受影響於
ALGOL 60, Lisp
影響語言
PAL, SASL, ML, NPL, Lucid, Haskell

ISWIM(「If you See What I Mean」的首字母縮寫),是的一種抽象的電腦程式語言或程式語言家族,它由Peter J. Landin設計,並描述在他1966年於ACM通訊發表的文章《The Next 700 Programming Languages》之中[1]

儘管沒有實現,它被證明為在程式語言開發中非常有影響力的語言,特別是對於函數式程式設計語言,比如SASLMLNPLHaskell和它們的後繼者,還有數據流程編程語言如Lucid

設計

[編輯]

ISWIM是具有函數式核心的指令式編程語言,它構成自加了語法糖的叫做「應用表達式」(AE)的lambda演算,並增加了可變變量賦值,還有強力控制機制即對應J算子英語J operator的程式點算子pp[2]。ISWIM的操作語意,使用Landin的SECD抽象機來定義,並且使用了傳值呼叫,因而是及早求值[3]

ISWIM基於了lambda演算,從而具有高階函數詞法範疇變量,其應用表達式為了「同時」或「平行」定義而擴充了在λ.之間的識別碼列表,為遞歸定義而採用了Y不動點算子。ISWIM的目標之一,就是要看起來更像數學表示,所以在定義結構之時,放棄了ALGOL的陳述式括號begin……end,轉而採用了越位規則和基於縮排的範疇。

ISWIM程式基於了一個單一表達式,它由wherelet子句、條件表達式和函數定義所限定。ISWIM在表示法上的特色,是與CPL一起,最早使用了where子句,尤其是let子句適合表達ALGOL 60結構而為後繼者語言所承襲:

AE ISWIM
{λf.f(b+2c)+f(2b-c)}
[λx.x(x+a)]

{λ(f,b,c).f(b+2c)+f(2b-c)}
[λx.x(x+a),
  u/(u+1),
  v/(v+1)]

{λg.g({λf.f}[λx.ax²+bx+c],
  u/(u+1),
  v/(v+1))}
[λ(f,p,q).f(p+2q,2p-q)]

{λf.f(6)}[Yλf.λn.(n=0)1 elsenf(n-1)]

{λx.xy(x+y)}
[{λy.+ay}
  [+]]

{λ(a,b,f).
  {λ(g,h).
    {λk.X}
    [λ(u,v).λx.K]}
  [(g,h).
    (λx.G,λ(y,z).H)]}
[A,B,λ(x,y).F]
f(b+2c)+f(2b-c)
where f(x) = x(x+a)

f(b+2c)+f(2b-c)
where f(x) = x(x+a)
  and b = u/(u+1)
  and c = v/(v+1)

g(f where f(x) = ax²+bx+c,
  u/(u+1),
  v/(v+1))
where g(f,p,q) = f(p+2q,2p-q)

f(6) where rec f(n) = (n=0)→1; nf(n-1)

xy(x+y)
where x = a²+a√y
  where y = a²+b²

X
where k(u,v)(x) = K
where rec g(x) = G
  and h(y,z) = H
where a = A
  and b = B
  and f(x,y) = F
let f(x) = x(x+a)
f(b+2c)+f(2b-c)

let f(x) = x(x+a)
  and b = u/(u+1)
  and c = v/(v+1)
f(b+2c)+f(2b-c)

let g(f,p,q) = f(p+2q,2p-q)
g((let f(x) = ax²+bx+c; f),
  u/(u+1),
  v/(v+1))

let rec f(n) = ((n=0)→1; nf(n-1)); f(6)

let x =
  let y = a²+b²; a²+a√y
xy(x+y)

let a = A
  and b = B
  and f(x,y) = F
let rec g(x) = G
  and h(y,z) = H
let k(u,v)(x) = K
X

下面以階乘函數應用英語Function application為例展示ISWIM的等價規則,設L = (n=0)→1; nf(n-1)G = (g where g(n) = L)並且F = (G where rec f = G)

  f(6) where rec f(n) = (n=0)→1; nf(n-1)   let rec f(n) = ((n=0)→1; nf(n-1)); f(6)
f(6) where rec f(n) = L let rec f(n) = L; f(6)
f(6) where rec f = (g where g(n) = L) let rec f = (let g(n) = L; g); f(6)
f(6) where rec f = G let rec f = G; f(6)
f(6) where f = (G where rec f = G) let f = (let rec f = G; G); f(6)
(G where rec f = G)(6) (let rec f = G; G)(6)
(G where f = (G where rec f = G))(6) (let f = (let rec f = G; G); G)(6)
(G where f = F)(6) (let f = F; G)(6)
((g where g(n) = L) where f = F)(6) (let f = F; (let g(n) = L; g))(6)
((g where g(n) = (n=0)→1; nf(n-1)) where f = F)(6) (let f = F; (let g(n) = ((n=0)→1; nf(n-1)); g))(6)
(g where g(n) = (n=0)→1; nF(n-1))(6) (let g(n) = ((n=0)→1; nF(n-1)); g)(6)
((n=0)→1; nF(n-1)) where n = 6 let n = 6; ((n=0)→1; nF(n-1))
6(F(5)) 6(F(5))
6((G where rec f = G)(5)) 6((let rec f = G; G)(5))
6(f(5) where f = (G where rec f = G)) 6(let f = (let rec f = G; G); f(5))
6(f(5) where rec f = G) 6(let rec f = G; f(5))
6(f(5) where rec f = (g where g(n) = L)) 6(let rec f = (let g(n) = L; g); f(5))
6(f(5) where rec f(n) = L) 6(let rec f(n) = L; f(5))
6(f(5) where rec f(n) = (n=0)→1; nf(n-1)) 6(let rec f(n) = ((n=0)→1; nf(n-1)); f(5))

在ISWIM論文中首次出現了用來定義結構的代數資料類型定義,這是通過自然語言的either……or…………and……描述完成的,但明確的表示出了「英語Product type[4]

ISWIM Standard ML
an  () is
  either , and has
    a , which is an 
  or a , in which case it has
    a , which is an ,
    and a , which is an ,
  or a , ……
  or , ……
  or a , ……
  or , …… .      
datatype aexp
  = SIMPLE of body 
  | COMBINATION of rator * rand
  | CONDITIONAL ……
  | ONE_ARMED ……
  | LISTING ……
  | BEET ……
and body = BODY of identifier
and rator = RATOR of aexp
and rand = RAND of aexp

實現和衍生

[編輯]

沒有進行過直接實現ISWIM的嘗試,但Arthur Evans的PAL[5],和John C. Reynolds英語John C. Reynolds的Gedanken[6],取得了Landin的多數概念,包括強力的控制轉移操作,這兩者都是動態型別語言。Robin MilnerML,可以被認為等價於沒有J算子,而有類型推論的ISWIM。

從ISWIM衍生出的另一條路線,是去掉指令式特徵即賦值和J算子,而只留下純函數式語言[7],接着就有可能切換到惰性求值。這條路線導致了SASLHopeKRCMirandaHaskellClean

參照

[編輯]
  1. ^ Landin, P. J. The Next 700 Programming Languages (PDF). Communications of the ACM (Association for Computing Machinery). March 1966, 9 (3): 157–165 [2021-08-28]. S2CID 13409665. doi:10.1145/365230.365257. (原始內容 (PDF)存檔於2022-03-23). 
  2. ^ Landin, P.J. A Generalization of Jumps and Labels (PDF). 1965. 
    Thielecke, H. An Introduction to Landin's "A Generalization of Jumps and Labels". Higher-Order and Symbolic Computation. December 1998, 11 (2): 117–123. S2CID 1562780. doi:10.1023/A:1010060315625. 
  3. ^ Gordon Plotkin英語Gordon Plotkin. Call-by-Name, Call-by Value and the Lambda Calculus (PDF) (報告). 1975 [2020-04-26]. (原始內容 (PDF)存檔於2020-02-01). 
  4. ^ Turner, D. A., Some History of Functional Programming Languages (PDF), Lecture Notes in Computer Science 7829, Berlin, Heidelberg: Springer Berlin Heidelberg: 1–20, 2013 [2024-01-28], ISBN 978-3-642-40446-7, doi:10.1007/978-3-642-40447-4_1, The ISWIM paper also has the first appearance of algebraic type definitions used to define structures. This is done in words, but the sum-of-products idea is clearly there. 
  5. ^ Arthur Evans. PAL: a language designed for teaching programming linguistics. Proceedings ACM National Conference. ACM National Conference. Association for Computing Machinery. 1968. 
    A. Evans. PAL -- A Reference Manual and a Primer (PDF) (報告). Department of Electrical Engineering, Massachusetts Institute of Technology. February 1968 [2021-09-09]. (原始內容 (PDF)存檔於2022-03-06). 
    A. Evans. Appendix 2.1. The Complete Syntax for PAL (PDF) (報告). February 1968 [2021-09-10]. (原始內容 (PDF)存檔於2022-03-06). 
    J. M. Wozencraft, A. Evans. Notes on Programming Linguistics (PDF). M.I.T. Department of Electrical Engineering. 1971 [2021-09-11]. (原始內容 (PDF)存檔於2022-03-06). 
  6. ^ John C. Reynolds英語John C. Reynolds. GEDANKEN: a simple typeless language which permits functional data structures and co-routines (PDF) (報告). Argonne National Laboratory. September 1969 [2021-09-09]. (原始內容 (PDF)存檔於2021-09-09). 
    John C. Reynolds英語John C. Reynolds. Definitional interpreters for higher-order programming languages. ACM '72: Proceedings of the ACM annual conference - Volume. August 1972 [2022-11-19]. doi:10.1145/800194.805852. (原始內容存檔於2022-11-27). 
  7. ^ Ivanović, Mirjana; Budimac, Zoran. A definition of an ISWIM-like language via Scheme. ACM SIGPLAN Notices. April 1993, 28 (4): 29–38. S2CID 14379260. doi:10.1145/152739.152743. 

本條目部分或全部內容出自以GFDL授權發佈的《自由線上電腦詞典》(FOLDOC)。