根据thefreedictionary.com上的解释, syntactic sugar,指的是“语法中的糖分”,但此术语的中心词是“语法”,所以可以说成”含糖的语法”(也可以与下文中的“富糖”、“脱糖”对应)。另外,如果出现频率不高的话,也可以译为“语法糖衣”。

[译文]
含糖语法,是由Peter J. Landin创造的一个术语,指的是为一门计算机语言的语法中添加的附加物或附加成分,它不会影响语言的功能,但却能使人类使用起该语言来”更甜美”一些。含糖语法为编程人员(对计算机规范语言来说,是设计人员)提供了一种编写程序(编写规范)的替代方式,这种方式更具有实用性、更有助于形成较好的程序设计风格,或者使代码读起来更自然。但是,它不会影响形式上的可表达性,也不会让语言拥有某种新功能。

很容易用某种更简单的”核心”语法,将含糖语法转换(“脱糖”)为一个程序(规范)。以Landin为例,其核心是通过一系列操作(如赋值)浓缩成的λ演算。受Landin的启发,一些后来的编程语言,像ML和Scheme,都明确地设计为一种基于要素构件的语言核心。为方便起见,高级特性经过”脱糖”或降解,可以转换为其子集。事实上,这正是在原语基础上构建起来的通常的数学实践。然而,许多现代的、”富糖”型的语言(例如C#)则无法脱糖。但之所以它们的特性仍被视为”含糖”,是因为存在于先驱语言(例如C)中的原语,足以重新创建这些语言。

[原文]
Syntactic sugar is a term coined by Peter J. Landin for additions to the syntax of a computer language that do not affect its functionality but make it “sweeter” for humans to use. Syntactic sugar gives the programmer (designer, in the case of specification computer languages) an alternative way of coding (specifying) that is often more practical, more conducive to a better programming style, or more natural to read. However, it does not typically affect the expressiveness of the formalism or permit the language to do something
new.

Syntactic sugar can often be easily translated (“desugared”) to produce a program (specification) in some simpler “core” syntax. In Landin’s case, the core was a lambda calculus enriched with a few operations, such as assignment. Following Landin’s insights, some later programming languages, such as ML and Scheme, were explicitly designed as a language core of essential constructs. The convenient, higher-level features could be desugared and decomposed into that subset. This is, in fact, the usual mathematical practice of building up from primitives. However many modern, “sugar-rich” languages (such as C#) cannot be desugared. Still, their features may be considered “sugar” because primitives exist in predecessor languages (such as C) to fully recreate them.



朋友们的留言

  1. medical assistant certification | 12月 1st, 2011 at 20:14

    I’ve seen progression in every post. Your newer posts are simply wonderful compared to your posts in the past. Keep up the good work

    Reply to this comment
  2. pharmacy technician | 12月 1st, 2011 at 21:46

    These kind of post are always inspiring and I prefer to read quality content so I happy to find many good point here in the post

    Reply to this comment
  3. iroko worktops | 12月 2nd, 2011 at 00:24

    I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own Blog

    Reply to this comment

我来说两句儿

可以在留言中使用以下标签 :<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree