编程语言是整个程序活动中最重要的部分,如同人说话一样,说话是用于表达思想,与人沟通。类似,编程语言是程序员表达思想,与计算机沟通的。
对于计算机而言,能理解的只是电流高低,对应即二进制10。这称为机器语言。计算机内部由集成电路铺就,会有一些处理器元件存在,通过算术逻辑单元(ALU),能进行简单的逻辑运算:与、或、非、移位、比较以及简单的加、减、乘运算。
如今的计算机软件层出不穷,百花齐放,规模也逐年增大,但计算机底层硬件仍然是没有变化。
那么如何让计算机按照我们的意愿去工作?我们这时需要指令。指令是计算机能理解的电流信号。程序员需要编写指令,来让计算机达到计算的
目的,让计算机表现出智能。那么计算的内容又如何确定呢?
计算机只能做计算,计算机的智能是人为赋予的。这是一直没有改变的事实。
那么,如何才能赋予计算机智能呢?用计算机能理解的语言沟通,即指令。程序员编写指令,交给计算机,计算机进行计算,反馈出结果。就如同你要让一个外国人帮你做事,那么你得发出让她听得懂的语言,她才能理解,才能顺着你的意思去做。但计算机只懂二进制,那我们要写二进制吗?是的,肯定要的。先辈们就是写二进制的,最初使用打孔纸条,后来使用汇编语言,后来经过先辈们的一代代努力,为了让程序员更简单地命令计算工作,如今编程语言百花齐放,成千上万种。
只要让计算机工作,那么肯定逃不开二进制语言。所以,无论何种语言,最终都会变换成二进制语言。编程语言的选择,完全取决于程序员自己。是程序员创造了编程语言。每种编程语言有其自身适应业务,比如使用汇编语言可以直接面向硬件编程,因为汇编语言很容易转换成机器语言;使用C语言,可以面向系统编程,因为大多数系统本身是使用C语言写就;使用JavaScript可以面向浏览器编程,因为浏览器核心可以解释JavaScript代码等等。
所有的编程语言,无论其如何变化,其实质是没有改变的,所谓万变不离其宗。编程语言的核心,仍然是指示计算机工作。编程语言在机器语言之上,构建出了更利于人类使用的概念。如Ruby,Python,C++,Rust,Go等等,都是介于人类和机器之间的语言。人类通过学习编程语言,按照编程语言的语法规则表达思想,写成程序,编程语言将这些程序按照解释规则,转换成机器语言,交由机器进行运算。这是人类和机器进行沟通的方式。机器和人类沟通的方式,则由先辈们具象化了,即:机器的反馈是以人类能理解的方式表现,如声音、图像、文字、视频等。
那编程语言都有的是什么东西呢?这要从程序本身入手。程序本身是由指令和数据组成,演化为如今是算法与数据结构。指令或算法,在编程语言中,通常表现为:控制语句、逻辑判断、基础运算等;数据,更多指的是数据的存储。
在编程语言中,常常分为两派:C和Lisp。
C语言是从汇编发展而来,很多概念也继承过来。其中的核心为指令,它将指令分为了:控制语句、逻辑判断语句、运算符、跳转语句等。数据则分为整数、小数、指针等基本数据,以及数组、结构体等数据结构。
Lisp语言则承自数学,是数学与计算机相结合的结晶。它的核心是演算。它以表为基础,以函数为中心原则。它的数据就是以表指代,它的指令皆为函数。
现今的编程语言,都是从这两者发展而来。不过在它们基础之上,附加了更多概念。如,附加面向对象概念,是为了解决大型软件开发中的代码复用、扩展等问题;附加函数式概念,是为了解决并行运算中的数据安全等问题。
C系代表着性能、状态、副作用、嵌入式;Lisp系代表着灵活、太极(元能力)、慢。
编程语言通用概念
注释:解释源码的注解文字
注释常常在解释或编译时会被丢弃,用于给代码阅读者以参考。
变量:用于存储数据。
变量用于存储数据,会在内存中有其空间。静态编程语言中,每个变量都要有数据类型,用于预分配内存空间;动态编程语言变量的类型是动态的,内存不固定,所以常常伴随垃圾回收机制。
字面量:是一个固定值的表示法。
用于赋值给变量。字面量是原值,本身不可改变。如字面量10和字面量11,代表的是不同的值。如:
10,0x1001,020,"string",true,5.83,3.14e2
[1,2,3],(1,2,3)
{name:"Xiao",age:30}
符号:是指代内容的字串。
是不可更改的,是由编译器或解释器使用的文本,如:
a = 10
a = "name"
a = @b
a是变量,在最初赋值为10,之后赋值为”name”,但最后赋值为b所具有的值。其中,文本a和文本@b就是符号,10和”name”是字面量。但a和@b是变量。
函数/过程/方法/lambda表达式:运算规则
函数是从数学发展而来,用于表述参数的运算规则。函数可以有返回值,也可以没有返回值。没有返回值的函数,通常称为过程。
def ==(a,b)
a.age == b.age
end
运算符:符号化函数
运算符是从数学发展过来,其本质还是一种运算规则,是一种符号化的函数。所以,也可以把运算符当作函数。
(+ 1 2)
(/ 3 4)
(> 3 4)
流程控制:控制程序非线性执行
流程控制通常有两种:分支和循环。分支常通过逻辑判断来进行,对不同的条件进行测试,来选择其中一个分支执行。循环通常为有限循环与无限循环。在计算机中,通常不存在无限
这样的概念。因此,我们常说的循环,即是有限循环。对于不同的语言,循环有这样几种方式:迭代、递归。两者作用一致。
块、作用域与闭包:变量生存周期
有些变量是临时的,用完即销毁,这就涉及作用域。作用域是限定变量起作用的范围,也称为生命周期,出了作用域,变量即销毁。对于函数执行而言,通常会有执行环境,此运行环境通常不做存储,但闭包会读取此运行环境,以做特殊用途。常见的是用在回调函数情形下。
模块/包/命名空间/库:可供复用的代码集合
如今的程序规模越来越庞大,也越来越精细,往往一个软件的完成,需要多人共同努力完成。代码复用即为了应对这种问题。在代码复用的基础上,产生了许多概念,如库、包、模块等。
数据结构:数据组织方式
数据结构在编程语言中,或多或少都有实现,最典型的是数组/列表,几乎所有高级编程语言都有这个概念。随着软件规模扩大化,处理的数据也越来越多,简单地数据结构已经很难应付如今复杂的问题,所以很多编程语言将多种数据结构要么内置于语言,要么置于标准库。内置于语言,多见于脚本语言,它们用于解决日常问题;外置于标准库,可保证语言核心简洁。如你所见,常见数据结构放眼即是。常用数据结构有这样几种:数组、列表、哈希表。
数据结构扩展:可自由适应业务,自定义数据结构
数据结构是组织数据的形式,不仅如此,当自定数据结构时,还要有匹配的操纵这个数据结构的一系列函数存在。在C系语言中,常见struct,enum,union等,它们又称为自定数据类型
编程语言中的特殊概念
面向对象
面向对象的核心是对象——可包含数据(以字段或属性形式)和代码(以过程或方法形式)。方法可操纵字段。程序的实现是以创建大量对象并且互相交互的形式。
面向对象里的两个概念,一为类,一为实例。类是抽象的,可定义此类对象通用的属性和方法;实例是类的具象化个体。
面向对象将函数和变量分为以下几种:
- 类变量:属于整个类,所有实例共享此变量
- 实例变量或属性:术语每个实例自己的数据,每个实例都有此变量的一分副本
- 类方法:属于整个类,只能访问类变量和函数调用参数数据
- 实例方法:属于分散的对象,可访问实例变量、输入参数、类变量等。
面向对象实现3个特征:
- 封装:绑定数据和操纵这些数据的方法,并在失误使用和外部调用时保持安全。主要的是数据隐藏。主要目标是保证数据的隔离安全性。
- 动态分派/消息发送:这是对象而不是任何外部代码的职责。在响应方法调用时,在运行时查找对象关联表,以选择过程代码来执行。也就是,当通过a.do(1)函数调用时,会将消息1分发给a对象,此时a对象会从关联表中查找do方法进行调用。这称之为动态分派。当关联表中有多个同名方法时,此过程称为多重分派。
- 多态:子类型是多态的一种形式,当调用代码时,可以不用知道它是层次结构中的哪个类。同时,继承层次结构中的同名方法其表现可不同。多态是实现动态分派的一种手段。
-
复合,继承和委托:对象可保存其他对象的实例变量,这称为对象复合。复合描述的是has-a关系。继承将所有父类的数据和方法以同名形式存在于子类,类似于完整复制,继承可以快速复用已有代码。继承描述的是is-a关系。复合和继承都能复用代码。委托也可用于替代继承。
- Mixin,Triats:是用于给类添加新的功能,既不是has-a,也不是is-a的形式。
面向对象有其好处在可重用性、可维护性。但随着并行和多线程编程越来越流行,面向对象难以处理这类问题。
面向对象的本质是抽象,越抽象,越可能称为假、大、空。面向对象代码在复用过程中,会出现冗余的情形。
OOP与其他编程语言相比,没有独特的优势,只是提供一种问题建模的方式而已,反而往往带来复杂性。创建类,就是在创建类型,往往把问题的焦点转移到了类型,而不是聚焦数据结构和算法,这有点本末倒置的嫌疑。
编程语言选择
编程语言的选择,通常选择的是编程语言的生态。只要编程语言是图灵完备的,那么它们即是等价的,即A能完成的工作B也能完成。然而,现在所有流行于市的编程语言,都是图灵完备的。所以,当面临选择时,实则是选择其生态圈。典型的例子即为C语言,C语言老而弥坚。从编程语言角度而言,C语言并非是刻意设计的编程语言,而更多的是刚好够用的设计哲学。所以,C语言本身并非坚不可催,如果不慎,就可能引发崩溃等严重错误。但,从其生态而言,C语言不可或缺——如今大多数操作系统是用C语言构建,C语言在嵌入式设备、手机、智能家电也遍地开花,也可如此说:C语言统治着智能时代的最底层基石部分。
而在互联网、网页一端,Javascript则由来已久。同样的,从语言角度出发,Javascript很低级,甚至并不高效,而且比较丑陋:怪异的模块管理方式、诡异的this关键字等等,但Javascript在逐渐演变,牢据着网页端,丝毫不松手。Javascript是网页浏览器指定官方语言,甚至蔓延至网页后端(nodejs)。
C++则巩固着游戏引擎和高性能部分,从语言层面而言,C++并没有解决C语言的易崩溃部分,原始的模块管理,低效编译、语法冗余的template等。但其继承了C语言的高效,C++的哲学是不必为你所不需要的部分买单,因此是高性能的不二之选,同时提供了面向对象,比C语言提供了更快的开发速率。当有新的语言能提供与C++相等的性能时,并且能兼容C语言所处的平台时,经过了精心设计,C++会被取缔。
Go作为新时代的编程语言,吸纳了许多编程语言的优点,其生态圈也非常丰富,占据着云服务和区块链等新生领域。从语言角度而言,Go语言是后起之秀,在设计中就规避了C++的一些问题(如编译时间长、没有包管理等),但Go语言在抉择上,也并非尽善尽美,如冗余interface、原始的错误处理机制等。
Ruby在快速网页开发中,占得一席之地,但昙花一现。Ruby从语言角度而言,非常完美、简洁,其设计哲学是为了让程序员更快乐地编程,因此很多魔法技巧都可以在Ruby中绽放,强大的DSL机制,可以快速完成任务,如同Rails其展现一样。但Ruby的生态圈并未从网站开发蔓延开来,导致其昙花一现,迅速凋零。
Python借助其简单的语法,吸收了非常多的编程新手,同时其设计哲学一件事只有一种最优解法,让有经验的程序员能专注于任务,而无须为语言层面的东西操心,提高了工作效率,也是许多专业人士的选择。Python如今基本上有取代Shell、Bat趋势,是自动化任务的首选语言,也是原型开发的试验场。基本上所有的原型开发,都可快速通过Python来实现并检测结果。由于这些原因,Python只会越来越流行,直至有某种语言比Python更易学、易用,更易于用在日常自动化工作中为止。
Java的生态,如今基本上只在Android上了。Java从语言本身而言,非常拘束,解决问题必须写类,必须了解清楚概念。甚至Java这种语言,有大批言论要应用设计模式,扬言干掉if,switch,提高程序复用性——这简直是荒唐。C#设计之初就是Java的竞争对手,C#和Java很类似,不过C#是微软的。C#语言,从语言本身而言,是经过精心设计的,但同Java一样,语法冗余。要不是Unity3D和跨平台Mono的出现和流行,C#说不定早已握死于微软之手。
Haskell、Rust、Elixir等语言,尚未形成气候,对于工作选择,面临相当大的风险——一切尚未实现的功能,都得自己实现。此时,选择这些新的语言,则需要从其设计哲学入手,来判断其未来。
那么,如此说来,总结一下现代化编程语言的语言层面:
- 模块管理或包管理、库管理:集成第三方库的形式。基本上是从网络下载并自动导入即可;当发布时,只需发布到网络即可。
- API文档自动化:管理库的文档的方式。基本上是自动生成静态网页形式,供开发者本地阅读。
- 原生并发支持:有简洁的语法,能提供并发支持,并且不易出错。现如今是async,go等子句形式,以进程、线程、协程、纤程以及原子式操作等作为底层,在其上有Actor,Channel等模式形式。函数式编程语言则直接在语言层面以非改变值形式,提供并发操作底层支持,再配合线程、Actor等,实现高并发。
- Unicode:国际码支持。
- 模式匹配、正则表达式:提供快速符号匹配支持。现在的业务基本上都是处理大量文本信息,文本信息解析效率也是比较重要的部分。
- 宏或元编程:自动生成代码,可以简化很多代码编写。在人工智能领域,有个非常重要的概念称为自我学习与自我完善,即,代码可以自更新和自修复。元编程或宏可以提供这种用途。
还有许多其他功能,可通过标准库进行扩展。语言本身应保持精简和完善,语法层面应足够完善、极富表达力,编译器或解析器层面保证复杂表达式的精确执行。
一篇有意思的文章:《跨语法语言》
Various
-
注释
直到行尾
标识 | 语言 |
---|---|
# |
Awk, BourneShell, CoffeeScript, E, FishShell, GNU-bc, GNU-sed, Icon, Io, Julia, Maple, merd, Perl, Perl6, PHP, Pliant, Python, Ruby, Tcl, YAML |
// |
BCPL, C#, C++, C99, Dylan, F#, Go, Io, Java, JavaScript, PHP, Pike, Scilab, YCP, Yorick |
-- |
Ada, Cecil, Eiffel, Haskell, Lua, Sather, Simula, SQL92 |
; |
Assembler, Common Lisp, Emacs Lisp, Logo, MUMPS, Rebol, Scheme |
% |
Erlang, Matlab, Mercury, Oz, PostScript, Prolog, TeX |
rem |
Basic |
' |
Visual Basic |
" |
Vimscript |
\ |
Forth |
! |
Assembler, Fortran90 |
NB. |
J |
C or * in column 1 |
Fortran |
嵌套注释
标识 | 语言 |
---|---|
(* ... *) |
Beta, F#, Mathematica, Modula-3, OCaml, Pascal, SML |
%( ... %) |
Matlab |
/* ... */ |
Classic REXX, Dylan, Io, Oz, SQL99 |
{ ... } |
Pascal, Rebol |
{- ... -} |
Haskell |
#| ... |#(1) |
Common Lisp, Scheme |
#= ... =# |
Julia |
#[ ... ] |
Perl6 |
#if 0 ... #endif |
C |
comment { ... } |
Rebol |
comment [ ... ] |
Rebol |
[ ... ](2) |
Rebol |
--[[ ... ]] |
Lua |
非嵌套
标识 | 语言 |
---|---|
" ... " |
Smalltalk |
/* ... */ |
B, C, C#, C++, CSS, GNU-bc, Go, Java, JavaScript, Mercury, PHP, Pike, PL/I, YCP, Yorick |
<!-- ... --> |
HTML, XML |
( ... ) |
Forth |
### ... ### |
CoffeeScript |
-
文档注释
直到行尾 | 标识 | 语言 | |—|—| |
///
| C#, F#, Java | |-- |
| Haskell | |-- ^
| Haskell |非嵌套 | 标识 | 语言 | |—|—| |
/** ... */(3)
| C, C#, E, Java, JavaScript, PHP | |(** ... *)
| F# |
标识 | 语言 |
---|---|
{-| ... -} |
Haskell |
(** ... *) |
OCaml |
/* DOCUMENT ... */ |
Yorick |
indexing identifier: "..."; |
Eiffel |
someClass comment: '...' |
Smalltalk |
rebol [ Note: "..." ] |
Rebol |
func ["..." arg] ... |
Rebol |
class X: """... """ def x(): """... """ (4) |
Python |
(define (f para1 para2) "..." ...) |
Scheme |
(defun f (para1 para2) "..." ...) |
Common Lisp, Emacs Lisp |
=pod ... =cut(5) |
Perl, Perl6 |
=begin ... =end |
Ruby |
function MYFUNCTION %MYFUNCTION the very first comment line is displayed in the help table of contents % % the remaining lines are displayed when getting help for MYFUNCTION % |
Matlab |
- 当前行和文件的信息
标识 | 语言 |
---|---|
__LINE__ __FILE__ |
C, C++, Perl, PHP, Pike, Ruby |
__LINE__ __SOURCE_FILE__ |
F# |
$?LINE $?FILE |
Perl6 |
__file__ |
Python |
(new System.Diagnostics.StackFrame(true)).GetFileLineNumber() (new System.Diagnostics.StackFrame(true)).GetFileName() |
C# |
Thread.currentThread().getStackTrace()[1].getLineNumber(); Thread.currentThread().getStackTrace()[1].getFileName(); |
Java |
system/script/header/file(6) |
Rebol |
SOURCELINE() / parse source OS . SOURCENAME |
Classic REXX |
info frame 0 |
Tcl8.5 |
thisContext lineNumber / thisContext method source |
Smalltalk |
runtime.Caller(0) |
Go |
-
符号
区分大小写(关键字、变量标识符等…) |规则|语言| |—|—| |
case-sensitive
| Awk, B, BourneShell, C, C#, C++,
CoffeeScript, F#, FishShell, Go, Haskell,
Io, Java, JavaScript, Lua, Maple,
Mathematica, Matlab, merd, Modula-3,
OCaml, Perl, Perl6, Pike, Pliant,
Prolog, Python, Ruby, Smalltalk,
Tcl, XML, YAML, Yorick | |case-insensitive
| Ada, Assembler, Classic REXX, Common Lisp, CSS, Eiffel, Forth, HTML, Logo, Pascal, PL/I, Rebol, SGML, SQL92, Visual Basic | |case-sensitive: variablescase-insensitive: keywords, functions, constants...
| PHP | |case-sensitive: identifierscase-insensitive: keywords
| E | |case-sensitive: identifierscase-insensitive: commands
| MUMPS | |case-sensitive: upper case disallowed
| GNU-bc |what is the standard way for scrunching together multiple words |规则|语言| |—|—| |
camelCase
| CoffeeScript, JavaScript | |CamelCase or camelCase
| C#, E, Go, Haskell, Io, Java, JavaScript, Mathematica, Pascal, Smalltalk, Tcl, Visual Basic | |underscores
| FishShell, GNU-bc, merd | |dots
| Logo | |hyphens
| Common Lisp, Emacs Lisp, Rebol, Scheme | |underscores for functions / types, unclear for modules / constructors
| OCaml | |UPPER_CASE
| BourneShell | |lowercasenoseparator
| Matlab | |underscores, UPPER_CASE for class names
| Eiffel | |CamelCase for classes, underscores for methods
| Python | |CamelCase for types, underscores for functions, variables, ...
| Pliant | |CamelCase for methods, types and modules, underscore for functions
| F# | |CamelCase for modules and classes, ALL_CAPS for constants, underscores for functions, variables, ...
| Ruby | |CamelCase for modules and classes, ALLCAPS for macros, underscores for methods, constants and variables
| Pike | |CamelCase for modules, ALL_CAPS for constants, unclear for functions / variables
| Perl, Perl6 | |CamelCase for variables, underscores for predicates
| Prolog | |usually lowercase or underscores, ALL_CAPS for macros
| C | |usually underscores
| C++ | |Camel_Case
| Ada |变量标识符正则表达式 |规则|语言| |—|—| |
[a-zA-Z][a-zA-Z0-9]*
| FishShell, Mathematica, PL/I, Smalltalk | |[a-zA-Z][_a-zA-Z0-9]*
| Eiffel, Matlab, Vimscript | |[a-zA-Z](_?[a-zA-Z0-9])*
| Ada | |[_a-zA-Z][_a-zA-Z0-9]*
| Awk, B, C, C#, C++, E, Go, Maple, PHP, Python, Tcl | |[_a-zA-Z0-9]+
| BourneShell, Perl, Perl6 | |[a-zA-Z0-9]+
| FishShell | |[_a-zA-Z][_a-zA-Z0-9]* or '[^']*'
| Pliant | |[_a-zA-Z$][_a-zA-Z0-9$]*
| Java | |[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*
| CoffeeScript, JavaScript | |[a-zA-Z%][a-zA-Z0-9]*
| MUMPS | |[_a-z][_a-zA-Z0-9]*
| Ruby | |[_a-z][_a-zA-Z0-9]*[!?']*
| merd | |[_a-z][_a-zA-Z0-9']*
| Haskell, OCaml, SML | |[_a-zA-Z][_a-zA-Z0-9']*
| F# | |[_A-Z][_a-zA-Z0-9]*
| Mercury, Prolog | |[_a-zA-Z!0&*/:<=>?^][_a-zA-Z!0&*/:<=>?^0-9.+-]*
| Scheme | |[a-zA-Z!?@#][a-zA-Z0-9!?@#]*
| Classic REXX | |[_a-zA-Z?!.'+*&|=~-][_a-zA-Z0-9?!.'+*&|=~-]* or [^0-9[](){}":;/][^ \n\t[](){}":;/]*
| Rebol | |[a-z][a-z0-9_]*
| GNU-bc | |anything without a space and is not a number
| Common Lisp, Forth |函数标识符正则表达式 (if different from variable identifier regexp) |规则|语言| |—|—| |
[_a-zA-Z][_a-zA-Z0-9]*[!?]?
| Ruby | |[_a-z][_a-zA-Z0-9]*
| Mercury, Prolog | |[A-Z][_a-zA-Z0-9]*(7)
| Vimscript | |[^ \t\n\r\f]+
| Tcl | |[^ \t\n\r\f/]+
| FishShell |关键字正则表达式 (if different from variable identifier regexp) |规则|语言| |—|—| |
[A-Z]+
| Modula-3 | | | |类型正则表达式 (if different from variable identifier regexp) |规则 | 语言 | | ———————- | ————– | |
[_A-Z][_a-zA-Z0-9']*
| Haskell | |[_a-z][_a-zA-Z0-9']*
| Mercury, OCaml |常量正则表达式 (if different from variable identifier regexp) |规则 | 语言 | | ———————- | ————– | |
[A-Z][_a-zA-Z0-9]*
| Ruby | |[_A-Z][_a-zA-Z0-9']*
| Haskell, OCaml | |[_a-z][_a-zA-Z0-9']*
| Mercury | -
breaking lines (useful when end-of-line and/or indentation has a special meaning)
规则 | 语言 |
---|---|
nothing needed |
Ada, B, C, C#, C++, Common Lisp, D, Eiffel, Emacs Lisp, F#, Forth, Go, Haskell, Java, JavaScript, Maple, Mathematica, OCaml, Oz, Pascal, Perl, Perl6, PHP, PostScript, Rebol, Scheme, Smalltalk, SML, XSLT, YCP |
\ |
Awk, BourneShell, C, CoffeeScript, E, FishShell, GNU-bc, Io, Python, Ruby, Tcl |
_ |
Visual Basic |
, |
Classic REXX |
~ |
Logo |
... |
Matlab |
-
变量赋值或声明
赋值 |规则 | 语言 | | ———————- | ————– | |
=
| Awk, B, Basic, BourneShell, C, C#, C++, Classic REXX, Erlang, Go, Icon, Io, Java, JavaScript, Lua, Mathematica, Matlab, Oz, Perl, Perl6, PHP, Pike, YCP, Yorick | |:=
| Ada, BCPL, Cecil, Dylan, E, Eiffel, Maple, Mathematica, Modula-3, Pascal, Pliant, Sather, Simula, Smalltalk, SML | |<-
| F#, OCaml | |_(8)
| Squeak | |:
| BCPL, Rebol | |->(9)
| Beta | |def
| PostScript | |setq
| Common Lisp, Emacs Lisp | |setf
| Common Lisp | |set
| Common Lisp, FishShell, Rebol | |SET v=...
| MUMPS | |set!
| Scheme | |is
| Prolog | |make "v e
| Logo | |e v !
| Forth |声明 |规则 | 语言 | | ———————- | ————– | |
=
| Haskell, Mercury, Prolog | |<-
| Haskell | |:-
| Prolog | |:=
| Io | |let v = e in
| F#, OCaml | |let val v = e in
| SML | |let v = e(10)
| BCPL, F#, Vimscript | |def v := e / var v := e
| E | |my / our / local / use vars
| Perl | |my / our / temp
| Perl6 | |define
| Dylan, Scheme | |let let*
| Common Lisp, Scheme | |letrec
| Scheme | |flet labels defun defmethod defvar defparameter defsetf ..
| Common Lisp | |local V1 = e V2 = e2 in ... end
| Oz | |global v1, v2
| Python | |global v1 v2
| Matlab, Scilab | |:@
| Beta | |NEW v
| MUMPS | |v: t
| Ada, Eiffel, Pascal | |t v
| C, C#, C++, Java | |var v t
| Go | || v1 v2 |
| Smalltalk | |auto v1, v2; extrn v3, v4;
| B | |auto
| GNU-bc | |var
| JavaScript, Pliant | |gvar
| Pliant | |variable v(11)
| Forth | |e value v
| Forth | |Module[{x, y = v}, ... ]
| Mathematica | |Block[{x, y = v}, ... ]
| Mathematica | |With[{c1 = v1, c2 = v2, ... }, ...]
| Mathematica | |<xsl:variable name="v" select="e"/>
| XSLT |两者一起:
规则 | 语言 |
---|---|
= |
CoffeeScript, GNU-bc, merd, Python, Ruby |
:= |
Go, merd |
set, variable |
Tcl |
- 组合表达式
规则 | 语言 |
---|---|
( ... ) |
Ada, Awk, B, BCPL, Beta, C, C#, C++, Classic REXX, CoffeeScript, D, E, Eiffel, F#, GNU-bc, Go, Haskell, Io, Java, JavaScript, Julia, Logo, Lua, Maple, Mathematica, Matlab, merd, Modula-3, MSH, MUMPS, OCaml, Oz, Pascal, Perl, Perl6, PHP, Pike, Pliant, Prolog, Python, Rebol, Ruby, Scilab, Smalltalk, SML, SQL92, Tcl, Vimscript, XPath, YCP, Yorick |
[ ... ] |
Rebol |
indentation |
merd |
$ ... |
Haskell |
begin ... end |
F#, FishShell, OCaml, Ruby |
space(12) |
merd |
- block (grouping statements, especially when statements are not expressions) 块(组合语句,特别是语句不是表达式时)
规则 | 语言 |
---|---|
{ ... } |
Awk, BCPL, BourneShell, GNU-bc, GNU-sed, JavaScript, PHP, Pike, Tcl, Yorick |
{ ... }(13) |
B, C, C#, C++, E, Go, Haskell, Java, Modula-3, Perl, Perl6, YCP |
( ... )(13) |
BourneShell |
[ ... ](14) |
Logo, Smalltalk |
"..." |
Tcl |
begin ... end(13) |
Ada, Pascal |
(begin ...) |
Scheme |
BEGIN ... END |
Modula-3 |
do ... end |
Classic REXX |
do ... end(13) |
Lua, PL/I |
indentation |
CoffeeScript, F#, MUMPS, Pliant, Python |
indentation(13) |
Haskell, merd |
foo ... end where foo in { if, do, ... } |
Modula-2, Ruby |
foo ... end where foo in { if, for, while, ... } |
Matlab, Scilab |
foo ... end where foo in { if, loop, ... } |
Eiffel |
foo ... end foo where foo in { if, do, ... } |
Ada, Fortran90 |
(* ... *)(15) |
BCPL |
(# ... #) |
Beta |
- use a block as a return value (when statements are not expressions) 块作为返回值(当语句不是表达式时)
规则 | 语言 |
---|---|
valof |
BCPL |
do |
Perl, Perl6 |
proc() .. end proc |
Maple |
-
equality / inequality
shallow |规则 | 语言 | | ———————- | ————– | |
== !=
| Awk, B, C, C++, CoffeeScript, F#, Go, Io, Java, OCaml, Perl, Perl6, Pike, Yorick | |= /=
| Eiffel, Fortran90 | |= <>
| Forth, Logo, Maple, Modula-2, Pliant, Rebol | |= #(16)
| Modula-2, Modula-3 | |= !=
| BourneShell, FishShell | |== === != !==(17)
| JavaScript, PHP | |=== !==
| Perl6, PHP5 | |== ~=
| Lua | |== ~~
| Smalltalk | |== ~==
| Dylan | |= '=
| MUMPS | |= ~= neqv(15)
| BCPL | |f= f<>
| Forth | |is_equal(18)
| Eiffel | |eq ne
| Emacs Lisp, PostScript | |eq, eql
| Common Lisp | |eq? eqv?
| Scheme | |.EQ. .NE.
| Fortran | |is / is not
| Python | |is / isnot
| Vimscript |deep |规则 | 语言 | | ———————- | ————– | |
== !=
| Awk, C#, C++, E, merd, PHP5, Python, Ruby, Tcl, Vimscript, YCP | |== <>
| Python | |== /=
| Haskell | |== \=
| Oz | |== \==
| Classic REXX, Prolog | |= /=
| Ada | |= !=
| Maple, XPath | |= <>
| Beta, F#, OCaml, Pascal, Rebol, SML, SQL92, Visual Basic | |= ~=
| Dylan, Smalltalk | |== ~= eq ne isequal isequalwithequalnans
| Matlab | |== ~= eq ne isequal
| Scilab | |=@= \=@= / = \= / =:= =\=(19)
| Prolog | |=== =!= / == !=(20)
| Mathematica | |.eq
| Logo | |equal?
| Scheme | |equals
| Java | |equal
| Common Lisp, Emacs Lisp, Pike | |equalp
| Common Lisp | |eqv
| Perl6 | |deep_is_equal
| Eiffel | |isEqual
| Objective-C | -
comparison
规则 | 语言 |
---|---|
< > <= >= |
Ada, Awk, Awk, B, Beta, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, Dylan, E, Eiffel, Emacs Lisp, F#, Forth, Go, Haskell, Io, Java, JavaScript, Logo, Lua, Maple, Mathematica, Matlab, merd, Modula-3, OCaml, Pascal, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, Scheme, Scilab, Smalltalk, SML, SQL92, Tcl, Vimscript, Visual Basic, XPath, YCP, Yorick |
< > =< >= |
Mercury, Oz |
< > '> '< |
MUMPS |
<< >> <<= >>=(21) |
Classic REXX |
@< / @=< / @> / @>= |
Prolog |
lt gt le ge |
Perl, Perl6, PostScript |
-lt -gt -le -ge |
BourneShell, FishShell, MSH |
.LT. .GT. .LE. .GE. |
Fortran |
u< u> u<= u>= |
Forth |
f< f> |
Forth |
returns 3 values (i.e. inferior, equal or superior)
|规则 | 语言 |
| ———————- | ————– |
| a <=> b
| merd, Perl, Perl6, Ruby |
| cmp
| Perl, Perl6, Python |
| compare
| F#, Forth, Haskell, Mercury, OCaml, Pliant, Prolog, Smalltalk |
| strcmp
| C, PHP |
| three_way_comparison
| Eiffel |
| string compare
| Tcl |
| compareTo
| Java |
| strings.Compare()
| Go |
returns 4 values (i.e. inferior, equal, superior or not comparable)
规则 | 语言 |
---|---|
compare |
Pliant |
compareTo |
E |
min / max (binary or more)
规则 | 语言 |
---|---|
min / max |
Beta, C++, Common Lisp, Dylan, E, Eiffel, F#, Forth, Haskell, Io, Java, Lua, Maple, Matlab, merd, OCaml, PHP5, Pike, Pliant, Prolog, Python, Rebol, Scheme, Scilab, Smalltalk, SQL92, Tcl8.5, Yorick |
min minstr / max maxstr(22) |
Perl |
Min / Max |
Mathematica, Oz |
MIN / MAX |
Classic REXX, Modula-3 |
measure-object -min / measure-object -max |
MSH |
fmin / fmax |
Forth |
Integer'min / Integer'max |
Ada |
- runtime evaluation
规则 | 语言 |
---|---|
eval |
BourneShell, Common Lisp, Emacs Lisp, FishShell, JavaScript, Matlab, Perl, Perl6, PHP, Python, Ruby, Scheme, Tcl, YCP |
CoffeeScript.eval(23) |
CoffeeScript |
exec |
Python |
evstr / execstr |
Scilab |
dostring |
Lua |
doString |
Io |
evaluate |
Forth |
Compiler evaluate: |
Smalltalk |
runtime_compile / compile + execute |
Pliant |
Compiler.evalExpression or Compiler.parseOzVirtualString |
Oz |
compile_string |
Pike |
interpret |
Classic REXX |
ToExpression |
Mathematica |
run |
Logo |
XECUTE |
MUMPS |
do / reduce / compose / load |
Rebol |
[...] |
Tcl |
=..(24) |
Prolog |
-
manual memory allocation
allocation |规则 | 语言 | | ———————- | ————– | |
malloc
| C | |allocate throw
| Forth | |new
| Ada |deallocation
规则 | 语言 |
---|---|
free |
C |
free throw |
Forth |
- force garbage collection
规则 | 语言 |
---|---|
doGC |
Beta |
GC.start |
Ruby |
gc |
Logo, Maple, Pike |
System.gc() |
Java |
System.gcDo |
Oz |
System.GC.Collect() |
C#, F# |
gc.collect() |
Python |
gc_collect_cycles(25) |
PHP5 |
full_collect |
Eiffel |
garbage_collect |
Mercury, Prolog |
collectgarbage |
Lua |
Collector collect |
Io |
VM.garbageCollect() |
JavaScript |
Gc.full_major() |
OCaml |
Smalltalk garbageCollect |
Smalltalk |
System.Mem.performGC |
Haskell |
incremental garbage collection => not needed |
Perl, Perl6 |
recycle |
Rebol |
interp.gc() |
E |
(ext:gc) |
Common Lisp |
runtime.GC() |
Go |
Functions
- function call
规则 | 语言 |
---|---|
f(a,b,...) |
Ada, Awk, Awk, B, C, C#, C++, CoffeeScript, CSS, Dylan, E, Eiffel, Erlang, Go, Io, Java, JavaScript, Lua, Maple, Matlab, Mercury, merd, Modula-3, Pascal, Perl, Perl6, PHP, Pike, Prolog, Python, Ruby, XPath, YCP, Yorick |
f a b ... |
BourneShell, F#, FishShell, Haskell, Logo, Matlab, MSH, OCaml, Pliant, Rebol, SML, Tcl |
f(a,b,...f) or f[a,b,...] depending on the version |
BCPL |
(f a b ...) (apply f l) |
Common Lisp, Emacs Lisp, Scheme |
(funcall f a b ...) |
Common Lisp, Emacs Lisp |
{f a b} |
Oz |
[apply f a b] |
Tcl8.5 |
f[a,b,...] |
Mathematica |
f[a,b,...] or f.call(a,b,...) |
Ruby |
&$f(a,b,...) or $f->(a,b,...) |
Perl |
$f.(a,b,...) |
Perl6 |
f a, b, ... |
CoffeeScript, Perl |
f, a, b, ...(26) |
Yorick |
v = f(a, b, ...) or call f a, b, ... |
Classic REXX |
a b ... f |
Forth, PostScript |
(a,b,...)->&f or (a,b,...)->f |
Beta |
f:a(27) |
FL |
f@a(28) |
Mathematica |
a // f(28) |
Mathematica |
a ~ f ~ b(29) |
Mathematica |
.. [ f, A, B, ...] |
Prolog |
<xsl:call-template name="f"> <xsl:with-param name="a" select=a/> <xsl:with-param name="b" select=b/> </xsl:call-template> |
XSLT |
with no parameter
|规则 | 语言 |
| ———————- | ————– |
| f
| Ada, BourneShell, Eiffel, Forth, Haskell,
Io, Logo, Matlab, Mercury, MSH, Pascal, Perl,
Perl6, Pliant, PostScript, Prolog, Rebol, Ruby,
Tcl, Yorick |
| f()
| Awk, C, C#, C++, CoffeeScript, E, Erlang, F#, Go,
Java, JavaScript, Lua, Maple, merd, OCaml, Perl,
PHP, Pike, Python, SML, YCP |
| (f)
| Common Lisp, Emacs Lisp, Scheme |
| (funcall f)
| Common Lisp, Emacs Lisp |
| {f}
| Oz |
| f[]
| Mathematica |
| f[] or f.call
| Ruby |
| &$f or $f->()
| Perl |
| $f.()
| Perl6 |
| v = f()
| Classic REXX |
| call f
| Classic REXX, Fortran |
| f value(30)
| Smalltalk |
| <xsl:call-template name="f">/
| XSLT |
partial application
(in the examples below, a normal call is “f(a,b)”)
give the first argument
|规则 | 语言 |
| ———————- | ————– |
| f a
| F#, Haskell, OCaml, SML |
| f(a)
| Mercury |
| f(a,)
| merd |
| &f.assuming(var_name => a)
| Perl6 |
| functools.partial(f, a)(31)
| Python |
| interp alias {} f_a {} f a
| Tcl |
give the second argument
|规则 | 语言 |
| ———————- | ————– |
| f(,b)
| merd |
| &f.assuming(b => b)
| Perl6 |
| flip f b(32)
| Haskell |
give the first argument to operator “>”
|规则 | 语言 |
| ———————- | ————– |
| (a >)
| Haskell, merd |
| (>) a
| F#, OCaml |
give the second argument to operator “>”
|规则 | 语言 |
| ———————- | ————– |
| (> a)
| Haskell, merd |
- function definition
规则 | 语言 |
---|---|
sub f { ... } |
Perl, Perl6 |
sub f($para1, $para2, ...) { ... } |
Perl6 |
def f(para1, para2, ...): ... |
Python |
def f(para1, para2, ...) ... end |
Ruby |
def f(para1, para2, ...) ... { ... } |
E |
f para1 para2 = ... |
Haskell |
let f para1 para2 = ... |
F#, OCaml |
f(para1, para2, ...) = valof $( ... $) |
BCPL |
f(para1, para2, ...) = ... |
merd |
f[para1_, para2_, ...] := ... para1 ... |
Mathematica |
f ... or f: para1 ... |
Smalltalk |
f: func [para1 para2 ...] ... |
Rebol |
/f { ... } def |
PostScript |
f := (para1, para2, ...) -> ... |
Maple |
f := method(para1, para2, ..., code) |
Io |
func f(a, b, c...) { ... } |
Yorick |
typ0 f(typ1 para1, typ2 para2, ...) { ... } |
C, C#, C++, Pike, YCP |
function f(para1, para2) { ... } |
Awk, JavaScript, PHP5 |
function f(para1, para2) ... code ... end |
Lua |
function f; ...; end |
FishShell |
function f { ... } |
KornShell |
function f { param(para1, [typ2]para2, ...) ... } |
MSH |
(define (f para1 para2) ...) |
Scheme |
(defun f (para1 para2) ...) |
Common Lisp, Emacs Lisp |
fun { F Para1 Para2 } ... end |
Oz |
fun f para1 para2 = ... |
SML |
proc f {para1 para2} { ... } |
Tcl |
function retval = f(para1, para2) retval = ... |
Matlab, Scilab |
:- func f(typ1, typ2, ...) = typ0. f(Para1, Para2, ...) = ... |
Mercury |
function f(para1 : type1; para2 : typ2; ...) return retval is begin ... end f; |
Ada |
function f para1 para2 -> retval arg typ1 para1; arg typ2 para2; arg rettyp retval; ... |
Pliant |
function f(para1 : typ1, para2 : typ2, ...) : retval; var retval : typ0; begin ... end |
Pascal |
f (para1 : typ1; para2, para3 : typ2; ...) : rettyp is do ... end |
Eiffel |
<xsl:template name="f"> <xsl:param name="para1"/> <xsl:param name="para2"/> ... </xsl:template> |
XSLT |
Function f(para1, para2) ... End Function |
Visual Basic |
: f ... ; |
Forth |
f() { ... } |
BourneShell, KornShell |
f : procedure ... return retval |
Classic REXX |
to f :para1 :para2 ... end |
Logo |
func f(para1 typ1, para2 typ2, ...) (typ3, ...) { ... } |
Go |
procedures
|规则 | 语言 |
| ———————- | ————– |
| procedure f(para1 : typ1; para2, para3 : typ2); begin ... end
| Pascal |
| f (para1 : typ1; para2, para3 : typ2; ...) is do ... end
| Eiffel |
| procedure f(para1 : typ1; para2 : MODE type2; ...) is begin ... end f; MODE ::= | OUT | IN OUT
| Ada |
| void f(typ1 para1, typ2 para2, ...) { ... }
| C, C#, C++, Pike |
| let f(para1, para2, ...) be $( ... $)
| BCPL |
| proc { F Para1 Para2 } ... end
| Oz |
| f := proc(para1, para2, ...) ... end proc
| Maple |
| Sub f(para1, para2) ... End Sub
| Visual Basic |
| function f(para1, para2) ...
| Matlab, Scilab |
| f : procedure ... return
| Classic REXX |
| func f(para1 typ1, para2 typ2, ...) { ... }
| Go |
variable number of arguments
规则 | 语言 |
---|---|
one can use overloading on different number of arguments |
C++, Java |
sub f { ... @_ } |
Perl |
sub f; ... $argv; end |
FishShell |
f() { ... $@ } |
BourneShell |
f := ... ## & |
Mathematica |
f[params___] := ... params ... |
Mathematica |
function f(varargin) for i=1:nargin ...(varargin{i}) end |
Matlab |
function f(varargin) for e=varargin ...(e) end |
Scilab |
(args...) -> ... |
CoffeeScript |
(lambda x ...) or(33) |
Scheme |
f(args ...typ0)(34) |
Go |
predicates
规则 | 语言 |
---|---|
f(Para1, Para2, ....) :- ... . |
Prolog |
- anonymous function
规则 | 语言 |
---|---|
sub { my ($a, $b) = @_; ... } |
Perl |
{ my ($a, $b) = @_; ... }(35) |
Perl |
{ ... } (arguments are in the stack |
PostScript |
[ ... ] |
Logo |
{ param(para1, [typ2]para2, ...) ... } |
MSH |
{|a, b| ... }(36) |
Ruby |
[:a :b| ... ] |
Smalltalk |
[list {a b} {...}] |
Tcl8.5 |
lambda a, b: ... |
Python |
lambda(typ1 para1, typ2, para2, ...) { ... }; |
Pike |
(a, b) => ... |
C#3, CoffeeScript |
(a, b) -> ... |
CoffeeScript, Maple |
a, b -> ... |
merd |
-> $a, $b { ... } |
Perl6 |
\a b -> ... |
Haskell |
:noname ... |
Forth |
fn (a, b) => ... |
SML |
fun a b -> ... |
F#, OCaml |
(func(A, B) = C :- ...) |
Mercury |
function(a, b) { ... } |
JavaScript, PHP5 |
function(a, b) use (&$v1, $v2) { ... }(37) |
PHP5 |
function(a, b) ... end |
Lua |
Function[{a, b}, ....](38) |
Mathematica |
fun(a, b) -> ... end |
Erlang |
fun {$ A B} ... end(39) |
Oz |
func [a b ...] ... |
Rebol |
def _(para1, para2, ...) ... { ... } |
E |
proc {|a, b| ...} |
Ruby |
lambda {|a, b| ...} |
Ruby |
(lambda (a b) ...) |
Common Lisp, Emacs Lisp, Scheme |
inline('...x...y...')(40) |
Matlab |
method(a, b, ...) |
Io |
method(a, b) ... end method(41) |
Dylan |
create_function(',','...') |
PHP |
delegate(ta a, tb b) { ... } |
C#2 |
[](ta a, tb b) { ... } |
C++-0x |
[](ta a, tb b) -> typ { ... } |
C++-0x |
func(para1 typ1, ...) (typ2, ...) { ... } |
Go |
-
function return value
breaks the control flow
规则 | 语言 |
---|---|
return(42) |
Ada, Awk, B, BCPL, BourneShell, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, E, FishShell, Go, Io, Java, JavaScript, Lua, Maple, Matlab, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, Tcl, Vimscript, YCP, Yorick |
Return |
Mathematica, Visual Basic |
RETURN |
Modula-3 |
resultis(43) |
BCPL |
return-from xxx |
Common Lisp |
^ |
Smalltalk |
Exit Function / Exit Sub |
Visual Basic |
exit |
Forth |
output |
Logo |
function body is the result
|规则 | 语言 |
| ———————- | ————– |
| no syntax needed(44)
| CoffeeScript, Common Lisp, Dylan, Emacs Lisp, Erlang, F#, Haskell, Io, Maple, Mathematica, Matlab, OCaml, Oz, Perl, Perl6, Rebol, Ruby, Scheme, SML, Tcl |
setting the result
|规则 | 语言 |
| ———————- | ————– |
| Result := val
| Eiffel |
| <function name> = val
| Visual Basic |
| <function name> := val
| Pascal |
| <retvar name> = val;
| Ada, Matlab |
- function called when a function is not defined (in dynamic languages)
规则 | 语言 |
---|---|
AUTOLOAD |
Perl |
AUTOSCALAR, AUTOMETH, AUTOLOAD... |
Perl6 |
__autoload |
PHP5 |
__getattr__ |
Python |
method_missing |
Ruby |
doesNotUnderstand |
Smalltalk |
__noSuchMethod__(45) |
CoffeeScript, JavaScript |
unknown |
Tcl |
no-applicable-method |
Common Lisp |
doesNotRecognizeSelector |
Objective-C |
TryInvokeMember(46) |
C# |
match [name, args] { ... } |
E |
the predicate fail |
Prolog |
forward |
Io |
- runtime inspecting the caller information
规则 | 语言 |
---|---|
caller |
Perl, Perl6, Ruby |
call |
Io |
inspect.stack()[1] |
Python |
backtrace |
Pike |
debug_backtrace |
PHP5 |
trace 'I' |
Classic REXX |
evalin('caller', ...) |
Matlab |
current_predicate |
Prolog |
thisContext sender |
Smalltalk |
where(2) |
Maple |
info level |
Tcl |
runtime.Caller(0) |
Go |
- function composition
规则 | 语言 |
---|---|
. |
Haskell |
~ |
merd |
o |
SML |
@ |
Maple |
compose |
Dylan |
Composition |
Mathematica |
<< |
F# |
>> |
F# |
- identity function
规则 | 语言 |
---|---|
id |
Haskell |
identity |
Common Lisp |
Identity |
Mathematica |
yourself |
Smalltalk |
Control Flow
- sequence
规则 | 语言 |
---|---|
, |
C, C++, Go, JavaScript, Matlab, Perl, Pike, Prolog, Scilab |
. |
Smalltalk |
; |
Ada, Awk, B, Beta, BourneShell, C, C#, C++, E, F#, FishShell, GNU-sed, Go, Haskell, Io, Java, JavaScript, Maple, Mathematica, Matlab, merd, Modula-3, OCaml, Pascal, Perl, Perl6, PHP, Pike, PL/I, Pliant, Python, Ruby, SML, Tcl, YCP |
: |
Maple |
nothing, optionally ; |
Classic REXX, Lua |
space |
Eiffel, Rebol |
end-of-line |
Assembler, Awk, Basic, BourneShell, CoffeeScript, E, F#, FishShell, Fortran, GNU-sed, Haskell, Io, JavaScript, Lua, Matlab, merd, Pliant, Python, Ruby, Tcl |
(begin ...) |
Scheme |
(progn ...) (prog1 ...) (prog2 ...) |
Common Lisp, Emacs Lisp |
>> |
Haskell |
- if_then
规则 | 语言 |
---|---|
if c then ... |
CoffeeScript, F#, merd, OCaml, Pascal, Tcl |
if c then ... end |
Eiffel, Lua, Oz, Ruby |
if c then ... end if |
Ada, Maple |
if c then ... fi |
Maple |
if c; then ... fi |
BourneShell |
if (c) then ... end |
Dylan |
if c do ... |
BCPL |
IF c THEN ... END |
Modula-2, Modula-3 |
if (c) ... |
Awk, B, C, C#, C++, Java, JavaScript, PHP, Pike, YCP |
if c: ... |
Python |
if c ... |
Pliant, Rebol, Tcl |
if (c): ... endif |
PHP |
if c {...} |
Go, Perl6 |
if c [...] |
Logo |
if (c) {...} |
E, Perl, Yorick |
IF c ... |
MUMPS |
c -> ... |
FL |
c ... if |
PostScript |
... if c |
Perl, Ruby |
c if b1 then |
Forth |
(if c ...) |
Common Lisp, Scheme |
(when c ...) |
Emacs Lisp |
c and ... |
Perl, Ruby |
if(c, ...) |
Io |
If[c, ...] |
Mathematica |
if(c) then(...) |
Io |
c ifTrue(...) |
Io |
c ifTrue: ... |
Smalltalk |
<xsl:if test="c">...</xsl:if> |
XSLT |
if c ... endif |
Vimscript |
If c Then ... |
Visual Basic |
If c ... End If |
Visual Basic |
if c; ... end |
Ruby |
if c; ...; end |
FishShell |
if c, ..., end |
Matlab |
if c ... end |
Matlab, Ruby |
if c then ; ... if c then ... if c then do ... end |
Classic REXX |
c and ... |
Perl |
t label |
GNU-sed |
if c ... |
CoffeeScript |
- if_then_else
规则 | 语言 |
---|---|
if c then b1 else b2 |
CoffeeScript, F#, Haskell, merd, OCaml, SML |
if c then b1 else b2 end |
Eiffel, Lua, Ruby |
if c then b1 elsif c2 then b2 else b3 end if |
Ada |
if c then b1 elseif c2 then b2 else b3 end |
Eiffel, Oz |
if (c) then b1 elseif (c2) then b2 else b3 end |
Dylan |
IF c THEN b1 ELSIF c2 THEN b2 ELSE b3 END |
Modula-3 |
If c Then b1 ElseIf c2 Then b2 Else b3 End If |
Modula-2 |
if (c) b1 else b2 |
Awk, B, C, C#, C++, Java, JavaScript, Pike, YCP |
if c b1 elsif c2 b2 b3 |
Tcl |
if c then b1 elseif c2 then b2 else b3 |
Tcl |
if c then begin b1 end else begin b2 end |
Pascal |
if c b1 eif c2 b2 else b3 |
Pliant |
if c then b1 elif c2 then b2 else b3 end if |
Maple |
if c; then b1; elif c2; then b2; else b3; fi |
BourneShell |
if c; b1; else b2; end |
FishShell |
if c1, b1, elseif c2, b2, else, b3, end |
Matlab |
if (c) b1 elseif (c2) b2 else b3 |
PHP |
if (c): b1 elseif (c2): b2 else: b3 endif |
PHP |
if (c) {b1} elsif (c2) {b2} else {b3} |
Perl |
if (c) {b1} else {b2} |
E, Yorick |
(if c b1 b2) |
Common Lisp, Scheme |
(if c then b1 else b2) |
Mercury |
(c -> b1 ; c2 -> b2 ; b3) |
Mercury |
c -> b1 ; b2 |
FL |
if(c, b1, b2) |
Io |
If[c, b1, b2] |
Mathematica |
if(c) then(b1) else(b2) |
Io |
c ifTrue: b1 ifFalse: b2 |
Smalltalk |
ifelse c [b1] [b2] |
Logo |
shunt c b1 c2 b2 b3 |
Pliant |
either c b1 b2 / if/else c b1 b2 |
Rebol |
(cond (c b1) (c2 b2) (t b3)) |
Common Lisp, Emacs Lisp |
(cond (c b1) (c2 b2) (else b3)) |
Scheme |
Which[c, b1, c2, b2, True, b3] |
Mathematica |
c -> b1 ; c2 -> b2 ; b3 |
Prolog |
case when c; b1 when c2; b2 else b3 end |
Ruby |
test c then b1 or b2 |
BCPL |
e | c = b1 | c2 = b2 | otherwise = b3(47) |
Haskell |
c b1 b2 ifelse |
PostScript |
c if b1 else b2 then |
Forth |
c ? b1 : b2 |
Awk, B, C, C#, C++, Java, JavaScript, Perl, PHP, Ruby, Tcl, YCP, Yorick |
c ?? b1 !! b2 |
Perl6 |
b1 if c else b2(31) |
Python |
$SELECT(c:b1,c2:b2,1:b3) |
MUMPS |
c -> b1, b2 |
BCPL |
(if c then b1 else b2 fi) |
Beta |
<xsl:choose> <xsl:when test="c"> b1 </xsl:when> <xsl:when test="c2"> b2 </xsl:when> <xsl:otherwise> b3 </xsl:otherwise> </xsl:choose> |
XSLT |
if c1 ... elseif c2 ... else ... endif |
Vimscript |
If c Then b1 Else b2 |
Visual Basic |
If c b1 Else b2 End If |
Visual Basic |
if c: b1 elif c2: b2 else: b3 |
Python |
if c b1 elsif c2 b2 else b3 end |
Ruby |
if c b1 elseif c2 b2 else b3 end |
Matlab |
if c then ; b1 ; else ; b2 if c then b1 else b2 if c then do b1 ... end else do b2 ... end |
Classic REXX |
IF c ... ELSE ... |
MUMPS |
if c b1 else if c2 b2 else b3 |
CoffeeScript |
if c {b1} else if c2 {b2} else {b3} |
Go |
- ifnot_then (unless)
规则 | 语言 |
---|---|
unless |
CoffeeScript, Emacs Lisp, Perl |
ifFalse |
Smalltalk |
if(c) not then(...) |
Io |
- multiple selection (switch)
规则 | 语言 |
---|---|
switch (val) { case v1: ...; break; case v2: case v3: ...; break; default: ...; } |
C, C++, Java, JavaScript, PHP, Pike |
switch val { case v1: ...; goto done; case v2: case v3: ...; goto done; } ...; done: |
B |
switch (val) { case v1: ...; break; case v2: case v3: ...; break; default: ...; break; }(48) |
C# |
switch (val) { match v1 { ... } match v2 { ... } match _ { ... } } |
E |
switchon val case v1: ... case v2: ... default: ... |
BCPL |
switch val case v1 ... case v2 v3 ... case '*' ... end |
FishShell |
switch val case v1 ... case {v2,v3} ... otherwise ... end |
Matlab |
case val of v1 : ...; v2, v3 : ... else ... end |
Pascal |
switch val { v1 {...} v2 - v3 {...} default {...} } |
Tcl |
case val in v1) statement1 ;; v2|v3) statement23 ;; *) statement_else ;; esac |
BourneShell |
(if val // v1 then ... // v2 then ... else ... if) |
Beta |
match val with | v1 -> ... | v2 | v3 -> ... | _ -> ... |
F#, OCaml |
case val of v1 => ... | v2 => ... | _ => ... |
SML |
CASE val OF v1 => ... | v2 => ... ELSE => ... END |
Modula-3 |
case val of v1 -> ... v2 -> ... _ -> ... |
Haskell |
val case v1 of ... endof v2 of ... endof ... endcase |
Forth |
val. v1 -> ... v2 -> ... _ -> ... |
merd |
(case val ((v1) ...) ((v2) ...) (otherwise ...)) |
Common Lisp |
(case val ((v1) ...) ((v2) ...) (else ...)) |
Scheme |
case val is when v1 => ... when v2 | v3 => ... when others => ... end case; |
Ada |
case val when v1; ... when v2, v3; ... else ... end |
Ruby |
inspect val when v1 then statement1 when v2, v3 => statement23 else statement_else end |
Eiffel |
select (val); when (v1) statement1; when (v2, v3) statement23; otherwise statement_else; end; |
PL/I |
X = val, (X = v1, ... ; X = v2, ... ; ...) |
Mercury, Prolog |
my %case = ( v1 => sub { ... }, v2 => sub { ... }, ); if ($case{val}) { $case{val}->() } else { ... } |
Perl |
use Switch; switch ($val) { case v1 { ... } case v2 { ... } else ... })(49) |
Perl |
given $val { when v1 { ... } when v2 { ... } default { ... } } |
Perl6 |
Select val Case v1 ... Case v2, v3 ... Case Else ... End Select |
Visual Basic |
switch (val) { v1 { ... } v2 { ... } default { ... } } |
MSH |
switch val [ v1 [...] v2 [...] ] switch/default [ v1 [...] v2 [...] ][...] |
Rebol |
val caseOf: {[v1]->[...]. [v2]->[...]} otherwise: ... |
Squeak |
Switch[val, v1, ..., v2, ..., _, ...] |
Mathematica |
select when v1 ... when v2 | v3 ... otherwise ... end |
Classic REXX |
CASE val WHEN v1 THEN ... WHEN v2 THEN ... ELSE ... END |
SQL92 |
switch val { case v1, v2, ...: ... fallthrough case v3: ... default: ... } |
Go |
-
loop
forever loop |规则 | 语言 | | ———————- | ————– | |
loop
| CoffeeScript, merd, Perl6, PostScript, Ruby | |loop(...)
| Io | |loop ... end loop
| Ada | |LOOP ... END
| Modula-3 | |(loop do ...)
| Common Lisp | |cycle (# do ... #)
| Beta | |repeat
| Squeak | |begin ... again
| Forth | |forever
| Logo, Rebol | |Do ... Loop
| Visual Basic | |do forever ... end
| Classic REXX | |for {}
| Go |while condition do something |规则 | 语言 | | ———————- | ————– | |
while (c) ...
| Awk, B, C, C#, C++, E, Java, JavaScript, Perl, PHP, Pike, Ruby, YCP, Yorick | |while c ...
| CoffeeScript, Perl6, Tcl | |while c loop ... end loop
| Ada | |while c do ...
| BCPL, Pascal, SML | |while c do ... done
| F#, OCaml | |while c do ... end do
| Maple | |while c do ... end
| Lua | |WHILE c DO ... END
| Modula-3 | |while c: ...
| Python | |while c; do ...; done
| BourneShell | |while c; ...; end
| FishShell | |while c, ..., end
| Matlab | |while [c][...]
| Rebol | |while c [...]
| Logo | |while(c, ...)
| Io | |While[c, ...]
| Mathematica | |do.while [...] c
| Logo | |c whileTrue: ...
| Smalltalk | |(loop while c do ...)
| Common Lisp | |loop (# while ::< (# do c -> value #) do ... #)
| Beta | |begin c while ... repeat
| Forth | |from until not c loop ... end
| Eiffel | |while c ...
| Pliant | |while c do ...
| F# | |Do While c ... Loop
| Visual Basic | |while c ... endwhile
| Vimscript | |do while c ... end
| Classic REXX | |for c {...}
| Go |do something until condition |规则 | 语言 | | ———————- | ————– | |
do ... until c
| Perl6 | |do {...} until c
| Perl | |do ... while (!c)
| Awk, C, C#, C++, Java, JavaScript, Pike, Yorick | |begin ... end until c
| Ruby | |begin ... c until
| Forth | |REPEAT ... UNTIL c
| Modula-3 | |loop (# until ::< (# do c -> value #) do ... #)
| Beta | |loop ... exit when c; end loop
| Ada | |(loop do ... until c)
| Common Lisp | |... repeatuntil c
| BCPL | |repeat ... until c
| Lua, Pascal | |repeat ... until (c)
| YCP | |repeat, ..., c
| Prolog | |until [... c]
| Rebol | |until c [...]
| Logo | |do.while [...] c
| Logo | |While[...; c]
| Mathematica | |[...] whileFalse: [c]
| Smalltalk | |Do ... Loop Until c
| Visual Basic |for each value in a numeric range, 1 increment (see also the entries about ranges) |规则 | 语言 | | ———————- | ————– | |
for (int i = 1; i <= 10; i++) ...
| C, C#, C++ | |for (i = 1; i <= 10; i++) ...
| Awk, JavaScript | |for ($i = 1; $i <= 10; $i++) ...
| PHP | |foreach my $i (1 .. 10) { ... }
| Perl | |foreach ($i in 1..10) { ... }
| MSH | |for (1 .. 10) -> $i { ... }
| Perl6 | |for i = 1:10, ..., end
| Matlab | |for i = 1, 10 do ... end
| Lua | |for i := 1 to 10 do ...
| Pascal | |for i = 1 to 10 do ... done
| F#, OCaml | |For i = 1 To 10 ... Next
| Visual Basic | |for i in 1 .. 10 loop ... end loop
| Ada | |for i in 1 .. 10 do ... done
| F# | |for i in [1..10] ...
| CoffeeScript | |for i in xrange(1, 11)
| Python | |for i in (seq 10); ...; end
| FishShell | |FOR I=1:1:10 ...
| MUMPS | |for i from 1 to 10 do ... end do
| Maple | |for [i 1 10 +1] [...]
| Logo | |for {set i 1} {$i <= 10} {incr i} {...}
| Tcl | |1 1 10 ... for
| PostScript | |11 1 do ... loop
| Forth | |(1..10).each {|i| ... }
| Ruby | |1.upto(10) {|i| ... }
| Ruby | |1 to(10) foreach(...)
| Io | |1 to: 10 do: [...]
| Smalltalk | |(loop for i from 1 to 10 do ...)
| Common Lisp | |do label i = 1, 10
| Fortran | |Do[..., {i, 1, 10}](50)
| Mathematica | |do i = 1 for 10 ... end
| Classic REXX | |for i := 1; i <= 10; i++ {...}
| Go |for each value in a numeric range, 1 decrement |规则 | 语言 | | ———————- | ————– | |
for X := 10 downto 1 do ...
| Pascal | |for i = 10 downto 1 do ... done
| F#, OCaml | |for i in reverse 1 .. 10 loop ... end loop
| Ada | |for i in 10 .. -1 .. 1 do ... done
| F# | |for (int i = 10; i >= 1; i--) ...
| C, C#, C++ | |for (my $i = 10; $i >= 1; $i--) { ... }
| Perl | |loop (my $i = 10; $i >= 1; $i--) { ... }
| Perl6 | |for (i = 10; i >= 1; i--) ...
| Awk, JavaScript | |for ($i = 10; $i >= 1; $i--) ...
| PHP | |from i := 10 until i < 1 loop ... i := i - 1 end
| Eiffel | |for i = 10:-1:1, ..., end
| Matlab | |for i = 10, 1, -1 do ... end
| Lua | |For i = 10 To 1 Step -1 ... Next
| Visual Basic | |for i in xrange(10, 0, -1)
| Python | |for i in
seq 10 -1 1; do ...; done
| BourneShell | |for i in (seq 10 -1 1); ...; end
| FishShell | |for i from 10 to 1 by -1 do ... end do
| Maple | |for [i 1 10 -1] [...]
| Logo | |FOR I=10:-1:1 ...
| MUMPS | |for {set i 10} {$i >= 1} {incr i -1} {...}
| Tcl | |10 -1 1 ... for
| PostScript | |1 10 do ... -1 +loop
| Forth | |1 to: 10 by: -1 do: [...]
| Smalltalk | |10 to(1) foreach(...)
| Io | |10.downto(1) {|i| ... }
| Ruby | |(loop for i from 1 to 10 by -1 do ...)
| Common Lisp | |do label i = 10, 1, -1
| Fortran | |Do[..., {i, 10, 1, -1}]
| Mathematica | |do i = 10 to 1 by -1 ... end
| Classic REXX | |for i in [10..1] ...
| CoffeeScript | |for i := 10; i >= 1; i-- {...}
| Go |for each value in a numeric range, free increment |规则 | 语言 | | ———————- | ————– | |
for (int i = 1; i <= 10; i += 2) ...
| C, C#, C++, Pike | |for (i = 1; i <= 10; i += 2) ...
| Awk, JavaScript | |for ($i = 1; $i <= 10; $i += 2) ...
| PHP | |for (my $i = 1; $i <= 10; $i += 2) { ... }
| Perl | |loop (my $i = 1; $i <= 10; $i += 2) { ... }
| Perl6 | |from i := 1 until i > 10 loop ... i := i + 2 end
| Eiffel | |for i = 1:3:10, ..., end
| Matlab | |for i = 1, 10, 2 do ... end
| Lua | |For i = 1 To 10 Step 2 ... Next
| Visual Basic | |for i in 1 .. 2 .. 10 do ... done
| F# | |for i in xrange(1, 11, 2)
| Python | |for i in (seq 1 2 10); ...; end
| FishShell | |for i from 1 to 10 by 2 do ... end do
| Maple | |for [i 1 10 2] [...]
| Logo | |FOR I=1:2:10 ...
| MUMPS | |for {set i 0} {$i <= 10} {incr i 2} {...}
| Tcl | |1 2 10 ... for
| PostScript | |11 1 do ... 2 +loop
| Forth | |1 to: 10 by: 2 do: [...]
| Smalltalk | |(1..10).step(2) {|i| ... }
| Ruby | |1 to (9,2) foreach(...)
| Io | |(loop for i from 1 to 10 by 2 do ...)
| Common Lisp | |do label i = 1, 10, 2
| Fortran | |Do[..., {i, 1, 10, 2}]
| Mathematica | |do i = 1 to 10 by 2 ... end
| Classic REXX | |for i in [1..10] by 2 ...
| CoffeeScript | |for i := 1; i <= 10; i += 2 {...}
| Go |for “a la C” (while + initialisation) |规则 | 语言 | | ———————- | ————– | |
for
| Awk, C, C#, C++, Go, Java, JavaScript, Mathematica, MSH, Perl, PHP, Pike, Tcl, Yorick | |loop
| Perl6 | |for ((x = 0; x < 10; x++)); do ...; done
| BourneShell | |from init_code until c loop ... incr_statement end
| Eiffel | |(loop with VAR = INITIAL-VALUE ... while CONDITION finally INCREMENT ...)
| Common Lisp | -
breaking control flow
returning a value |规则 | 语言 | | ———————- | ————– | |
return(42)
| Ada, Awk, B, BCPL, BourneShell, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, E, FishShell, Go, Io, Java, JavaScript, Lua, Maple, Matlab, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, Tcl, Vimscript, YCP, Yorick | |Return
| Mathematica, Visual Basic | |RETURN
| Modula-3 | |resultis(43)
| BCPL | |return-from xxx
| Common Lisp | |^
| Smalltalk | |Exit Function / Exit Sub
| Visual Basic | |exit
| Forth | |output
| Logo |goto (unconditional jump)
规则 | 语言 |
---|---|
goto |
Ada, B, Basic, BCPL, C, C#, C++, Cobol, Fortran, Go, Logo, MUMPS, Pascal, Perl, PHP5, Yorick |
Goto |
Mathematica |
go throw |
Common Lisp |
signal |
Classic REXX |
b |
GNU-sed |
b, bra, jmp |
Assembler |
continue / break
规则 | 语言 |
---|---|
continue / break |
Awk, C, C#, C++, CoffeeScript, E, FishShell, Go, Io, Java, JavaScript, Matlab, PHP, Pike, Python, Tcl, YCP, Yorick |
Continue / Break |
Mathematica |
next / last |
Perl, Perl6 |
next / break(51) |
Maple, Ruby |
/ break |
BCPL, Lua |
/ break/return |
Rebol |
/ exit |
Ada, PostScript |
/ stop |
Logo |
restart / leave |
Beta, Pliant |
/ Exit Do, Exit For |
Visual Basic |
/ return-from xxx or return |
Common Lisp |
iterate / leave |
Classic REXX |
/ leave |
Forth |
redo / retry
规则 | 语言 |
---|---|
redo/ |
Perl, Perl6 |
redo / retry |
Io, Ruby |
-
exception
throwing
规则 | 语言 |
---|---|
raise |
Ada, Eiffel, F#, merd, OCaml, Python, Ruby, Scheme-SRFI34, SML |
RAISE |
Modula-3 |
raise ... end |
Oz |
Exception raise |
Io |
throw |
C#, C++, CoffeeScript, E, Erlang, Forth, Haskell, Java, JavaScript, Logo, PHP5, Pike, Prolog, Rebol |
Throw |
Mathematica |
throw/name |
Rebol |
die |
Perl, Perl6 |
return -code |
Tcl |
error |
Common Lisp, Dylan, Emacs Lisp, Lua, Lua, Maple, Matlab, Pliant, Yorick |
signal |
Common Lisp, Dylan, Smalltalk |
signal predefined_condition_name |
Classic REXX |
cerror warn |
Common Lisp |
[NSException raise:name ...] |
Objective-C |
panic(v) |
Go |
catching
规则 | 语言 |
---|---|
try: a except exn: ... |
Python |
try a with exn -> ... |
F#, OCaml |
try a catch (exn) ... |
C#, C++, Java, JavaScript |
try a ... catch exn ... |
CoffeeScript |
try { ... } catch(t $v) { ... } |
PHP5 |
try a catch exn then ... end |
Oz |
try a catch exn: ... end try |
Maple |
try(a) ; catch(...) |
Io |
try { a CATCH exn { ... } } |
Perl6 |
TRY a EXCEPT exn => ... END |
Modula-3 |
a handle exn => ... |
SML |
a on: exception_name do: [:exn | ...] |
Smalltalk |
ifCurtailed |
Smalltalk |
rescue |
Eiffel, Ruby |
eval {a}; if ($@) ... |
Perl |
exception when exception_name => |
Ada |
catch a (\exn -> ...) |
Haskell |
catch |
Erlang, Forth, Logo, Prolog, Rebol, Tcl |
Catch |
Mathematica |
catch/name |
Rebol |
catch(...) or catch { ... }; |
Pike |
if (catch(exn)) { ... } a |
Yorick |
pcall |
Lua |
with-exception-handler or guard |
Scheme-SRFI34 |
block a exception(exn) ... end |
Dylan |
?, shy, safe |
Pliant |
handler-bind handler-case ignore-errors |
Common Lisp |
NS_DURING a NS_HANDLER ... NS_ENDHANDLER |
Objective-C |
try a catch ... end |
Matlab |
signal on predefined_condition_name ... predefined_condition_name : ... |
Classic REXX |
recover() |
Go |
cleanup: code executed before leaving
规则 | 语言 |
---|---|
ensure |
Ruby, Smalltalk |
finally |
C#, F#, Java, Maple, Python |
FINALLY |
Modula-3 |
unwind-protect |
Common Lisp, Emacs Lisp |
cleanup |
Dylan |
dynamic-wind |
Scheme |
retrying: after catching an exception, tell the snippet to be re-run
规则 | 语言 |
---|---|
retry |
Eiffel, Ruby, Smalltalk |
restart |
Dylan |
resume execution where the exception took place
规则 | 语言 |
---|---|
resume |
Smalltalk |
- call-with-current-continuation
规则 | 语言 |
---|---|
call-with-current-continuation(52) |
Scheme |
callcc |
Ruby, SML-NJ |
Types
- declaration
规则 | 语言 |
---|---|
typedef t n |
C, C++, Pike |
type n is t |
Ada |
type n ... |
Pliant |
type n = t |
F#, Haskell, OCaml, Pascal, SML |
TYPE n = t |
Modula-3 |
using n = ... |
C# |
data n = t |
Haskell |
datatype n = t |
SML |
newtype n = t |
Haskell |
n = t |
merd, Python |
n : t |
Beta |
(deftype n () 't) |
Common Lisp |
type n t |
Go |
- annotation (or variable declaration)
规则 | 语言 |
---|---|
: |
Ada, E, Eiffel, F#, Modula-3, OCaml, Pascal, SML |
:: |
Dylan, Haskell, Mercury |
!! |
merd |
t v |
C, C#, C++, Java, Perl6, Pike, Pliant, YCP |
(declare (t v)) |
Common Lisp |
v :@ t |
Beta |
_t(53) |
Mathematica |
var n t |
Go |
-
cast
upcast |规则 | 语言 | | ———————- | ————– | |
(t) e
| C, C#, C++, Java, PHP | |t(e)
| Ada, Pascal | |[t] e
| Pike | |static_cast<t>(e)
| C++ | |e :> t
| OCaml | |e : t
| F# | |upcast e
| F# | |CAST(e as t)
| SQL92 | |typecast(e,t)
| Matlab | |(t)(e)
| Go |downcast (need runtime checking)
规则 | 语言 |
---|---|
(t) e |
Java |
t(e) |
Ada |
e : t |
E |
[t] e |
Pike |
dynamic_cast<t>(e) |
C++ |
e as t |
C# |
e :?> t |
F# |
downcast e(54) |
F# |
v ?= e(55) |
Eiffel |
NARROW(e, t) |
Modula-3 |
typecast(e,t) |
Matlab |
computed conversion (calls an internal or a user-defined function)
规则 | 语言 |
---|---|
(t) e |
C++, Pike |
[t] e |
MSH |
t(e) |
C++, Matlab, Python |
t e |
F# |
e : t |
E |
e :: t |
Haskell |
cast e t |
Pliant |
... cast t |
Pliant |
make t e / to t e |
Rebol |
-
mutability, constness
type of a mutable value
规则 | 语言 |
---|---|
mutability is the default |
C, C#, C++, Go, Java, Matlab |
val x: T |
Pascal |
T ref |
F#, OCaml, SML |
STRef a T |
Haskell |
in out T(56) |
Ada |
type of a constant value
|规则 | 语言 |
| ———————- | ————– |
| const T
| C++, C99 |
| constant T
| Ada |
| const x: T
| Pascal |
| constness is the default
| F#, Haskell, OCaml, SML |
| const e t
| Go |
special cases
规则 | 语言 |
---|---|
"readonly" fields(57) |
C# |
"final" fields, parameters, local variables(57) |
Java |
Object Oriented & Reflexivity
- method invocation
规则 | 语言 |
---|---|
object.method(para) |
Ada, Beta, C#, C++, Cecil, CoffeeScript, Delphi-Kylix, E, Eiffel, F#, Icon, Java, JavaScript, merd, Modula-3, MSH, Perl6, Python, Ruby, Sather, Visual Basic |
object#method para |
OCaml |
object:method(para) |
Lua |
object method(para) |
Io |
object method para |
Pliant, Tcl |
object method: para1 method_continuation: para2 |
Smalltalk |
object <- method(para)(58) |
E |
[ object method: para ] |
Objective-C |
object->method(para) |
C++, Perl, PHP, Pike |
object["method"](para) |
Pike |
object/method para |
Rebol |
method object para |
Haskell, Mercury |
(method object para) |
Common Lisp |
method(object, para) |
Ada, Dylan, Matlab |
para->method |
Beta |
(send object method para) |
MzScheme |
with no parameter
规则 | 语言 |
---|---|
object.method |
Ada, Eiffel, F#, merd, Perl6, Ruby |
object.property(59) |
C# |
object.method() |
C#, C++, CoffeeScript, E, Java, JavaScript, Python |
object#method |
OCaml |
object:method |
Pliant |
object->method |
Perl |
object->method() |
PHP5, Pike |
object/method |
Rebol |
object["method"]() |
Pike |
object method |
Io, Smalltalk |
[ object method ] |
Objective-C |
method object |
Haskell, Mercury |
(method object) |
Common Lisp |
method(object) |
Ada, Dylan, Matlab |
(send object method) |
MzScheme |
- object creation
规则 | 语言 |
---|---|
new |
PHP, Pliant, Simula |
new class_name(...) |
C#, C++, CoffeeScript, F#, Java, JavaScript, Perl, PHP, Visual Basic |
new class_name ... |
CoffeeScript, OCaml |
class_name.new(...) |
Perl6, Ruby |
class_name new |
Smalltalk |
class_name(...) |
F#, Matlab, Pike, Python |
class_name v(...) |
C++ |
v : class_name |
Ada |
class_name.Create |
Delphi-Kylix |
!class_name!constructor_name(...) |
Eiffel |
& |
Beta |
make-object |
MzScheme |
(make-instance class_name ...) |
Common Lisp |
[class_name alloc] |
Objective-C |
make class_name! ... |
Rebol |
def object_name { ... } |
E |
- object cloning
规则 | 语言 |
---|---|
o.clone |
Perl6 |
o.clone(60) |
Eiffel, Ruby |
o.deep_clone |
Eiffel |
o.clone() |
Java |
o.Clone() |
C# |
clone $o |
PHP5 |
o clone |
Io |
clone / copy or deepCopy |
Smalltalk |
Storable::dclone |
Perl |
[o copy] |
Objective-C |
copy.copy(o)(61) |
Python |
purecopy |
Emacs Lisp |
{< >} or Oo.copy o |
OCaml |
o2 = o(62) |
C++, Matlab, PHP |
$o2 = $o |
PHP |
o2.all := o.all |
Ada |
make o [] |
Rebol |
o_ : T'Class := o(63) |
Ada |
- manually call an object’s destructor
规则 | 语言 |
---|---|
delete |
C++, JavaScript |
destroy |
Pike |
DESTROY |
Perl |
dealloc |
Objective-C |
Dispose |
C#, F# |
del, __del__ |
Python |
__destruct |
PHP5 |
Requires instantiation of Ada.Unchecked_Deallocation |
Ada |
- class declaration
规则 | 语言 |
---|---|
class |
C#, C++, CoffeeScript, Haskell, Java, Matlab, MzScheme, OCaml, Perl6, PHP, Pike, Python, Ruby |
class c inherit p1 p2 ... feature decl decl ... end |
Eiffel |
defclass defstruct |
Common Lisp |
subclass |
Smalltalk |
struct |
C++ |
type |
Pliant |
type c is tagged record ... end record(64) |
Ada |
@interface c { ... } ... @end |
Objective-C |
: |
Beta |
type c() = class ... end |
F# |
type c() = ... |
F# |
- testing class membership
规则 | 语言 |
---|---|
isa |
Matlab, Perl |
is_a? kind_of? |
Ruby |
o.meta.isa |
Perl6 |
isKindOf(65) |
Smalltalk |
isKindOfClass |
Objective-C |
dynamic_cast |
C++ |
instanceof |
CoffeeScript, Java, JavaScript, PHP5 |
isinstance |
Python |
in |
Ada |
is |
C# |
is_a |
PHP |
:? |
F# |
Program.inherits or Program.implements |
Pike |
entry_type |
Pliant |
typep |
Common Lisp |
ISTYPE |
Modula-3 |
object## < classname## |
Beta |
type.accepts(object) / object =~ v : type |
E |
var ?= val(66) |
Eiffel |
- get the type/class corresponding to an object/instance/value
规则 | 语言 |
---|---|
class |
Matlab, Objective-C, Ruby, Smalltalk |
__class__ |
Python |
getClass |
Java |
get_class |
PHP |
GetType |
F# |
typeid |
C++ |
typeof |
C#, CoffeeScript, JavaScript |
type-of |
Common Lisp |
type |
Io |
ref |
Perl |
generator |
Eiffel |
meta |
Perl6 |
object_program |
Pike |
getAllegedType |
E |
- methods available
规则 | 语言 |
---|---|
methods |
Matlab, Ruby |
get_class_methods |
PHP |
getMethods |
Java |
get-member |
MSH |
indices |
Pike |
o.meta.getmethods |
Perl6 |
dir |
Python |
slotNames |
Io |
o.GetType().GetMethods() |
F# |
o class selectors / o class allSelectors |
Smalltalk |
o.__getAllegedType().getMessageTypes() |
E |
- inheritance
规则 | 语言 |
---|---|
child :< parent |
Beta |
class child : parent |
C#, C++ |
class child < parent end |
Ruby |
class child is parent { ... } |
Perl6 |
class child extends parent |
CoffeeScript, Java, PHP5 |
class child(parent): |
Python |
class child inherit parent end |
Eiffel |
parent subclass: child |
Smalltalk |
make parent ... |
Rebol |
inherit |
OCaml, Pike |
def child extends makeSuperObject(parent, ...) { ... } |
E |
type child is new parent with record ... end record |
Ada |
type child = inherit parent ... |
F# |
(defclass child (parent) ...) |
Common Lisp |
@interface child : parent { ... } ... @end |
Objective-C |
@ISA = qw(parent1 parent2) |
Perl |
clone , setProtos, setProto, prependProto, appendProto |
Io |
instance Parent Child where ... |
Haskell |
- has the method
规则 | 语言 |
---|---|
can |
Perl, Perl6 |
respond_to? |
Ruby |
respondsTo |
E, Smalltalk |
respondsToSelector |
Objective-C |
hasattr(obj, "meth")(67) |
Python |
object->method |
Pike |
all [in object 'method function? get in object 'method] |
Rebol |
find-method |
Common Lisp |
ismethod |
Matlab |
hasSlot |
Io |
try obj.GetType().GetMethod("meth") with ... |
F# |
obj.meth? instanceof Function |
CoffeeScript |
method_exists |
PHP5 |
- current instance
规则 | 语言 |
---|---|
this |
Beta, C#, C++, CoffeeScript, Java, JavaScript, PHP, Pike |
THIS |
Simula |
self |
Io, Objective-C, Rebol, Ruby, Smalltalk |
object_name if defined as: def object_name { ... } |
E |
Current |
Eiffel |
first parameter(68) |
Matlab, Perl, Pliant, Python |
the object variable |
F# |
dispatching parameter |
Ada, Common Lisp |
Me |
Visual Basic |
. |
Perl6 |
- accessing parent method
规则 | 语言 |
---|---|
super |
CoffeeScript, E, Java, Objective-C, Ruby, Smalltalk |
super(Class, self).meth(args) |
Python |
base |
C# |
resend |
Io |
Precursor |
Eiffel |
$o.SUPER::method(...) |
Perl6 |
$o->SUPER::method(...) |
Perl |
method(parent(dispatching-parameter)) |
Ada |
parent(dispatching-parameter).method |
Ada |
parent::method |
PHP5 |
call-next-method |
Common Lisp |
type foo2 = inherit foo as parent ... member ... = ... parent.meth |
F# |
- accessing child method
规则 | 语言 |
---|---|
inner |
Beta |
Package, Module
- package scope
规则 | 语言 |
---|---|
. |
Ada, C#, CoffeeScript, E, F#, Go, Haskell, Java, Modula-3, OCaml, Pascal, Python, Ruby, SML, Squeak |
: |
XML |
:: |
C++, merd, Perl, Ruby, Squeak, Tcl, YCP |
: ::(69) |
Common Lisp |
:- |
Maple |
' |
Perl |
``` | Mathematica |
__ |
Mercury |
/ |
Matlab |
- declare
规则 | 语言 |
---|---|
package p; |
Java, Perl |
namespace p { ... } |
C#, C++ |
namespace p ... |
F# |
namespace P; |
PHP5 |
namespace eval p ... |
Tcl |
module p where ... |
Haskell |
module P ... end |
Ruby |
module P = struct ... end |
OCaml |
{ module "p"; ... } |
YCP |
:- module(p) |
Prolog |
p = module() ... end module |
Maple |
(defpackage p ...) |
Common Lisp |
automatically done based on the file name |
OCaml, Python, Tcl8.5 |
package declare(70) |
Matlab |
Begin["p ”] … End[]` |
Mathematica |
BeginPackage["p ”] … EndPackage[]` |
Mathematica |
<node xmlns="namespace"> ... </node> |
XML |
package p is -- Declare public package members here private -- Declare private package members here end p; package body p is ... -- Define package implementation here end p; |
Ada |
package p |
Go |
selective export
|规则 | 语言 |
| ———————- | ————– |
| module p (name1, name2, ...) where ...
| Haskell |
| @ISA = qw(Exporter); @EXPORT = qw(name1 name2 ...);
| Perl |
| package p is ... end; package body p is ... end;
| Ada |
| p = module() export name1, name2, ...; ... end module
| Maple |
| (export 'name1 'name2)
| Common Lisp |
| attached to each name (public, private...)
| Java, Pike |
| namespace export name1
| Tcl |
| namespace p val name1 : type1 ...
| F# |
| append_features
| Ruby |
| module type PType = sig val name1 : type1 ... end module P : PType = struct ... end
| OCaml |
| all files in package directory are exported. files in /private sub-directory are not exported, but can be used by the package itself
| Matlab |
| __all__ = [ ... ]
| Python |
| Identifier is only exported if the first character of its name is an Unicode upper case letter; and the identifier is declared in the package block or it is a field name or method name. No other identifiers are exported
| Go |
-
import
everything into current namespace |规则 | 语言 | | ———————- | ————– | |
use p(71)
| Perl | |uses p
| Pascal | |using p
| C# | |using namespace p;
| C++ | |(use-package 'p)
| Common Lisp | |open p
| F#, OCaml | |import
| Pike | |import p
| Haskell | |IMPORT p;
| Modula-2 | |import p.*
| Java | |import "p"
| YCP | |from p import *
| Python | |with p; use p;
| Ada | |namespace import p *
| Tcl | |inherit c export {NONE} all end
| Eiffel | |include or even extend
| Ruby | |do
| Rebol | |addpath
| Matlab | |. p
| BourneShell | |source p
| BourneShell | |builtin -f /path/to/lib.so
| KornShell | |<< p
| Mathematica | |
Get[“p"]
| Mathematica | |Needs["p
”]| Mathematica | |
use P1\P;| PHP5 | |
use P1\P as Q;` | PHP5 |selectively
规则 | 语言 |
---|---|
import p (name1, name2, ...) |
Haskell |
import p.name1; import p.name2 |
Java |
(import '(p:name1 p:name2)) |
Common Lisp |
use p qw(name1 name2 ...) |
Perl |
from p import name1, name2, ... |
Python |
FROM p IMPORT name1, name2, ...; |
Modula-2 |
namespace import p name1 |
Tcl |
using p::name1; using p::name2; ... |
C++ |
with p; use type p.type1; ... |
Ada |
with(p[name1, name2,]) |
Maple |
def name := <import:p.name> |
E |
:- use_module(name1, name2, ...) |
Prolog |
package (ie. load the package)
规则 | 语言 |
---|---|
import p |
Python |
use p;(72) |
Perl |
require p |
Perl |
require "p" |
Ruby |
require, "p" |
Yorick |
(require 'p)(73) |
Common Lisp |
with p; |
Ada |
with(p) |
Maple |
package require p |
Tcl |
automatically done(74) |
Java, OCaml |
import "p" |
Go |
Strings
- type name
规则 | 语言 |
---|---|
char[] |
C |
char const[] |
C++ |
string |
C#, C++, F#, Go, Maple, OCaml, Pascal, PHP, Pike, SML, Vimscript, YCP |
string! |
Rebol |
String |
Ada, C#, CoffeeScript, Haskell, Java, JavaScript, merd, Ruby, Smalltalk, Visual Basic |
STRING |
Eiffel |
str |
Python, YAML |
Str |
Perl6, Pliant |
NSString * |
Objective-C |
CHAR, VARCHAR(size) |
SQL92 |
Sequence |
Io |
- character type name
规则 | 语言 |
---|---|
char |
C, C#, C++, F#, OCaml, SML |
char! |
Rebol |
Char |
Haskell, merd, Perl6 |
Character |
Ada, Smalltalk |
CHARACTER |
Eiffel |
rune |
Go |
- character “z”
规则 | 语言 |
---|---|
'z' |
Ada, B, C, C#, C++, Classic REXX, E, Eiffel, F#, Go, Haskell, Matlab, OCaml, Pascal, Pike |
"z" |
BourneShell, Classic REXX, Maple, merd |
"z |
Logo |
$z |
Smalltalk |
#\z |
Common Lisp, Scheme |
#"z" |
Rebol, SML |
&z |
Oz |
?z |
Emacs Lisp, Ruby |
char z, [char] z(75) |
Forth |
-
strings
with no interpolation of variables |规则 | 语言 | | ———————- | ————– | |
'...'
| Beta, BourneShell, Classic REXX, CoffeeScript, CSS, FishShell, JavaScript, Lua, Matlab, Pascal, Perl, Perl6, PHP, Prolog, Python, Ruby, Smalltalk, SQL92, Vimscript, XPath, YAML | |"..."
| Ada, Awk, C, C#, C++, Classic REXX, Common Lisp, CSS, Dylan, E, Eiffel, Emacs Lisp, F#, FL, Go, Haskell, Io, Java, JavaScript, Lua, Maple, Mathematica, Modula-3, MUMPS, OCaml, Oz, Pike, Pliant, Prolog, Python, Rebol, Scheme, SML, XPath, YAML, YCP | |"...
| Logo | |'''...'''
| Python | |"""..."""
| Io, Python | |[[ ... ]]
| Lua | |R"[ ... ]"
| C++-0x | |<<'MARK' ... MARK
| BourneShell, Perl, Ruby | |<<<'MARK' ... MARK(76)
| PHP5 | |{...{...}...}
| Tcl | |(...)
| PostScript | |q(...(...)...), q[...], q{...}, q<...>, q/.../
| Perl, Perl6 | |%q(...(...)...), %q[...], %q{...}, %q<...>, %q/.../
| Ruby | |q(...(...)...)
| merd | |@"...""..."
| C# | |s"..."
| Forth | |@"..."
| Objective-C |with interpolation of variables |规则 | 语言 | | ———————- | ————– | |
...(77)
| Tcl | |"... $v ..."
| BourneShell, FishShell, Perl, Perl6, PHP, Tcl | |"... {v} ..."
| merd | |"... #{v} ..." "... #$v ..." "... #@v ..." "... #@@v ..."
| CoffeeScript, Ruby | |<<MARK ... $v ... MARK
| BourneShell, Perl | |<<MARK ... #{v} ... MARK
| Ruby | |<<<MARK ... $v ... MARK
| PHP | |qq(...(... $v ...)...), qq[...], qq{...}, qq<...>, qq/.../
| Perl, Perl6 | |%Q(...(... #{v} ...)...), %Q[...], %Q{...}, %Q<...>, %Q/.../
| Ruby | |qq(...(... {v} ...)...)
| merd | |"... #{v} ..." interpolate
| Io | |"... %(v)s ..." % vars()
| Python |end-of-line (without writing the real CR or LF character)
规则 | 语言 |
---|---|
\n |
Tcl |
"\n" |
C, C#, C++, CoffeeScript, FishShell, Go, Haskell, Io, Java, JavaScript, Lua, Maple, Mathematica, OCaml, Perl, Perl6, PHP, Pike, Python, Ruby, YCP, Yorick |
"*n" |
B, BCPL |
"%N" |
Eiffel |
"^/" |
Rebol |
"~%"(78) |
Common Lisp |
"[lf]" |
Pliant |
vb_nl |
Visual Basic |
<N>(79) |
Smalltalk |
- multi-line
规则 | 语言 |
---|---|
all strings allow multi-line strings |
BourneShell, Common Lisp, E, Emacs Lisp, F#, FishShell, Io, Maple, Mathematica, OCaml, Pascal, Perl, Perl6, PHP, Ruby, Scheme, Smalltalk, YCP |
"...", {...} |
Tcl |
@"..." |
C# |
'''...''', """...""" |
Python |
[[ ... ]] |
Lua |
{...} |
Rebol |
"...\n" "...\n" |
C |
... "...\n\ \...\n" |
Haskell |
"...", "..." |
Classic REXX |
"...%N% %...%N" |
Eiffel |
""" ... """ |
CoffeeScript |
... |
Go |
- convert something to a string (see also string interpolation)
规则 | 语言 |
---|---|
show |
Haskell |
to_s, to_str, inspect, String() |
Ruby |
to_string |
merd, Pliant |
tostring |
Lua, YCP |
toString |
CoffeeScript, Java, JavaScript |
ToString |
C#, F#, Mathematica |
String |
CoffeeScript, JavaScript |
perl |
Perl6 |
Dumper |
Perl |
"" . e |
Perl |
"" ~ e |
Perl6 |
"" + e |
CoffeeScript, E, Java, JavaScript |
string |
Pliant, Vimscript |
str, e, repr |
Python |
out |
Eiffel |
cvs |
PostScript |
T'Image(e)(80) |
Ada |
asString |
Io, Smalltalk |
printString |
Smalltalk |
as(<string>, e) |
Dylan |
(string) e |
PHP, Pike |
convert(e,string) |
Maple |
(coerce e 'string) |
Common Lisp |
prin1-to-string |
Emacs Lisp |
to string! / to-string / to "" |
Rebol |
description |
Objective-C |
pr1 |
Yorick |
unneeded, all values are strings |
Tcl |
string(e) |
Go |
- serialize (marshalling)
规则 | 语言 |
---|---|
export-clixml |
MSH |
serialize |
Io, PHP |
Marshal.to_string |
OCaml |
Marshal.dump |
Ruby |
Data.Binary.encode |
Haskell |
BinaryFormatter.Serialize |
F# |
storeBinaryOn |
Smalltalk |
Storable::store |
Perl |
pickle.dump(81) |
Python |
(with-standard-io-syntax (write obj stream)) |
Common Lisp |
T'Output(80) |
Ada |
- unserialize (un-marshalling)
规则 | 语言 |
---|---|
import-clixml |
MSH |
unserialize |
PHP |
Marshal.from_string |
OCaml |
Marshal.load |
Ruby |
Data.Binary.decode |
Haskell |
BinaryFormatter.Deserialize |
F# |
readBinaryFrom |
Smalltalk |
pickle.load |
Python |
(with-standard-io-syntax (read obj stream)) |
Common Lisp |
Storable::store |
Perl |
doString |
Io |
T'Input(80) |
Ada |
- sprintf-like
规则 | 语言 |
---|---|
sprintf |
Awk, C, C++, F#, Maple, Matlab, merd, OCaml, Perl, Perl6, PHP, Pike, Ruby |
printf |
Haskell |
% |
Python, Ruby |
format |
Java, Lua, Tcl |
format(82) |
Common Lisp, Erlang, Scheme-SRFI28 |
Format |
C#, F# |
putFormat |
Beta |
stringWithFormat |
Objective-C |
expandMacrosWith(82) |
Smalltalk |
Storable::retrieve |
Perl |
fmt.Sprintf |
Go |
-
simple print
on strings |规则 | 语言 | | ———————- | ————– | |
puts
| C, Dylan, Tcl | |print
| Awk, Basic, Java, Maple, merd, PHP, SML | |write
| JavaScript, Pascal, Pike, Yorick | |putStr
| Haskell | |print_string
| F#, OCaml | |console
| Pliant | |writeln
| JavaScript, Pascal | |write-string
| Common Lisp | |putStrLn
| Haskell | |Put_Line
| Ada | |display
| Cobol | |message
| Emacs Lisp | |put_string
| Eiffel | |show
| Smalltalk | |print_endline(83)
| OCaml | |println(83)
| Java, merd | |put_chars
| Erlang | |echo(84)
| BourneShell, FishShell, PHP | |type
| Forth | |putText
| Beta | |say
| Classic REXX | |p or i
| GNU-sed | |fmt.Print
| Go | |echom
| Vimscript |on simple objects |规则 | 语言 | | ———————- | ————– | |
print
| Perl, Perl6 | |say(83)
| Perl6 | |puts(83)
| Tcl | |puts -nonewline
| Tcl |on any objects |规则 | 语言 | | ———————- | ————– | |
print
| Io, Logo, Lua, Ruby | |print(83)
| Dylan, Haskell, Python, Rebol | |Print
| Mathematica | |print e,
| Python | |println(83)
| Io | |prin
| Rebol | |Put
| Ada | |p(83)
| Ruby | |puts(85)
| Ruby | |display
| Scheme | |write
| Common Lisp, Io, Prolog, Scheme | |writeln(83)
| Io | |print
| Common Lisp | |printOn
| Smalltalk | |princ prin1
| Common Lisp, Emacs Lisp | |print_any
| F# | |WriteLine
| C#, F# | |nothing - just remove ";" at the end of the expression, and it will print it
| Matlab | |disp
| Matlab |printf-like |规则 | 语言 | | ———— | ———————————————————— | |
printf
| Awk, C, C++, F#, Haskell, KornShell, Maple, Matlab, merd, OCaml, Perl, PHP, Ruby | |write
| Pike | |WriteLine
| C# | |putFormat
| Beta | |format(82)
| Common Lisp, Prolog | |fmt.Printf
| Go | -
string equality & inequality
规则 | 语言 |
---|---|
eq ne |
Perl, Perl6, Tcl |
strcmp |
C, Matlab |
== !=(Vimscript: whether or not == and != are case-sensitive depends on user settings.) |
CoffeeScript, Go, JavaScript, Pike, Vimscript |
==? !=?(86) |
Vimscript |
==# !=#(87) |
Vimscript |
== !== |
PHP |
== ~= |
Lua |
= \= |
Prolog |
isEqualToString(88) |
Objective-C |
== != |
Awk, C#, C++, E, Io, merd, Python, Ruby, YCP |
== <> |
Python |
== /= |
Haskell |
== \= |
Oz |
= != |
BourneShell, FishShell, Maple, XPath |
= /= |
Ada |
= \= |
Classic REXX |
= <> |
Beta, F#, OCaml, Pliant, SML, Visual Basic |
= ~= |
Dylan, Smalltalk |
== \== or = <> \= |
Classic REXX |
=== =!= / == !=(20) |
Mathematica |
== ~= |
Matlab |
equal? |
Ruby, Scheme |
equals |
Java |
equal, equalp |
Common Lisp |
is_equal |
Eiffel |
isEqual |
Objective-C |
- string size
规则 | 语言 |
---|---|
length |
Awk, Beta, C++, CoffeeScript, Common Lisp, Eiffel, F#, Haskell, Java, JavaScript, Maple, Matlab, Objective-C, OCaml, Perl, PostScript, Prolog, Ruby |
LENGTH |
Classic REXX |
'Length |
Ada |
length? |
Rebol |
size |
C++, E, Io, Ruby, Smalltalk, SML, YCP |
Length |
C#, F#, Modula-3, Oz, Pascal |
len |
Go, Pliant, Python, Vimscript, Visual Basic |
strlen |
C, PHP, Vimscript |
string length |
Tcl |
string-length |
Scheme, XPath |
StringLength |
Mathematica |
sizeof |
Pike |
count |
Eiffel, Logo |
bytes chars |
Perl6 |
CHARACTER_LENGTH |
SQL92 |
atom_length |
Prolog |
wc -c |
FishShell |
# |
Lua |
${#v} |
BourneShell |
dup(89) |
Forth |
- string concatenation
规则 | 语言 |
---|---|
+ |
C#, C++, CoffeeScript, E, Eiffel, F#, Go, Java, JavaScript, merd, MSH, Pascal, Pike, Pliant, Python, Ruby, YCP |
. |
Perl, PHP, Vimscript |
.. |
Io, Lua |
, |
Smalltalk |
~ |
D, Perl6 |
& |
Ada, Modula-3, Visual Basic |
^ |
F#, OCaml, SML |
_ |
MUMPS |
|| |
Cecil, Classic REXX, Icon, Maple, PL/I, SQL92 |
++ |
Haskell |
$a$b |
BourneShell, FishShell, Tcl |
concatenate |
Common Lisp, Dylan |
string-append |
Scheme |
StringJoin |
Mathematica |
cat |
Maple |
Cat |
Modula-3 |
strcat |
C |
concat |
XPath |
append |
Beta, Prolog, Rebol |
stringByAppendingString |
Objective-C |
`` | Awk, Classic REXX |
[string1 string2] |
Matlab |
word |
Logo |
- duplicate n times
规则 | 语言 |
---|---|
* |
Ada, E, Pike, Python, Ruby |
x |
Perl, Perl6 |
times |
merd |
repeat |
Pliant |
repeated |
Io |
str_repeat |
PHP |
string repeat |
Tcl |
strrep |
Lua |
repmat |
Matlab |
insert/dup |
Rebol |
COPIES |
Classic REXX |
cat(s$n) |
Maple |
concat $ replicate |
Haskell |
strings.Repeat |
Go |
- upper / lower case character
规则 | 语言 |
---|---|
upcase / downcase |
Emacs Lisp, Ruby |
uc / lc |
Perl, Perl6 |
upper / lower(90) |
Lua, Matlab, Pliant, Python |
toUpper / toLower |
Haskell |
to_upper / to_lower |
Eiffel |
To_Upper / To_Lower |
Ada |
toUpperCase / toLowerCase |
CoffeeScript, E, Java, JavaScript |
upper_case / lower_case |
Pike |
uppercase / lowercase |
F#, Logo, OCaml |
strupper / strlower |
Lua |
strtoupper / strtolower |
PHP |
ToUpper / ToLower |
C#, F#, Oz |
toupper / tolower |
Awk, C, C++ |
string toupper / string tolower |
Tcl |
asLowercase / asUppercase |
Io, Smalltalk |
upCase / lowCase |
Beta |
uppercase form / lowercase form |
Rebol |
char-upcase / char-downcase |
Common Lisp, Scheme |
char_type(C_, to_upper(C)), char_type(C_, to_lower(C)) |
Prolog |
\U / \L / \C |
GNU-sed |
unicode.ToUpper / unicode.ToLower |
Go |
- uppercase / lowercase / capitalized string
规则 | 语言 |
---|---|
upcase / downcase |
Emacs Lisp, Ruby |
upper / lower |
Matlab, SQL92 |
upper / lower / capitalize |
Python |
uppercase/lowercase |
F#, Logo, OCaml, Rebol |
upcase_atom/downcase_atom |
Prolog |
toUpperCase / toLowerCase |
CoffeeScript, E, Java, JavaScript |
ToUpperCase / ToLowerCase |
Mathematica |
ToUpper / ToLower |
C#, F# |
to_upper / to_lower |
Ada, Eiffel |
toupper / tolower |
Awk, YCP |
uc / lc |
Perl, Perl6 |
UpperCase / LowerCase |
Pascal |
StringTools[UpperCase] / StringTools[LowerCase] / StringTools[Capitalize] |
Maple |
uppercaseString / lowercaseString / capitalizedString |
Objective-C |
UCase / LCase |
Visual Basic |
strtoupper / strtolower |
PHP, Yorick |
strupper / strlower |
Lua |
string toupper / string tolower / string totitle |
Tcl |
string-upcase / string-downcase |
Common Lisp, Scheme |
asLowercase / asUppercase / asUppercaseFirst |
Smalltalk |
asLowercase / asUppercase / makeFirstCharacterUppercase |
Io |
upcase_atom / downcase_atom |
Prolog |
makeLC / makeUC |
Beta |
parse upper var in_var out_var / parse lower var in_var out_var |
Classic REXX |
strings.ToUpper / strings.ToLower / strings.Title |
Go |
- ascii to character
规则 | 语言 |
---|---|
chr |
F#, Haskell, OCaml, Pascal, Perl, Perl6, PHP, Python, Ruby, SML |
chr$ |
Visual Basic |
char |
Matlab |
format %c $c |
Tcl |
toChar |
E |
strchar |
Lua |
from_integer |
Eiffel |
fromCharCode |
CoffeeScript, JavaScript |
FromCharacterCode |
Mathematica |
character |
Pliant |
Character value: c |
Smalltalk |
asCharacter |
Io |
code-char |
Common Lisp |
integer->char |
Scheme |
'Val |
Ada |
(char) c |
C, C#, C++, Java |
to char! / to-char |
Rebol |
X2C, D2C |
Classic REXX |
$CHAR(s) |
MUMPS |
char_code |
Prolog |
ascii |
Logo |
StringTools[Char] |
Maple |
utf8.DecodeRuneInString(s) |
Go |
- character to ascii
规则 | 语言 |
---|---|
ord |
F#, Haskell, Pascal, Perl, Perl6, PHP, Python, SML |
asc |
Visual Basic |
getNumericValue |
Java |
charCodeAt |
CoffeeScript, JavaScript |
asciiValue |
Smalltalk |
code |
Eiffel, OCaml |
char-code |
Common Lisp |
char->integer |
Scheme |
s[0] |
Ruby |
s 0 get |
PostScript |
s at(0) |
Io |
scan $s %c |
Tcl |
strbyte |
Lua |
toInteger |
E |
'Pos |
Ada |
number |
Pliant |
(int) c |
C, C#, C++, Java |
to integer! / to-integer |
Rebol |
ToCharacterCode |
Mathematica |
C2X, C2D |
Classic REXX |
$ASCII(s) |
MUMPS |
(done automatically when applying mathematical operations on char, such as +) |
Matlab |
char |
Logo |
char_code |
Prolog |
StringTools[Ord] |
Maple |
string(c) |
Go |
- accessing n-th character
规则 | 语言 |
---|---|
s[n] |
C, C#, C++, E, Go, Maple, PHP, Pike, Python, Ruby, Vimscript |
s(n) |
Ada, Matlab |
s:n |
Pliant |
s.[n] |
F#, OCaml |
s !! n |
Haskell |
s @ n |
Eiffel |
s/:n |
Rebol |
string index s n |
Tcl |
sub |
SML |
char, aref, schar, svref |
Common Lisp |
GetChar |
Modula-3 |
s at(n) |
Io |
at(91) |
C++, Smalltalk |
aref |
Common Lisp |
char(s, i) |
B |
charAt |
CoffeeScript, Java, JavaScript |
characterAtIndex |
Objective-C |
n -> s.inxGet |
Beta |
string-ref |
Scheme |
StringTake[s, {n}] |
Mathematica |
$EXTRACT(s, n) |
MUMPS |
item |
Logo |
over n chars + c@ |
Forth |
s/.{n}(.).*/\1/ |
GNU-sed |
- extract a substring
规则 | 语言 |
---|---|
s[n..m] |
CoffeeScript, Maple, Pike, Ruby |
s.[n..m] |
F# |
s(n..m) |
Ada |
s(n:m) |
Matlab |
s(n,m+1) |
E |
s[n:m+1] |
Go, Python, Vimscript |
s[n,len] |
Ruby |
s n len |
Pliant |
strndup(s + n, len) |
C |
substring |
Eiffel, Java, Scheme, SML, XPath, YCP |
Substring |
C# |
substr |
C++, Perl, Perl6, PHP |
SUBSTR |
Classic REXX |
sub |
F#, Lua, OCaml |
SUB |
Modula-3 |
subseq |
Common Lisp |
slice |
CoffeeScript, Io, JavaScript |
mid$ |
JavaScript |
string range |
Tcl |
StringTake[s, {n, m}] |
Mathematica |
strpart(s, n, m) |
Yorick |
copy/part at s n len |
Rebol |
copy/part at s n at s m |
Rebol |
s copyFrom: n to: m |
Smalltalk |
(n,m)->s.sub |
Beta |
[s substringWithRange:NSMakeRange(n, len)] |
Objective-C |
SUBSTRING(s FROM n len) |
SQL92 |
$EXTRACT(s, n, m) |
MUMPS |
sub_string / sub_atom |
Prolog |
(take len . drop n) s |
Haskell |
over n chars + len |
Forth |
s/.{n}(.{len}).*/\1/ |
GNU-sed |
- locate a substring
规则 | 语言 |
---|---|
index |
Ada, Perl, Perl6, Python, Ruby |
indexOf |
CoffeeScript, Java, JavaScript |
IndexOf |
C#, F# |
indexOfString |
Smalltalk |
startOf |
E |
search |
Common Lisp, Pike, PostScript |
StringTools[Search] |
Maple |
StringPosition |
Mathematica |
strstr strchr |
C |
find |
C++, Logo, Lua, Python, Rebol, YCP |
findSeq |
Io |
findSubstring |
Haskell |
strfind |
Matlab, Yorick |
strpos |
PHP |
$FIND |
MUMPS |
index_non_blank / find_token |
Ada |
substring_index |
Eiffel |
rangeOfString |
Objective-C |
POS |
Classic REXX |
POSITION(needle IN s) |
SQL92 |
sub_string / sub_atom |
Prolog |
string first |
Tcl |
strings.Index |
Go |
- locate a substring (starting at the end)
规则 | 语言 |
---|---|
rindex |
OCaml, Perl, Perl6, Python, Ruby |
rfind |
C++, Python |
find/last |
Rebol |
strrchr |
C |
index(Going => Backward) |
Ada |
lastStartOf |
E |
lastIndexOf |
CoffeeScript, Java, JavaScript |
last_index_of(92) |
Eiffel |
LastIndexOf |
C#, F# |
lastIndexOfString |
Smalltalk |
string last |
Tcl |
(search substring string :from-end t) |
Common Lisp |
[string rangeOfString:substring options:NSBackwardsSearch] |
Objective-C |
LASTPOS |
Classic REXX |
t=strfind(s,p), t(end) |
Matlab |
strrpos |
PHP |
StringTools[SearchAll](s,p)[-1] |
Maple |
strings.LastIndex |
Go |
Booleans
- type name
规则 | 语言 |
---|---|
Bool |
Haskell, Perl6, Pliant |
bool |
C#, C++, C99, F#, Go, OCaml, PHP, Python, SML, YAML |
Boolean |
Ada, Lua, Pascal, Smalltalk, Visual Basic |
boolean |
CoffeeScript, Common Lisp, Java, JavaScript, Maple, PHP, YCP |
BOOLEAN |
Eiffel |
logic! |
Rebol |
logical |
Matlab |
- false value
规则 | 语言 |
---|---|
false |
Ada, BCPL, Beta, BourneShell, C#, C++, C99, CoffeeScript, E, F#, FL, Forth, Go, Io, Java, JavaScript, Logo, Lua, Maple, Matlab, OCaml, Oz, Pascal, PHP, Pliant, PostScript, Rebol, Ruby, Smalltalk, SML, Tcl, YAML, YCP |
False |
Eiffel, Haskell, Mathematica, merd, Python, Visual Basic |
FALSE |
Modula-3, SQL92 |
false() |
XPath |
#f |
Dylan, Scheme |
n |
YAML |
nil |
Common Lisp, Emacs Lisp, Io, Lua, Ruby |
no |
CoffeeScript, Tcl, YAML |
No |
Prolog |
none |
Rebol |
None |
Python |
null |
CoffeeScript, JavaScript |
NULL |
C, C++, C99, PHP |
off |
CoffeeScript, Tcl, YAML |
undef |
Perl, Perl6 |
undefined |
CoffeeScript, JavaScript |
fail |
Prolog |
FAIL |
Maple |
array containing at least one false value |
Matlab |
exit status different from 0 |
BourneShell |
0(93) |
Awk, B, C, C++, C99, Classic REXX, CoffeeScript, Forth, JavaScript, Matlab, MUMPS, Perl, Perl6, PHP, Pike, Python, Tcl, Visual Basic, XPath, Yorick |
0.0 |
Matlab, Perl, PHP |
NaN |
CoffeeScript, JavaScript, XPath |
"" |
Awk, CoffeeScript, JavaScript, Perl, Perl6, PHP, Python, XPath |
"0" |
Awk, Perl, Perl6, PHP |
'' |
CoffeeScript, Matlab, Perl |
'\0' |
C, C++, C99 |
() |
Perl, Perl6, Python |
[] |
Matlab, Python |
{} |
Matlab, Python |
array() |
PHP |
- true value
规则 | 语言 |
---|---|
TRUE |
Modula-3, SQL92 |
True |
Eiffel, Haskell, Mathematica, merd, Python, Visual Basic |
true |
Ada, BCPL, Beta, BourneShell, C#, C++, CoffeeScript, E, F#, FL, Forth, Go, Io, Java, JavaScript, Logo, Maple, OCaml, Oz, Pascal, PHP, Pliant, PostScript, Prolog, Rebol, Ruby, Smalltalk, SML, Tcl, YAML, YCP |
true() |
XPath |
t |
Common Lisp, Emacs Lisp |
#t |
Dylan, Scheme |
y |
YAML |
yes |
CoffeeScript, Tcl, YAML |
Yes |
Prolog |
on |
CoffeeScript, Tcl, YAML |
exit status 0 |
BourneShell |
anything not false |
Awk, B, C, C++, Common Lisp, Dylan, Emacs Lisp, Matlab, MUMPS, Perl, Perl6, Pike, Python, Rebol, Ruby, Scheme, XPath, Yorick |
1 |
Classic REXX, MUMPS |
non zero number |
Tcl |
non-zero-numbers |
Visual Basic |
-1 |
Forth |
- logical not
规则 | 语言 |
---|---|
! |
Awk, B, C, C#, C++, CoffeeScript, E, Go, Java, JavaScript, Mathematica, Perl, Perl6, PHP, Pike, Ruby, Tcl, Vimscript, YCP, Yorick |
not(94) |
Ada, Beta, CoffeeScript, Common Lisp, Eiffel, Emacs Lisp, F#, Haskell, Io, Logo, Lua, Maple, merd, OCaml, Pascal, Perl, Perl6, Pliant, PostScript, Prolog, Python, Rebol, Ruby, Scheme, Smalltalk, SML, XPath |
Not |
Oz, Visual Basic |
NOT |
Modula-3 |
~ |
BCPL, Dylan, Matlab, PL/I |
^ |
PL/I |
' |
MUMPS |
\ |
Classic REXX |
=0 |
Forth |
-
logical or / and
short circuit |规则 | 语言 | | ——————– | ———————————————————— | |
|| / &&
| Awk, C, C#, C++, CoffeeScript, E, F#, Go, Haskell, Java, JavaScript, Mathematica, Matlab, merd, OCaml, Perl, Perl6, PHP, Pike, Ruby, Tcl, Vimscript, YCP, Yorick | || / &
| B, BCPL, Dylan | |or / and
| CoffeeScript, Common Lisp, Emacs Lisp, Io, Logo, Lua, Modula-2, Perl, Perl6, PHP, Pliant, Python, Ruby, Scheme, Smalltalk | |OR / AND
| Modula-3 | |or / &(95)
| Modula-2 | |any / all
| Rebol | |orelse / andalso
| SML | |orelse / andthen
| Oz | |or else / and then
| Ada, Eiffel | |; / ,
| Prolog | |& / !
| MUMPS |non short circuit (always evaluates both arguments) |规则 | 语言 | | ————– | ———————————————————— | |
| / &
| C#, Classic REXX, Java, Matlab, Smalltalk | |or / and
| Ada, Beta, Eiffel, Maple, Pascal, PostScript, Rebol, SML, XPath | |Or / And(96)
| Oz, Visual Basic | |\/ / /\(15)
| BCPL | |?| /
| Perl6 |
Bags and Lists
- type name
规则 | 语言 |
---|---|
seq |
YAML |
a list |
F#, OCaml, SML |
[a] |
Haskell |
a[] |
C# |
list |
Maple, Python |
List |
Io, Mathematica, Pliant |
Array or List |
Perl6 |
ARRAY or LINKED_LIST |
Eiffel |
Array or OrderedCollection |
Smalltalk |
ARRAY |
Perl |
array |
PHP |
cell |
Matlab |
vector |
C++ |
Containers.Vectors.Vector or Ada.Containers.Doubly_Linked_Lists.List |
Ada |
[]a |
Go |
- list concatenation
规则 | 语言 |
---|---|
+ |
E, Eiffel, merd, PHP, Pike, Python, Ruby, Vimscript |
, |
Maple, Matlab, Perl, Smalltalk |
@ |
F#, OCaml, SML |
~ |
D |
& |
Ada |
++ |
Haskell |
||| |
Icon |
array_merge |
PHP |
merge |
YCP |
concat |
CoffeeScript, JavaScript, Tcl |
concatenate |
Dylan |
nconc |
Common Lisp, Emacs Lisp |
append |
Beta, Common Lisp, Emacs Lisp, Go, Prolog, Rebol, Scheme |
Append |
Oz |
appendSeq |
Io |
arrayByAddingObjectsFromArray |
Objective-C |
sentence |
Logo |
Join |
Mathematica |
-
list flattening
one level depth |规则 | 语言 | | ———————— | ——————————– | |
concat
| F#, Haskell, Mercury, SML | |flatten
| F#, Io, merd, OCaml, Prolog, YCP | |Flatten
| Oz | |eval concat
| Tcl | |ListTools[FlattenOnce]
| Maple | |{*}$l
| Tcl8.5 | |"$l"
| FishShell |recursive |规则 | 语言 | | ——————– | ———– | |
flatten
| Pike, Ruby | |ListTools[Flatten]
| Maple | |Flatten
| Mathematica | -
list constructor
规则 | 语言 |
---|---|
[ a, b, c ](97) |
CoffeeScript, E, Haskell, JavaScript, Maple, Matlab, merd, Perl, Perl6, PHP5, PostScript, Prolog, Python, Ruby, SML, Vimscript, YAML, YCP |
( a, b, c ) |
Perl, Perl6 |
{ a, b, c }(98) |
C, C++, Lua, Mathematica |
#(a, b, c) |
Dylan |
#(a b c)(99) |
Smalltalk |
{ a. b. c } |
Squeak |
[ a ; b ; c ] |
F#, OCaml |
[ a b c ] |
Logo, Oz, Rebol |
({ a, b, c }) |
Pike |
'(a b c) |
Common Lisp, Emacs Lisp, Scheme |
<< a, b, c >> |
Eiffel |
list(a, b, c) |
Io |
list |
Common Lisp, Dylan, Emacs Lisp, Scheme, Tcl |
array(a, b, c) |
PHP |
new t[] { a, b, c } |
C# |
new[] { a, b, c } |
C#3 |
new List<t> { a, b, c} |
C#3 |
Array(a, b, c)(100) |
JavaScript |
[NSArray arrayWithObjects:a, b, c, nil] |
Objective-C |
set l a b c |
FishShell |
- a - b - c |
YAML |
[]t{a, b, c} |
Go |
- list/array indexing
规则 | 语言 |
---|---|
a[i] |
B, BourneShell, C, C#, C++, CoffeeScript, Dylan, E, FishShell, Go, Java, JavaScript, KornShell, Lua, Maple, merd, Modula-3, MSH, Pascal, Perl, Perl6, PHP, Pike, Python, Ruby, Vimscript |
a*[i] or a!i or a*(i) depending on the version |
BCPL |
a[[i]] |
Mathematica |
a[i]:default |
YCP |
a(i) |
Ada, Matlab |
a:i |
Pliant |
a/:i |
Rebol |
a.(i) |
F#, OCaml |
a.[i] |
F# |
a !! i |
Haskell, Mercury |
a @ i |
Eiffel |
a i get(101) |
PostScript |
a at(i) |
Io |
at(102) |
C++, Smalltalk |
lindex |
Tcl |
nth |
Common Lisp, Emacs Lisp, OCaml |
Nth |
Oz |
aref |
Common Lisp, Emacs Lisp |
nth0 / nth1 |
Prolog |
list-ref / vector-ref |
Scheme |
element |
Dylan |
slice |
Ruby |
node[i] |
XPath |
objectAtIndex |
Objective-C |
item |
Logo |
a i cells + @ (for write access: o a i cells + ! |
Forth |
-
adding an element at the beginning (list cons)
return the new list (no side-effect) |规则 | 语言 | | ———– | ——————————- | |
:
| Haskell, merd | |::
| F#, OCaml, SML | ||
| Oz | |[ e | l ]
| Erlang, Prolog | |[e l[]]
| Maple | |[e l]
| Matlab | |cons
| Common Lisp, Emacs Lisp, Scheme | |pair
| Dylan | |fput
| Logo | |Prepend
| Ada, Mathematica |side-effect |规则 | 语言 | | ————— | ——————————————- | |
unshift
| CoffeeScript, JavaScript, Perl, Perl6, Ruby | |prepend
| YCP | |push_front
| C++ | |addFirst
| Smalltalk | |insert
| Rebol | |put_first
| Eiffel | |push
| Common Lisp, Io | |array_unshift
| PHP | |PrependTo
| Mathematica | -
adding an element at index
return the new list (no side-effect) |规则 | 语言 | | ————— | —————- | |
linsert l i e
| Tcl | |Insert
| Ada, Mathematica |side-effect |规则 | 语言 | | ————————————————– | ———— | |
[a insertObject:e atIndex:i]
| Objective-C | |a.insert(i, e)
| Python, Ruby | |a insertAt(e, i)
| Io | |a add: e beforeIndex: i / a add: e afterIndex: i
| Smalltalk | |splice(@a, $i, 0, $e)
| Perl | -
adding an element at the end
return the new list (no side-effect) |规则 | 语言 | | ——————— | —————- | |
[l e]
| Matlab | |push
| merd | |arrayByAddingObject
| Objective-C | |lput
| Logo | |linsert l end e
| Tcl | |Append
| Ada, Mathematica |side-effect |规则 | 语言 | | ———— | ——————————————- | |
push
| CoffeeScript, JavaScript, Perl, Perl6, Ruby | |push_back
| C++ | |append
| Go, Io, Pliant, Python, Rebol | |AppendTo
| Mathematica | |lappend
| Tcl | |+=
| Pliant | |add
| Java, Smalltalk, YCP | |put_last
| Eiffel | |array_push
| PHP | |addObject
| Objective-C | -
first element
规则 | 语言 |
---|---|
head |
Haskell |
Head |
F# |
hd |
F#, OCaml |
car |
Common Lisp, Emacs Lisp, Scheme |
first |
Eiffel, Io, Logo, Pliant, Rebol, Smalltalk |
First(103) |
Mathematica |
First_Element |
Ada |
iterator
|规则 | 语言 |
| ——- | —- |
| head
| Beta |
| begin
| C++ |
| First
| Ada |
- all but the first element
规则 | 语言 |
---|---|
tail |
Haskell |
Tail |
F# |
tl |
F#, OCaml |
cdr |
Common Lisp, Emacs Lisp, Scheme |
Rest |
Mathematica |
butfirst |
Logo |
allButFirst |
Smalltalk |
l[1:] |
Go, Python |
a(2:end) |
Matlab |
L = [_|ButFirst] |
Prolog |
lrange l 1 end |
Tcl |
- last element
规则 | 语言 |
---|---|
last |
E, Eiffel, Haskell, Io, Logo, Pliant, Prolog, Rebol, Scheme, Smalltalk |
Last |
Mathematica, Oz |
lastObject |
Objective-C |
a[-1] |
Perl, Pike, Python, Ruby |
a(end) |
Matlab |
node[last()] |
XPath |
(car (last l)) |
Common Lisp, Emacs Lisp |
lindex l end |
Tcl |
Last_Element |
Ada |
l[len(l)-1:] |
Go |
iterator
|规则 | 语言 |
| —— | —- |
| Last
| Ada |
| | |
- all but the last element
规则 | 语言 |
---|---|
Most |
Mathematica |
- get the first element and remove it
规则 | 语言 |
---|---|
shift |
CoffeeScript, JavaScript, Perl, Perl6, Ruby |
shift! |
merd |
pop |
Common Lisp, Logo |
removeFirst |
Io, Smalltalk |
array_shift |
PHP |
- get the last element and remove it
规则 | 语言 |
---|---|
pop |
CoffeeScript, E, Io, JavaScript, Perl, Perl6, Python, Ruby |
pop! |
merd |
array_pop |
PHP |
removeLast |
Io, Smalltalk |
dequeue |
Logo |
- for each element do something
规则 | 语言 |
---|---|
each |
merd, Pliant, Ruby |
for v in l ... |
CoffeeScript, E, Maple, Ruby |
for v in l: ... |
Python |
for v in l; do ...; done |
BourneShell |
for v in l do ... |
F# |
for v in l; ...; end |
FishShell |
for (v in l) ... |
Awk, Dylan |
for (var v in l) { ... } |
JavaScript |
For Each v in l ... Next |
Visual Basic |
for v in range loop .. end loop |
Ada |
for |
Perl |
foreach |
Logo, Lua, Perl, PHP, Pike, Rebol, Tcl |
foreach (t v in l) ... |
C# |
foreach (v in l) ... |
C#3 |
foreach ($v in l) ... |
MSH |
foreach(t v, l, { ... }) |
YCP |
l foreach(v, ...) |
Io |
for_each |
C++ |
for-each |
Scheme |
forall |
PostScript, Prolog |
ForAll |
Oz |
iter |
F#, OCaml |
do |
Smalltalk |
do_all |
Eiffel |
app |
SML |
mapc |
Emacs Lisp |
mapM_ |
Haskell |
Scan |
Mathematica |
(dolist (v l) ...) (loop for v in l do ...) mapc |
Common Lisp |
list.iterate (# do current ... #) |
Beta |
l.Iterate(...) |
F# |
Iterate |
Ada |
for i, v := range l {...} |
Go |
- transform a list (or bag) in another one
规则 | 语言 |
---|---|
map |
Dylan, F#, Haskell, Io, Maple, Mercury, merd, OCaml, Perl, Pike, Python, Ruby, Scheme, SML |
Map |
F#, Mathematica, Oz |
mapcar |
Common Lisp, Emacs Lisp |
maplist |
Prolog, YCP |
sublist |
Prolog |
map / map.se |
Logo |
for-each |
XSLT |
foreach or selected |
MSH |
collect |
Ruby, Smalltalk |
transform |
C++ |
array_map |
PHP |
/@ |
Mathematica |
[ f x | x <- l ](104) |
Haskell |
[ f(x) for x in l ](104) |
Python |
magical: sin(x) computes sin on each element |
Matlab |
- transform two lists in parallel
规则 | 语言 |
---|---|
map2 |
F#, OCaml |
zipWith |
Haskell |
Zip |
Maple, Oz |
map |
Dylan, Logo, Python, Scheme |
map.se |
Logo |
mapcar |
Common Lisp |
maplist2 |
Prolog |
l1 with: l2 collect: ... |
Smalltalk |
transform |
C++ |
ListPair.map |
SML |
magical: a binary function or operator is appliied on each element |
Matlab |
- find an element
规则 | 语言 |
---|---|
find |
C++, Common Lisp, F#, Haskell, merd, OCaml, Rebol, Ruby, Scheme-SRFI1, SML, YCP |
Find |
Ada |
find_if |
C++ |
find-if |
Common Lisp |
first(22) |
Perl |
detect |
Ruby, Smalltalk |
search |
Pike |
ListTools[Search] |
Maple |
lsearch -exact |
Tcl |
index |
Python |
indexOf |
Io |
indexOfObject, indexOfObjectIdenticalTo |
Objective-C |
find(a == 3) |
Matlab |
Position |
Mathematica |
-
keep elements
matching |规则 | 语言 | | ——————————- | ———————————————————— | |
find_all
| F#, OCaml, Ruby | |filter
| F#, Haskell, Mercury, merd, OCaml, Pike, Python, Scheme-SRFI1, SML, YCP | |filter!
| Scheme-SRFI1 | |Filter
| Oz | |grep
| Perl, Perl6 | |where
| MSH | |select
| Io, Maple, Ruby, Smalltalk | |Select / Case
| Mathematica | |selectInPlace
| Io | |remove-if-not delete-if-not
| Common Lisp | |choose
| Dylan | |array_filter
| PHP5 | |[ x | x <- l, p x ](104)
| Haskell | |[ x for x in l if p(x) ](104)
| Python | |a(a == 3)
| Matlab |non matching |规则 | 语言 | | ——————— | ———– | |
remove-if delete-if
| Common Lisp | |reject
| Ruby | -
partition a list: elements matching, elements non matching
规则 | 语言 |
---|---|
partition |
F#, Haskell, merd, OCaml, Ruby, Scheme-SRFI1, SML |
partition! |
Scheme-SRFI1 |
Partition |
Oz |
-
split a list
in 2 based on a predicate |规则 | 语言 | | ——- | ——- | |
break
| Haskell | |span
| Haskell |into sublists delimited by elements matching a predicate |规则 | 语言 | | ——————— | ———– | |
split-sequence(105)
| Common Lisp | |ListTools[Split]
| Maple |into a list of lists of same value |规则 | 语言 | | ——- | ———– | |
group
| Haskell | |Split
| Mathematica |into sublists based on a predicate |规则 | 语言 | | ——— | ———– | |
groupBy
| Haskell | |Split
| Mathematica | -
is an element in the list
规则 | 语言 |
---|---|
member? |
Dylan, merd, Ruby |
include? |
Ruby |
mem |
F#, OCaml |
member |
Common Lisp, Prolog, Scheme |
Member |
Oz |
MemberQ |
Mathematica |
memq memv |
Scheme |
memberp / member? |
Logo |
contains |
E, Io, YCP |
containsObject |
Objective-C |
in |
CoffeeScript, JavaScript, Python, SQL92, Tcl8.5 |
in_array |
PHP |
includes |
Smalltalk |
elem |
Haskell, Mercury |
has |
Eiffel |
has_value |
Pike |
ismember |
Matlab |
/elt/ |
GNU-sed |
- is the predicate true for an element
规则 | 语言 |
---|---|
any(31) |
Haskell, Matlab, Mercury, Python, Scheme-SRFI1 |
any? |
Dylan, Ruby |
anySatisfy |
Smalltalk |
exists |
F#, OCaml, SML |
exists? |
merd |
some |
Common Lisp |
Some |
Oz |
ormap |
Maple |
detect |
Io |
- is the predicate true for every element
规则 | 语言 |
---|---|
all(31) |
Haskell, Mercury, Python, SML |
All |
Oz |
all? |
merd, Ruby |
allSatisfy |
Smalltalk |
every |
Common Lisp, Scheme-SRFI1 |
every? |
Dylan |
for_all |
F#, OCaml |
andmap |
Maple |
- smallest / biggest element
规则 | 语言 |
---|---|
min / max |
Common Lisp, Eiffel, Io, Java, Maple, Matlab, Perl6, PHP5, Pike, Prolog, Python, Ruby, Scheme, Smalltalk |
Min / Max |
Mathematica |
minimum / maximum |
Haskell, Mercury, merd |
minimum-of / maximum-of |
Rebol |
min minstr / max maxstr(22) |
Perl |
min_element / max_element |
C++ |
- join a list of strings in a string using a glue string
规则 | 语言 |
---|---|
join(s, l) |
Perl, Perl6, PHP |
String.Join(s, l) |
C# |
s.join(l) |
Python |
l.join(s) |
CoffeeScript, JavaScript, Perl6, Ruby |
l asStringWith: s |
Smalltalk |
join l s |
Tcl |
implode(s, l) |
PHP |
ListTools[Join] |
Maple |
rjoin |
E |
join |
Io |
concat |
F#, OCaml |
strcat |
Matlab |
concat_atom |
Prolog |
l * s |
Pike, Ruby |
(mapconcat 'identity l s) |
Emacs Lisp |
componentsJoinedByString |
Objective-C |
intercalate |
Haskell |
StringJoin @@ Riffle[l, s] |
Mathematica |
strings.Join |
Go |
- list size
规则 | 语言 |
---|---|
size |
C++, Dylan, E, Io, Java, Matlab, merd, Pliant, Ruby, Scilab, Smalltalk, YCP |
sizeof |
Pike |
length |
C#, CoffeeScript, Common Lisp, Emacs Lisp, F#, Haskell, Java, JavaScript, Matlab, Mercury, OCaml, PostScript, Prolog, Ruby, Scheme, SML |
Length |
Ada, F#, Mathematica, Oz |
length? |
Rebol |
len |
Python, Vimscript |
llength |
Tcl |
$LENGTH |
MUMPS |
elems |
Perl6 |
getn |
Lua |
count |
Eiffel, FishShell, Objective-C, PHP, SQL92, XPath |
numel |
Matlab |
scalar @l |
Perl |
nops |
Maple |
# |
Lua |
len(l) |
Go |
- iterate with index
规则 | 语言 |
---|---|
each_with_index |
merd, Ruby |
enumerate(l) |
Python |
foreach($l as $i => $v) |
PHP |
a foreach(i, e, ...) |
Io |
for i => v in l |
E |
for (v in l, i from 0) ... end |
Dylan |
forAllInd |
Oz |
foreachi |
Lua |
foreach(l; typ0 i; typ1 v) { ... } |
Pike |
withIndexDo |
Squeak |
iteri |
F#, OCaml |
IterateIndexed |
F# |
MapIndexed |
Mathematica |
(loop for v in l as i upfrom 0 do ...) |
Common Lisp |
for v,i in l ... |
CoffeeScript |
for i, v := range l {...} |
Go |
- remove duplicates
规则 | 语言 |
---|---|
uniq |
merd, Perl6, Pike, Ruby |
uniq! |
Ruby |
uniq2 |
Pike |
unique(106) |
C++, Io, Matlab, Rebol |
nub |
Haskell |
array_unique |
PHP |
ListTools[MakeUnique] |
Maple |
delete-duplicates |
Common Lisp, Scheme-SRFI1 |
delete-duplicates! |
Scheme-SRFI1 |
remove-duplicates |
Common Lisp, Dylan |
lsort -unique |
Tcl |
toset |
YCP |
distinct |
SQL92 |
set |
Python |
Union |
Mathematica |
- sort
规则 | 语言 |
---|---|
sort(107) |
C#, C++, CoffeeScript, Common Lisp, E, Eiffel, F#, Haskell, Io, Java, JavaScript, Lua, Maple, Matlab, merd, OCaml, Perl, Perl6, PHP, Pike, Prolog, Python, Rebol, Ruby, Scheme, XSLT, YCP |
sort! |
Ruby |
sorted |
Python |
Sort |
Mathematica, Oz |
sort_by |
merd, Ruby |
sortBy |
Haskell, Io, Smalltalk |
order by |
SQL92 |
lsort |
Tcl |
asort |
Awk |
sort-object |
MSH |
sortedArrayUsingSelector, sortUsingSelector |
Objective-C |
predsort / keysort / mergesort |
Prolog |
- reverse
规则 | 语言 |
---|---|
reverse |
C++, CoffeeScript, Common Lisp, Dylan, Emacs Lisp, Haskell, Io, Java, JavaScript, Logo, Mercury, merd, Perl, Perl6, Pike, Prolog, Python, Rebol, Ruby, Scheme |
Reverse |
C#, Mathematica, Oz |
reversed |
Python, Smalltalk |
reverse_copy |
C++ |
rev |
F#, OCaml, SML |
Reverse_Elements |
Ada |
lreverse |
Tcl8.5 |
array_reverse |
PHP |
ListTools[Reverse] |
Maple |
fliplr flipud... |
Matlab |
l[::-1] |
Python |
- list of couples from 2 lists
规则 | 语言 |
---|---|
combine |
F#, OCaml |
zip |
F#, Haskell, Maple, merd, Perl6, Python, Ruby, Scheme-SRFI1, SML |
pairlis(108) |
Common Lisp |
transpose |
Ruby |
Transpose |
Mathematica |
[a b] |
Matlab |
- 2 lists from a list of couples
规则 | 语言 |
---|---|
split |
F#, OCaml |
unzip |
F#, Haskell, merd, SML |
unzip2 |
Scheme-SRFI1 |
transpose |
Ruby |
Transpose |
Mathematica |
zip(*l) |
Python |
a(1,:), a(2,:) |
Matlab |
- lookup an element in a association list
规则 | 语言 |
---|---|
lookup |
Haskell |
assoc |
Common Lisp, Emacs Lisp, F#, OCaml, Ruby, Scheme |
assq |
Emacs Lisp, Scheme |
assv |
Scheme |
get_assoc |
Prolog |
select |
Rebol |
a.(e) |
Matlab |
a[e] |
Maple |
gprop |
Logo |
/. |
Mathematica |
- list out of a bag
规则 | 语言 |
---|---|
to_a |
Ruby |
toArray |
Java |
asArray |
Smalltalk |
to_list |
merd |
list |
Python |
map-as(<list>, bag) |
Dylan |
[a.(:)] |
Matlab |
array get |
Tcl |
- f(… f(f(init, e1), e2) …, en)
规则 | 语言 |
---|---|
foldl |
Haskell, Maple, Mercury, merd, SML |
FoldL |
Oz |
fold_left |
OCaml |
fold |
F#, Scheme-SRFI1 |
Fold |
Mathematica |
reduce(109) |
Common Lisp, Dylan, Io, Perl, Perl6, Pike, Python |
inject |
Ruby |
inject into |
Smalltalk |
- f(e1, f(e2, … f(en, init) …))
规则 | 语言 |
---|---|
foldr |
Haskell, Maple, Mercury, merd, SML |
FoldR |
Oz |
fold-right |
Scheme-SRFI1 |
fold_right |
OCaml |
foldBack |
F# |
rreduce |
Pike |
(reduce f '(e1 e2 ... en) :from-right t :initial-value init) |
Common Lisp |
reverseReduce |
Io |
Various Data Types
- tuple type
规则 | 语言 |
---|---|
typ1 * ... * typn |
F#, OCaml, SML |
(typ1, ..., typn) |
Haskell |
typ1, ..., typn |
merd |
tuple |
Python |
tuple! |
Rebol |
Tuple[Typ1, Typ2, Typ3] |
E |
tuple< typ1, ..., typn > |
C++-0x |
- tuple constructor
规则 | 语言 |
---|---|
a, b, c |
F#, Lua, merd, OCaml, Python, Ruby |
( a, b, c ) |
Ada, C++-0x, Haskell, Perl, Prolog, SML |
{ a. b. c } |
Smalltalk |
{ a, b, c } |
Matlab |
[ a, b, c ] |
E |
a . b . c |
Rebol |
(cons a b) |
Common Lisp |
-
computable tuple (these are a kind of immutable lists playing a special role in parameter passing)
empty tuple |规则 | 语言 | | ——— | ————————- | |
()
| merd, Perl, Perl6, Python | |[]
| Ruby | |{}
| Matlab, Smalltalk | |#()
| Smalltalk | |Nothing
| Prolog |1-uple |规则 | 语言 | | ———— | ————- | |
a or [a]
| Ruby | |a,
| Perl6, Python | |tuple([a])
| Python | |(a)
| Perl | |((a))
| merd | |{a}
| Smalltalk |using a tuple for a function call |规则 | 语言 | | —————————– | ———— | |
t
| merd, Perl | |*t
| Python, Ruby | |t{:}
| Matlab | |f @@ t
| Mathematica | |L =.. [ F | Args ], call(L)
| Prolog | -
reference (pointer)
creation |规则 | 语言 | | ———– | —————— | |
&
| B, C, C#, C++, Go | |\
| Perl | |AddressOf
| Visual Basic | |addr(110)
| Pascal | |@(110)
| Pascal | |lv
| BCPL | |ref
| C#, F#, OCaml, SML | |newSTRef
| Haskell | |NewCell
| Oz | |variable
| Forth | |'access
| Ada | |:> :>>
| Pliant | |''
| Maple |dereference |规则 | 语言 | | —————————— | —————– | |
*(111)
| B, C, C#, C++, Go | |$ @ % &(111)
| Perl | |->[...] ->{...} ->(...)(112)
| Perl | |->(113)
| C, C++ | |^(112)
| Modula-3, Pascal | |!(111)
| F#, OCaml, SML | |rv
| BCPL | |readSTRef
| Haskell | |Access
| Oz | |.[all]
| Ada | |@
| Forth | |eval
| Maple | |(reg)
| Assembler |assigning (when dereferencing doesn’t give a lvalue) |规则 | 语言 | | ———— | ————– | |
writeSTRef
| Haskell | |Assign
| Oz | |:=
| F#, OCaml, SML | |!
| Forth | -
optional value
null value |规则 | 语言 | | ——————– | ———————————————————— | |
0(114)
| C++, Forth | |0 nullptr(114)
| C++-0x | |NULL
| C, Maple, SQL92 | |nil
| Common Lisp, Emacs Lisp, Io, Lua, Objective-C, Ruby, Smalltalk | |null
| C#, CoffeeScript, Java, JavaScript | |Null(115)
| Ada, Mathematica | |undef
| Perl | |None
| F#, OCaml, Python | |NONE
| SML | |Nothing
| Haskell | |Void
| Eiffel | |#f ()
| Emacs Lisp | |(empty) / ~ / null
| YAML |value |规则 | 语言 | | ——— | ———————————————————— | |
v
| Ada, C#, CoffeeScript, Common Lisp, Eiffel, Emacs Lisp, Java, JavaScript, Lua, Perl, Perl, Python, Ruby, Scheme, Smalltalk | |*v(114)
| C, C++ | |Just v
| Haskell | |Some v
| F#, OCaml | |SOME v
| SML |type name |规则 | 语言 | | ——– | ————– | |
option
| F#, OCaml, SML | |Maybe
| Haskell |null coalescing |规则 | 语言 | | ———- | ———————- | |
COALESCE
| SQL92 | |?:
| PHP | |||
| JavaScript, Perl, Ruby | |//(116)
| Perl | |??
| C# | |if(a, b)
| Visual Basic | |or
| Python, Scheme | -
record
type declaration |规则 | 语言 | | ———————————————————— | ———- | |
struct { typ1 n1; typ2 n2; ... }
| C, C++ | |type typ = { n1 : typ1; n2 : typ2 }
| OCaml, SML | |data Typ = N0 { n1, n2 :: typ1, n3 :: typ3, ... }
| Haskell | |type Typ is record N1 : Typ1; N2 : Typ2 := default_val; ... end record;
| Ada | |type typ struct{ n1 typ1; n2 typ2; }
| Go |selector |规则 | 语言 | | ———————- | ———————————————————— | |
.
| Ada, Beta, C, C#, C++, CoffeeScript, E, Eiffel, F#, Go, Java, JavaScript, Lua, Matlab, Modula-2, Modula-3, OCaml, Oz, Pascal, Python, Ruby | |::
| XPath | |%
| Fortran90 | |'(117)
| Ada | |^
| Mercury | |r { field }
| merd | |r:field
| Pliant | |field r
| Haskell | |->
| C, C++ | |r[field]
| Maple | |r["field"]
| JavaScript | |#field r
| SML | |normal function call
| Common Lisp, Dylan, Haskell, Io, Smalltalk | -
union type declaration
规则 | 语言 |
---|---|
union { typ1 n1; typ2 n2; ... } |
C, C++ |
data Typ = N1 typ1 | N2 typ2 | ... |
Haskell |
type typ = N1 of typ1 | N2 of typ2 | ... |
OCaml |
datatype typ = N1 of typ1 | N2 of typ2 | ... |
SML |
type Typ (Choice : Discrete_Type) is record case Choice is when Choice_1 => N1 : Typ1; ... when Choice_2 | Choice_3 => ... when others => ... end case; end record; |
Ada |
- enumerated type declaration
规则 | 语言 |
---|---|
enum typ { n1; n2; ... }(118) |
C, C#, C++, Java |
Enum typ n1 n2 End Enum |
Visual Basic |
(n1, n2, ...) |
Pascal |
type typ is(119) |
Ada |
data Typ = N1 | N2 | ... |
Haskell |
type typ = N1 | N2 | ... |
OCaml |
datatype typ = N1 | N2 | ... |
SML |
-
dictionary
type name |规则 | 语言 | | —————————– | —————– | |
map
| Go, YAML | |Map
| F#, Io | |std::map
| C++ | |dict
| Python | |Dictionary
| Pliant, Smalltalk | |dictionary
| Vimscript | |Hash
| Perl6, Ruby | |HASH
| Perl | |HASH_TABLE
| Eiffel | |HashTable
| Java | |Hashtbl
| F# | |Hashtbl.t
| OCaml | |struct
| Matlab | |table
| Maple | |array
| PHP | |Data.Map, Data.HashTable
| Haskell | |Containers.Ordered_Maps.Map
| Ada |constructor |规则 | 语言 | | ———————————————————— | ————————————————- | |
[ a => b, c => d ]
| E | |array( a => b, c => d )
| PHP | |{ a => b, c => d }
| Perl, Perl6, Ruby | |{ a, b, c, d }
| Perl, Ruby | |{ a: b, c: d }
| CoffeeScript, JavaScript, Python, Vimscript, YAML | |{ a: b; c: d }
| CSS | |$[ a: b, c: d ]
| YCP | |{ a->b. c->d }
| Squeak | |{ a = b, c = d }
| Lua | |@{ a = b; c = d }
| MSH | |([ a:b, c:d ])
| Pike | |([a]=b [c]=d)
| KornShell | |<< a b c d >>
| PostScript | |struct(a, b, c, d)
| Matlab | |Hash[ a, b, c, d ]
| Ruby | |Map.of_list [a, b; c, d]
| F# | |Hashtbl.of_list [a, b; c, d]
| F# | |table([a=b, c=d])
| Maple | |define table foo a => b; c => d end
| Dylan | |dict create a b c d
| Tcl8.5 | |new t { {a, b}, {c, d} }
| C# | |fromList
| Haskell | |[NSDictionary dictionaryWithObjectsAndKeys:b, a, d, c, nil]
| Objective-C | | ` a: b c: d| YAML | |
map[typ0]typ1{ a: b, c: d }` | Go |access: read/write |规则 | 语言 | | —————- | ———————————————————— | |
h[k]
| Awk, C#, C++, CoffeeScript, Dylan, E, Go, JavaScript, Lua, Maple, MSH, PHP, Python, Ruby, Vimscript | |$h{k}
| Perl | |%h{k} or %h<s>
| Perl6 | |h(k)
| Tcl | |h.[k]
| F# | |h.k
| CoffeeScript, JavaScript, Lua, Matlab | |h:k
| Pliant | |h["k"] or h->k
| Pike | |(gethash k h)
| Common Lisp |access: read |规则 | 语言 | | —————————————– | ————- | |
h k get
| PostScript | |find
| F#, OCaml | |fetch
| Ruby | |get
| Java | |dict get
| Tcl8.5 | |at
| Io, Smalltalk | |h@k or h.at(k)
| Eiffel | |h[k]:default
| YCP | |${h[k]}
| KornShell | |h.get(k, returned_value_when_k_unfound)
| Python | |objectForKey
| Objective-C | |lookup
| Haskell | |Element
| Ada |access: write |规则 | 语言 | | ————————– | ————– | |
h k o put
| PostScript | |put
| Eiffel, Java | |add, replace
| F#, OCaml | |store
| Ruby | |dict set
| Tcl8.5 | |h[k]
| KornShell, YCP | |atPut
| Io | |h at: k put: o
| Smalltalk | |[h setObject:o forKey:k]
| Objective-C | |insert
| Haskell | |Replace_Element
| Ada |has the key ? |规则 | 语言 | | ————————————- | ——————————– | |
exists $h{k}
| Perl | |exists
| Perl6, Pliant | |dict exists
| Tcl8.5 | |has
| Eiffel | |haskey
| YCP | |hasKey
| Io | |has_key
| Python, Vimscript | |has_key?, include?, key?, member?
| Ruby | |Contains
| Ada, C#, F# | |containsKey
| Java | |includesKey
| Smalltalk | |k in h
| CoffeeScript, JavaScript, Python | |k not in h
| Python | |in
| Awk | |mem
| F#, OCaml | |member
| Haskell | |isfield
| Matlab | |find(120)
| C++ | |h[k]
| Pike | |(gethash k h)
| Common Lisp | |maps
| E | |known
| PostScript | |isset(h[k]), array_key_exists(k, h)
| PHP | |v, exists := h[k]
| Go |remove by key |规则 | 语言 | | ——————– | ———————————————- | |
delete $h{k}
| Perl | |del h[k]
| Python | |unset(h[k])
| PHP | |remove
| Eiffel, F#, Java, OCaml, YCP | |Remove
| C#, F# | |dict remove
| Tcl8.5 | |removeAt
| Io | |removeKey
| E, Smalltalk | |remhash
| Common Lisp | |delete
| CoffeeScript, Haskell, JavaScript, Perl6, Ruby | |Delete
| Ada | |erase
| C++ | |m_delete
| Pike | |removeObjectForKey
| Objective-C | |undef
| PostScript | |rmfield
| Matlab | |delete(h, k)
| Go |list of keys |规则 | 语言 | | ———————————- | ———————————————————— | |
keys
| Haskell, Io, Maple, MSH, Perl, Perl6, Python, Ruby, Smalltalk | |dict keys
| Tcl8.5 | |keySet
| Java | |allKeys
| Objective-C | |AllKeys
| C# | |indices
| Pike | |current_keys
| Eiffel | |getKeys
| E | |array_keys
| PHP | |fieldnames
| Matlab | |findall(Key, item(Key, _), Keys)
| Prolog | |${!h[@]}
| KornShell |list of values |规则 | 语言 | | ————– | —————————————————- | |
values
| Io, Java, Perl, Perl6, Pike, Python, Ruby, Smalltalk | |dict values
| Tcl8.5 | |getValues
| E | |content
| Eiffel | |array_values
| PHP | |struct2cell
| Matlab | |entries
| Maple | |elems
| Haskell | |${h[@]}
| KornShell |merge |规则 | 语言 | | —————— | ———— | |
merge(121)
| Ruby | |array_merge(121)
| PHP | |union(122)
| Haskell | |update(121)
| Python, Ruby | |putAll(121)
| Java | |insert(122)
| C++ | |(%h1, %h2)(121)
| Perl | -
range
inclusive .. inclusive |规则 | 语言 | | ——————————— | ————————————- | |
a .. b
| Ada, E, merd, MSH, Pascal, Perl, Ruby | |a:b
| Matlab | |[ a .. b ]
| CoffeeScript, F#, Haskell | |to
| Io, Smalltalk | |seq a b / jot - a b(123)
| BourneShell, FishShell | |{a..b}
| KornShell | |range
| PHP | |range(from: a, to: b, by: step)
| Dylan | |Range
| Mathematica | |Range with
| Io | |List.number A B Step
| Oz | |numlist / between
| Prolog | |iseq
| Logo | |k, v := range h
| Go |inclusive .. exclusive |规则 | 语言 | | ——— | —————— | |
a ... b
| CoffeeScript, Ruby | |a ..! b
| E | |range
| Python |
Mathematics
-
type name
integers |规则 | 语言 | | ———————————————————— | ——————— | |
short, int, long
| C, C# | |int
| OCaml, PHP, SML, YAML | |Int
| Perl6 | |Int, uInt, Int8, Int16...
| Pliant | |int, long(124)
| Python | |integer
| Maple, PHP | |INTEGER, INT, SMALLINT
| SQL92 | |INTEGER, INTEGER_8, NATURAL_8...
| Eiffel | |int8, uint8, int16, uint16, ...64
| Go, Matlab | |int8_t, uint8_t, int16_t, uint16_t, ...64
| C99 | |int, int8, uint8, int16, uint16, int32, uint32, int64, uint64, bigint, bignum
| F# | |Int, Integer, Int8, Int16, Int32, Int64
| Haskell | |Integer, FixNum, BigNum
| Ruby | |Integer, SmallInteger, LargeInteger
| Smalltalk | |Integer
| Mathematica | |type T is range Low...High;
| Ada | |number
| Vimscript |floating point |规则 | 语言 | | ————————————————– | ————————————— | |
float, double, long double
| C | |float, double
| C# | |float
| Maple, OCaml, PHP, SML, Vimscript, YAML | |Float
| Ruby | |float, float32
| F# | |Float, Float32, Float64
| Pliant | |NUMERIC, DECIMAL, DOUBLE PRECISION
| SQL92 | |Rat
| Perl6 | |DOUBLE, REAL
| Eiffel | |single, double
| Matlab | |Float, Double, Ratio
| Haskell | |Float, Double, Fraction, FixedPoint
| Smalltalk | |float, decimal.Decimal
| Python | |Real, Rational
| Mathematica | |Number
| Io | |type T is digits N range Low..High;
| Ada | |type T is delta S digits N range Low..High;(125)
| Ada | |float32, float64
| Go | -
numbers syntax
integers |规则 | 语言 | | ——————— | ———————————————————— | |
1000
| Awk, B, BourneShell, C, C#, C++, CoffeeScript, E, Eiffel, F#, Forth, Go, Haskell, Io, Java, JavaScript, Logo, Maple, Mathematica, merd, OCaml, Oz, Pascal, Perl, Perl6, PHP, Pike, Pliant, Prolog, Python, Rebol, Ruby, Scheme, Smalltalk, SQL92, Tcl, Yorick | |1000, 1000.
| Common Lisp, Emacs Lisp | |1000, 1000., 1000.0
| Awk, Matlab | |1000, '1000'D
| Classic REXX | |1000, 1E3
| Ada |integers in base 2, octal and hexadecimal |规则 | 语言 | | ——————- | —————————————- | |
0b1, 07, 0xf(126)
| CoffeeScript, Oz, Perl, PHP5, Pike, Ruby | |0b1, 0o7, 0xf
| F#, OCaml, Perl6 | |07, 0xf
| Awk, C, C++, JavaScript, Python, Tcl | |0xf
| C#, E, Go, Io, Yorick | |07
| B | |0o7, 0xf
| Haskell | |1b
| Eiffel | |2#1#, 8#7#, 16#f#
| Ada | |2#{1}, #{F}
| Rebol | |#b1, #o7, #xf
| Common Lisp, Emacs Lisp, Scheme | |2^^1, 8^^7, 16^^f
| Mathematica | |2r1, 8r7, 16rf
| Smalltalk | |#2r1, #8r7, #16rf
| Common Lisp, Emacs Lisp | |1b, Fh
| Pliant | |'1'B, 'F'X
| Classic REXX | |B'1', X'F'
| SQL92 | |$f
| Forth |integer thousand-separator |规则 | 语言 | | ——————— | —————————————- | |
1_000, 10_00, 100_0
| Ada, E, Eiffel, OCaml, Perl, Perl6, Ruby | |1'000, 10'00, 100'0
| Rebol | |1_000
| merd |floating point |规则 | 语言 | | ———————— | ———————————————————— | |
1000., 1E3
| C, C++, Classic REXX, CoffeeScript, E, F#, Go, Java, JavaScript, Logo, Maple, OCaml, Python, Scheme, SQL92, Tcl | |1000., 1E3, 1,0
| Rebol | |1000., 1.E3
| Eiffel, Oz | |1000.0, 1E3
| C#, Common Lisp, Emacs Lisp, PHP, Pike, Prolog, Ruby, Smalltalk | |1000.0, 1.0E3
| Ada, Haskell | |1000, 1000.0, 1E3(127)
| Awk, merd, Perl, Perl6 | |1000., 1*^3, 1000
| Mathematica | |
1000e, 1e3` | Forth | -
addition / subtraction / multiplication / division
规则 | 语言 |
---|---|
+ / - / * / / |
BourneShell, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, D, Eiffel, Emacs Lisp, F#, Forth, Go, Haskell, Io, Java, JavaScript, Logo, Maple, Matlab, merd, MUMPS, Perl, Perl6, PHP, Pliant, Prolog, Python, Ruby, Scheme, Smalltalk, SQL92, Tcl, Vimscript, Yorick |
+ / - / * or nothing / / |
Mathematica |
+ +. / - -. / * *. / / /.(128) |
OCaml |
sum / difference / product / quotient |
Logo |
add / sub / mul / idiv div |
PostScript |
f+ / f- / f* / f/ |
Forth |
- exponentiation (power)
规则 | 语言 |
---|---|
** |
Ada, Classic REXX, E, F#, Fortran, Io, merd, OCaml, Perl, Perl6, PL/I, Prolog, Python, Rebol, Ruby, Tcl8.5 |
^ |
Awk, Dylan, Eiffel, Lua, Mathematica, Matlab, Pliant, Yorick |
*(129) |
APL |
**, ^ |
Maple |
^^ |
D |
**, ^ and ^^(130) |
Haskell |
f** |
Forth |
pow |
C, C++, CoffeeScript, Java, JavaScript, PHP, Pike, Python, SML, Tcl |
Pow |
C#, Oz |
power |
Delphi-Kylix, Logo, Rebol |
exp |
PostScript |
expt |
Common Lisp, Emacs Lisp, Scheme |
raisedTo |
Smalltalk |
math.Pow |
Go |
- negation
规则 | 语言 |
---|---|
- |
Ada, Awk, B, BCPL, BourneShell, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, D, E, Eiffel, Emacs Lisp, F#, Go, Haskell, Io, Java, JavaScript, Logo, Maple, Mathematica, Matlab, merd, MUMPS, Perl, Perl6, PHP, Pike, Pliant, Prolog, Python, Rebol, Ruby, Scheme, Smalltalk, Tcl, Vimscript, Yorick |
- -. |
OCaml |
~ |
Oz, SML |
neg |
PostScript |
negate |
Forth, Rebol |
fnegate |
Forth |
minus |
Logo |
-
random
random number |规则 | 语言 | | ——————————————- | ——————————————— | |
rand
| C, Maple, Matlab, Perl, Perl6, PHP, Ruby, Tcl | |random
| Common Lisp, Logo, Prolog, Python, Yorick | |$RANDOM
| MUMPS | |randomR
| Haskell | |Random(131)
| Ada | |Random.int
| OCaml | |Random, RandomReal, RandomInteger
| Mathematica | |Random value
| Io | |Random new nextInteger
| Smalltalk | |r: RANDOM create r.make r.start r.item
| Eiffel | |Random ran = new Random(); ran.Next(...);
| C# | |let r = System.Random() r.Next()
| F# | |mt_rand
| PHP | |rand.Read(132)
| Go |seed the pseudo random generator |规则 | 语言 | | —————————————- | —————————— | |
srand
| C, Perl, Perl6, PHP, Ruby, Tcl | |set_seed
| Eiffel | |random.seed
| Python | |Random setSeed
| Io | |Random.init, Random.self_init
| OCaml | |rand('state',...)
| Matlab | |rerandom
| Logo | |RandomTools[MersenneTwister][SetState]
| Maple | |Random new setSeed
| Smalltalk | |SeedRandom
| Mathematica | |mkStdGen
| Haskell | |make-random-state
| Common Lisp | |Reset
| Ada | |rand.Seed(133)
| Go | -
operator priorities and associativities
addition vs multiplication |规则 | 语言 | | —————– | ———————————————————— | |
mathematical
| BourneShell, C, C#, C++, Classic REXX, Eiffel, F#, Go, Haskell, Io, Java, Maple, Mathematica, Matlab, merd, Perl, Perl6, PHP, Python, Ruby, Tcl, Yorick | |same priorities
| MUMPS, Smalltalk |exponentiation vs negation (is -3^2 equal to 9 or -9) |规则 | 语言 | | —————- | ———————————————————— | |
mathematical
| Classic REXX, Eiffel, Haskell, Io, Maple, Mathematica, Matlab, Perl, Perl6, Python, Ruby | |negation first
| F#, OCaml | -
square root / e-exponential / absolute value
规则 | 语言 |
---|---|
sqrt / exp / abs |
Ada, C, C++, CoffeeScript, Common Lisp, E, Eiffel, Emacs Lisp, F#, Haskell, Io, Java, JavaScript, Lua, Maple, OCaml, Pascal, Perl, Perl6, PHP, Prolog, Python, Ruby, Scheme, Smalltalk, SML, Tcl, Yorick |
sqrt realsqrt / exp / abs |
Matlab |
sqrt / exp / |
Awk, Logo |
Sqrt / Exp / Abs |
C#, Mathematica, Oz |
sqrt / / abs |
PostScript |
Sqrt / / ABS |
Modula-3 |
/ exp / abs |
Pliant |
sqrt / / |
Pike |
square-root / exp / abs or absolute |
Rebol |
Sqrt / Exp / ABS |
Classic REXX |
sqrt,isqrt / exp / abs |
Tcl8.5 |
fsqrt / fexp / abs,fabs |
Forth |
math.Sqrt |
Go |
-
trigonometry
basic |规则 | 语言 | | ——————————– | ———————————————————— | |
sin / cos / tan
| Ada, C, C++, CoffeeScript, Common Lisp,
E, Emacs Lisp, F#, Haskell, Io, Java, JavaScript,
Lua, Maple, Matlab, OCaml, Pascal, Perl,
Perl6, PHP, Pike, Pliant, Prolog, Python, Ruby,
Scheme, Smalltalk, SML, Tcl, Yorick | |Sin / Cos / Tan
| C#, Classic REXX, Mathematica, Oz | |sin / cos /
| Awk, PostScript | |sine / cosine / tangent
| Eiffel, Rebol | |radsin / radcos / radtan
| Logo | |fsin / fcos / ftan
| Forth | |math.Sin / math.Cos / math.Tan
| Go |inverse |规则 | 语言 | | ————————————- | ———————————————————— | |
asin / acos / atan(134)
| Ada, C, C++, CoffeeScript,
Common Lisp, F#, Haskell,
Io, JavaScript, Matlab, OCaml,
Perl, Perl6, Pike, Pliant, Prolog,
Python, Ruby, Scheme, Tcl, Yorick | |Asin / Acos / Atan
| C#, Oz | |ASin / ACos / ATan
| Classic REXX | |arcsin / arccos / arctan
| Maple | |arcSin / arcCos / arcTan
| Smalltalk | |ArcSin / ArcCos / ArcTan
| Mathematica | |arcsine / arccosine / arctangent
| Rebol | |arc_sine / arc_cosine / arc_tangent
| Eiffel | |/ / atan
| PostScript | |/ / radarctan
| Logo | |fasin / facos / fatan
| Forth | |math.Asin / math.Acos / math.Atan
| Go | -
logarithm
base e |规则 | 语言 | | ———- | ———————————————————— | |
ln
| Delphi-Kylix, Logo, Maple, Pascal, PostScript, Smalltalk, SML | |log
| Awk, C, C++, CoffeeScript, Common Lisp,
E, Eiffel, Emacs Lisp, F#, Io, Java, JavaScript,
Lua, Maple, Matlab, OCaml, Perl, Perl6, PHP,
Pike, Pliant, Prolog, Python, Ruby, Scheme, Tcl, Yorick | |Log
| Ada, C#, Classic REXX, Mathematica, Oz | |log 10
| Haskell | |log-e
| Rebol | |fln
| Forth | |math.Log
| Go |base 10 |规则 | 语言 | | —————————– | ———————————————————— | |
log10
| C, C++, Delphi-Kylix, Eiffel, F#, Io,
Logo, Lua, Matlab, OCaml, Perl, Perl6, PHP, Pliant, Prolog, Python, Ruby, Tcl, Yorick | |Log10
| C#, Classic REXX | |log
| PostScript, SML | |log: 10
| Smalltalk | |log-10
| Rebol | |log[10]
| Maple | |Log[10, val]
| Mathematica | |logBase 10
| Haskell | |Log(X => val, Base => 10.0)
| Ada | |(log x 10)
| Common Lisp | |flog
| Forth | |math.Log10
| Go |base 2 |规则 | 语言 | | —————————- | ———– | |
log2
| Matlab | |log-10 / log-2
| Rebol | |Log(X => val, Base => 2.0)
| Ada | |log(val, 2)
| Python | |Log[2, val]
| Mathematica | |frexp
| C | |math.Log2
| Go | -
euclidean division (both quotient and modulo)
规则 | 语言 |
---|---|
divmod |
Python, Ruby |
divMod |
Haskell |
div ldiv lldiv |
C |
IntInf.quotrem |
SML |
floor |
Common Lisp, Dylan |
/mod |
Forth |
Div(135) |
Go |
-
modulo
modulo of -3 / 2 is 1 |规则 | 语言 | | ——– | ———————————————————- | |
%
| Classic REXX, Perl, Perl6, Pike, Python, Ruby, Tcl | |%%
| E | |\\
| Smalltalk | |mod
| Ada, Common Lisp, Emacs Lisp, Haskell, Matlab, Prolog, SML | |Mod
| Mathematica | |MOD
| Modula-3 | |modulo
| Dylan, Logo, Ruby | |rem
| Prolog |modulo of -3 / 2 is -1 |规则 | 语言 | | ———– | ———————————————————— | |
%
| Awk, B, C, C#, C++, CoffeeScript, E, F#, Go, Io, Java, JavaScript, PHP, Pliant, Yorick | |#
| MUMPS | |mod
| F#, Forth, Lua, OCaml, Oz, Pascal, PostScript, Prolog, XPath | |remainder
| Logo, Ruby, Scheme | |rem
| Ada, BCPL, Haskell, Matlab, Smalltalk | |//
| Classic REXX, Rebol | |\\
| Eiffel | -
truncate / round / floor / ceil
规则 | 语言 |
---|---|
trunc / round / floor / ceil |
C, C++, Maple, Matlab |
truncate / round / floor / ceiling |
Common Lisp, Haskell, Perl6, PostScript, Prolog, Scheme |
int / round / floor / ceil |
CoffeeScript, JavaScript, Pike, Python |
int / round / / |
Logo |
to_i, Integer() / round / floor / ceil |
Ruby |
TRUNC / FORMAT / Floor / Ceil |
Classic REXX |
Float'Truncation / Float'Rounding / Float'Floor / Float'Ceiling(136) |
Ada |
/ round / floor / ceil |
E, Io, Java, Lua, PHP, SML, Tcl |
/ Round / Floor / Ceiling |
C# |
/ Round / Floor / Ceil |
Oz |
/ round / floor / ceiling |
Dylan, Emacs Lisp, PostScript, XPath |
/ ROUND / FLOOR / CEILING |
Modula-3 |
/ rounded / floor / ceiling |
Eiffel, Smalltalk |
int / / floor / ceil |
F#, Perl |
int_of_float / / floor / ceil |
F#, OCaml |
/ / floor / ceil |
Lua, Yorick |
IntegerPart / Round / Floor / Ceiling |
Mathematica |
/ Rounding / Floor / Ceiling |
Ada |
to-integer / / / |
Rebol |
/ fround / / |
Forth |
math.Trunc / / math.Floor / math.Ceil |
Go |
-
bitwise operators
and / or / xor |规则 | 语言 | | ————————————- | ———————————————————— | |
& / | / ^
| C, C#, C++, CoffeeScript, E, Eiffel, Go, Java, JavaScript, Perl, PHP, Pike, Python, Ruby, Tcl | |& / | / ~
| Yorick | |& / |
| YCP | |+& / +| / +^
| Perl6 | |.&. / .|. / xor(137)
| Haskell | |&&& / ||| / ^^^
| F# | |and / or / xor
| Ada, Forth, PostScript, Rebol | |land / lor / lxor
| F#, OCaml | |logand / logior / logxor(138)
| Common Lisp | |bitand / bitor / bitxor
| Logo, Matlab | |BITAND / BITOR / BITXOR
| Classic REXX | |BitAnd / BitOr / BitXor
| Mathematica | |bitAnd / bitOr / bitXor
| Smalltalk | |bitwiseAnd / bitwiseOr / bitwiseXor
| Io | |/\ / \/ / xor
| Prolog |bitwise inversion |规则 | 语言 | | ——————- | ———————————————————— | |
~
| C, C#, C++, CoffeeScript, Java, JavaScript, Perl, PHP, Pike, Python, Ruby, SML, Tcl, YCP | |~~~
| F# | |not
| Ada, Eiffel, PostScript | |lnot
| F#, OCaml | |lognot(139)
| Common Lisp | |bitnot
| Eiffel, Logo | |BitNot
| Mathematica | |complement
| Haskell, Rebol | |bitcmp
| Matlab | |bitInvert
| Smalltalk | |bitwiseComplement
| Io | |invert
| Forth | |\
| Prolog |left shift / right shift / unsigned right shift |规则 | 语言 | | ———————————————————— | ———————————————————— | |
<< / >> / >>>
| CoffeeScript, Java, JavaScript | |<< / >>
| C, C#, C++, Go, Perl, PHP, Pike, Prolog, Python, Ruby, Tcl, YCP | |<<< / >>>
| F# | ||<< / |>>
| Eiffel | |lsl / lsr or asr
| F#, OCaml | |bitshift
| Matlab, PostScript | |bitShift
| Smalltalk | |ashift lshift
| Logo | |lshift / rshift
| Forth | |shiftL / / shiftR
| Haskell | |shiftLeft / shiftRight
| Io | |Shift_Left / Shift_Right / Shift_Right_Arithmetic / Rotate_Left / Rotate_Right
| Ada | |(ash x positive-integer) / (ash x negative-integer) /
| Common Lisp |
Threads
- thread definition
规则 | 语言 |
---|---|
class class_name(threading.Thread) {[override run method] } |
Python |
task task_name is [entry entry_name[(parameter ...)]...] end task_name |
Ada |
task type task_type_name is [entry entry_name[(parameter ...)]...] end task_type_name |
Ada |
class class_name extends Thread {[override run method] } |
Java |
thread ... |
Pliant |
parallel [threads nb_threads] [mini mini_threshold] [maxi maxi_threshold] [active] ... task parallel_instructions [post sequential_instructions] ... |
Pliant |
[NSThread detachNewThreadSelector:mainFunction toTarget:target withObject:obj] |
Objective-C |
- thread creation
规则 | 语言 |
---|---|
object t=Thread.Thread(f) |
Pike |
set t [thread create {code}] |
Tcl |
Thread createThread(...) |
Io |
- thread object creation
规则 | 语言 |
---|---|
MyTask : task_type_name; |
Ada |
class_name MyThread = new class_name() |
Java |
p := [ ... ] newProcess. |
Smalltalk |
p := [ ... ] fork.(140) |
Smalltalk |
- starting / stopping threads
规则 | 语言 |
---|---|
start() / stop()(141) |
Java |
resume / suspend / terminate |
Smalltalk |
Tasks are started when created / call Stop entry or "abort task-object-name" |
Ada |
thread send $t {script} |
Tcl |
- passing data directly between threads
规则 | 语言 |
---|---|
call an entry with parameters |
Ada |
call any public method |
Java |
common variables are copied at thread creation, in abscence of a "share" statement |
Pliant |
use messages, parameters or shared variables(142) |
Smalltalk |
- terminating thread communication due to a time-out
规则 | 语言 |
---|---|
select task_entry_call; or delay timeout_limit; end select; |
Ada |
-
Thread Synchronization
Defining a Synchronized Shared Resource |规则 | 语言 | | ———————————————————— | ——— | |
thread::mutex
| Tcl | |protected Object_Name is [entry entry_name(Parameter : [in out] is type [...]); procedure procedure_name(Parameter : [in out] is type [...]); function function_name return type; private shared data declaration end Object_Name;
| Ada | |synchronize (this){ ... }
| Java | |SharedQueue, Semaphore critical: [...], Future, LazyValue
| Smalltalk |Synchronized Writing to a shared resource |规则 | 语言 | | ———————————————————— | —- | |
Object_Name.Entry_Name(Parms)Object_Name.Procedure_Name(Parms)
| Ada | |Object_Name.SetMethod(Parms)
| Java |Synchronized Reading of a Shared Resource |规则 | 语言 | | ————————— | —- | |
Object_Name.Function_Name
| Ada | |Object_Name.GetMethod()
| Java |Monitor Syntax |规则 | 语言 | | ——————————– | —- | |
Objectg_Name.Entry_Name(Parms)
| Ada | | | | -
Joining Another Thread
Suspending a thread until another thread completes |规则 | 语言 | | ——————————————————- | ———— | |
Call task entry serviced just before task termination
| Ada | |OtherThread.join()
| Java, Python |Suspending a Thread Until Another Thread Establishes An Internal State |规则 | 语言 | | ————————————— | —- | |
Call a task entry on the other thread
| Ada | | | | -
Thread Prioritization
Selecting a Prioritization Model |规则 | 语言 | | —————————————– | —- | |
pragma Locking_Policy(Ceiling_Locking);
| Ada | | | |Establishing a base thread priority |规则 | 语言 | | —————————— | —- | |
pragma Priority(expression);
| Ada | | | |Changing Thead Priority |规则 | 语言 | | ——————————- | ——— | |
Set_Priority(Priority_Value);
| Ada | |setPriority(newPriority);
| Java | |p priority: n
| Smalltalk | -
Thread-safe sharing of data without synchronization
Ensuring access is atomic |规则 | 语言 | | —————————– | —- | |
pragma Atomic(Object_Name);
| Ada | | | |Ensuring access is always via a local copy of the shared data |规则 | 语言 | | ——————————- | —- | |
pragma Volatile(Object_Name);
| Ada | | | |
Remarks
-
(1) introduced in Scheme in R6RS
-
(2) when unused
-
(3) for C, it is not a standard convention, but it is the more widespread
-
(4) any string literal would work
-
(5) see also =head1, =head2, =over, etc
-
(6) need “file: %script-header.r” in file header
-
(7) for user defined functions only
-
(8) displayed <- with a special character
-
(9) variable on the right
-
(10) F#: with indentation
-
(11) the variable behaves like a pointer
-
(12) cf horizontal layout
-
(13) introduce scope
-
(14) Smalltalk: introduce scope
-
(15) ascii representation, original uses a special charset
-
(16) in Modula-2, <> and # are synonyms
-
(17) === and !== differ from == and != when the objects’ type differ
-
(18) for objects
-
(19) normal / structural / unification / arithmetic
-
(20) structural / mathematical
-
(21) deep comparison
-
(22) in List::Util
-
(23) just ‘eval’ evaluates JavaScript
-
(24) Univ operator
-
(25) starting with PHP 5.3
-
(26) procedure call
-
(27) in Pliant, special sugar for only one parameter
-
(28) only for one parameter
-
(29) only for two parameters
-
(30) f is a block
-
(31) Python >= 2.5
-
(32) it does not scale to 3rd argument
-
(33) lambda (x . y) …
-
(34) only final parameter may be variadic and accepts zero or more arguments
-
(35) when callee has special “&” prototype
-
(36) this is a block, not precisely a function, but it’s alike
-
(37) manual declaration of local variables wanted in the closure
-
(38) see also: #1 + #2 &
-
(39) also works for procedures: proc {$ A B} … end
-
(40) x, y, z are the parameters
-
(41) method is optional
-
(42) in Lua, “return xxx” can only appear before a block end. in Matlab, only in inline(‘…’)
-
(43) “return” is used when there is no value to return
-
(44) in Matlab, only for anonymous function
-
(45) firefox
-
(46) C#4, only for “dynamic” objects
-
(47) the result goes to “e”
-
(48) “break”s are mandatory, even for “default”!
-
(49) Perl >= 5.8.0
-
(50) 1 is optional in this example, since min is 1 by default
-
(51) in Ruby, see also catch/throw
-
(52) often provided in the abbreviated form call/cc
-
(53) matches an expression of type t
-
(54) type is infered
-
(55) expression “e” is cast to the type of “v”
-
(56) for parameters
-
(57) quite bad: only the reference is non-mutable whereas the object is still mutable
-
(58) eventual send
-
(59) properties are something alike attributes, but really are methods
-
(60) one level depth
-
(61) general deep copy function
-
(62) object cloning is the default, uses the copy constructor in C++
-
(63) or simply o_ := o for non-polymorphic objects
-
(64) c’Class is the class rooted in c
-
(65) see also isMemberOf
-
(66) assignment attempt
-
(67) see also callable(obj.meth) for unbound methods
-
(68) in Python, usually called self
-
(69) “:” is for external symbols only, recommended
-
(70) directory name is package name
-
(71) if names are exported using @EXPORT
-
(72) if names are not exported or are exported using @EXPORT_OK
-
(73) deprecated in ANSI Common Lisp, but used in ASDF
-
(74) using a correspondance from the package name to the file name
-
(75) inside a function
-
(76) since PHP 5.3
-
(77) no spaces
-
(78) when using format
-
(79) need expandMacros
-
(80) where T is the type of the value
-
(81) see also cPickle
-
(82) but not using the C-like %-syntax
-
(83) adding an end-of-line
-
(84) in BourneShell, adding an end-of-line
-
(85) adding an end-of-line unless already newline-terminated
-
(86) Always case insensitive
-
(87) Always case sensitive
-
(88) faster than isEqual
-
(89) the string is represented on the stack as (addr len)
-
(90) in Lua >= 5.0
-
(91) in C++, is range-checked whereas a[i] is not
-
(92) ESI dialect
-
(93) beware of 0.0 which is true in Pike!
-
(94) Smalltalk: postfix operator
-
(95) in Modula-2, “&” and “and” are synonyms
-
(96) in Oz, simple functions, not operators
-
(97) new in PHP 5.4
-
(98) restricted to initialisation of a local variable in C and C++
-
(99) a b c must be constants
-
(100) beware, if you give only one integer argument, it is the size!
-
(101) for write access: a i o put
-
(102) in C++, it is range-checked whereas a[i] is not. in Smalltalk, for write access: a :at i :put o
-
(103) see also Head
-
(104) list comprehension
-
(105) not in standard
-
(106) in C++, it is done in place
-
(107) in Scheme, not standard, but nearly standard
-
(108) the result is not guaranteed to be the same as the order in the input
-
(109) in Perl, in List::Util
-
(110) Borland extension in Pascal
-
(111) prefix
-
(112) postfix
-
(113) infix
-
(114) optional value is only for pointers
-
(115) only for “access” types in Ada
-
(116) introduced in Perl 5.10
-
(117) attribute selector
-
(118) Java: introduced in 1.5
-
(119) n1, n2, …
-
(120) returns an iterator
-
(121) right-bias
-
(122) left-bias
-
(123) jot on BSD
-
(124) long is a big integer
-
(125) fixed point
-
(126) 0b1 new in PHP 5.4
-
(127) integers are decimals
-
(128) with mathematical priorities
-
(129) APL uses a real multiplication sign for multiplication from a special character set
-
(130) for each various types
-
(131) from instances of Ada.Numerics.Float_Random or Ada.Numerics.Discrete_Random
-
(132) “math/rand” is pseudo random whereas “crypto/rand” is cryptographically random
-
(133) only applies to “math/rand”
-
(134) Ruby >= 1.7
-
(135) method on big.Int
-
(136) replace Float with whatever type you are using
-
(137) in module Data.Bits
-
(138) see also bit-and / bit-or / bit-xor
-
(139) see also bit-not
-
(140) equivalent to newProcess + resume
-
(141) “stop” is now deprecated
-
(142) a thread is created from a block, which is a closure on the variables as seen by the block