Syntax Across Programming Languages
Introduction
What's this about?
- Language Designers:
Looking for operator or function names? Well have a look at the following and remember using existing one may ease the transition :)
- Language Users:
You know one language and want to find the corresponding operator or function in another language
- Language lovers:
Want to know the various ways people invented for commenting/assigning/...?
Categories
- Various
- commenting
- documentation comment
- information about the current line and file
- tokens
- breaking lines (useful when end-of-line and/or indentation has a special meaning)
- variable assignment or declaration
- grouping expressions
- block (grouping statements, especially when statements are not expressions)
- use a block as a return value (when statements are not expressions)
- equality / inequality
- comparison
- runtime evaluation
- force garbage collection
- Functions
- Control Flow
- Types
- Object Oriented & Reflexivity
- Package, Module
- Strings
- type name
- character type name
- character "z"
- strings
- multi-line
- convert something to a string (see also string interpolation)
- serialize (marshaling)
- unserialize (un-marshaling)
- sprintf-like
- simple print
- string equality & inequality
- string size
- string concatenation
- duplicate n times
- upper / lower case character
- uppercase / lowercase / capitalized string
- ascii to character
- character to ascii
- accessing n-th character
- extract a substring
- locate a substring
- locate a substring (starting at the end)
- Booleans
- Bags and Lists
- type name
- list concatenation
- list flattening
- list constructor
- list/array indexing
- adding an element at the beginning (list cons)
- adding an element at index
- adding an element at the end
- first element
- all but the first element
- last element
- get the first element and remove it
- get the last element and remove it
- for each element do something
- transform a list (or bag) in another one
- transform two lists in parallel
- find an element
- keep elements matching
- f(... f(f(init, e1), e2) ..., en)
- f(e1, f(e2, ... f(en, init) ...))
- split a list in 2 based on a predicate
- is an element in the list
- is the predicate true for an element
- is the predicate true for every element
- smallest / biggest element
- join a list of strings in a string using a glue string
- list size
- iterate with index
- remove duplicates
- sort
- reverse
- list of couples from 2 lists
- 2 lists from a list of couples
- lookup an element in a association list
- list out of a bag
- Various Data Types
- Mathematics
- type name
- numbers syntax
- addition / subtraction / multiplication / division
- exponentiation (power)
- negation
- random
- operator priorities and associativities
- square root / e-exponential / absolute value
- trigonometry
- logarithm
- euclidian division (both quotient and modulo)
- modulo
- truncate / round / floor / ceil
- bitwise operators
- Threads
Various
- commenting
until end of line
# Awk, E, Icon, merd, Perl, Perl6, PHP, Pliant, Python, Ruby, sh, Tcl, YAML // BCPL, C#, C++, C99, Dylan, Java, JavaScript, PHP, Pike, YCP -- Ada, Cecil, Eiffel, Haskell, Lua, Sather, Simula, SQL92 ; Assembler, Common Lisp, Emacs Lisp, Rebol, Scheme % Erlang, Mercury, Oz, PostScript, Prolog, TeX rem Basic ' Visual Basic \ Forth ! Assembler, Fortran90 C or * in column 1 Fortran nestable
(* ... *) Beta, Modula-3, OCaml, Pascal, SML /* ... */ Classic REXX, Dylan, Oz, SQL99 { ... } Pascal {- ... -} Haskell #| ... |# Common Lisp #if 0 ... #endif C comment { ... } Rebol comment [ ... ] Rebol { ... } or [ ... ] when unused Rebol --[[ ... ]] Lua non nestable
" ... " Smalltalk /* ... */ B, C, C#, C++, Java, JavaScript, Mercury, PHP, Pike, PL/I, YCP <!-- ... --> HTML, XML ( ... ) Forth - documentation comment
until end of line
/// C#, Java -- | Haskell -- ^ Haskell non nestable
/** ... */ (1) C, C#, E, Java, PHP {-| ... -} Haskell (** ... *) OCaml indexing identifier: "..."; Eiffel rebol [ Note: "..." ] Rebol func ["..." arg] ... Rebol class X: """... """ def x(): """... """
(2)Python (define (f para1 para2) "..." ...) Scheme (defun f (para1 para2) "..." ...) Common Lisp, Emacs Lisp =pod ... =cut
(3)Perl, Perl6 =begin ... =end
Ruby - information about the current line and file
__LINE__ __FILE__ C, C++, Perl, PHP, Pike, Ruby $?LINE $?FILE Perl6 inspect.stack()[0][2] inspect.stack()[0][1] Python (new System.Diagnostics.StackFrame(true)).GetFileLineNumber() (new System.Diagnostics.StackFrame(true)).GetFileName()
C# system/script/header/file (4) Rebol SOURCELINE() / parse source OS . SOURCENAME Classic REXX - tokens
case-sensitivity (keywords, variable identifiers...)
case-sensitive Awk, B, C, C#, C++, Haskell, Java, JavaScript, Lua, merd, Modula-3, OCaml, Perl, Perl6, Pike, Pliant, Python, Ruby, sh, Smalltalk, Tcl, XML, YAML case-insensitive Ada, Assembler, Classic REXX, Common Lisp, Eiffel, Forth, HTML, Pascal, PL/I, Rebol, Scheme, SGML, SQL92, Visual Basic case-sensitive: variables
case-insensitive: keywords, functions, constants...PHP case-sensitive: identifiers
case-insensitive: keywordsE if case sensitive, what is the standard way for scrunching together multiple words
CamelCase C#, E, Haskell, Java, JavaScript, Pascal, Smalltalk, Tcl underscores merd hyphens Common Lisp, Rebol underscores for functions, unclear for modules / types / constructors OCaml UPPER_CASE sh underscores, UPPER_CASE for class names Eiffel CamelCase for classes, underscores for methods Python CamelCase for types, underscores for functions, variables, ... Pliant 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 usually lowercase or underscores, ALL_CAPS for macros C usually underscores C++ Camel_Case Ada variable identifier regexp
[a-zA-Z][a-zA-Z0-9]* PL/I, Smalltalk [a-zA-Z][_a-zA-Z0-9]* Eiffel [a-zA-Z](_?[a-zA-Z0-9])* Ada [_a-zA-Z][_a-zA-Z0-9]* Awk, B, C, C#, C++, E, Perl, Perl6, PHP, Python, sh, Tcl [_a-zA-Z][_a-zA-Z0-9]* or '[^']*' Pliant [_a-zA-Z$][_a-zA-Z0-9$]* Java, JavaScript [_a-z][_a-zA-Z0-9]* Ruby [_a-z][_a-zA-Z0-9]*[!?']* merd [_a-z][_a-zA-Z0-9']* Haskell, OCaml, SML [_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 \S+ Forth function identifier regexp (if different from variable identifier regexp)
[_a-zA-Z][_a-zA-Z0-9]*[!?]? Ruby [_a-z][_a-zA-Z0-9]* Mercury, Prolog [^ \t\n\r\f]+ Tcl keyword regexp (if different from variable identifier regexp)
[A-Z]+ Modula-3 type regexp (if different from variable identifier regexp)
[_A-Z][_a-zA-Z0-9']* Haskell [_a-z][_a-zA-Z0-9']* Mercury, OCaml constant regexp (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, Eiffel, Emacs Lisp, Forth, Java, JavaScript, OCaml, Oz, Pascal, Perl, Perl6, PostScript, Rebol, Scheme, Smalltalk, SML, XSLT, YCP \ Awk, E, Python, Ruby, sh, Tcl _ Visual Basic , Classic REXX - variable assignment or declaration
assignment
= Awk, B, Basic, C, C#, C++, Classic REXX, Erlang, Icon, Java, JavaScript, Lua, Oz, Perl, Perl6, PHP, Pike, sh, YCP := Ada, BCPL, Cecil, Dylan, E, Eiffel, Modula-3, Pascal, Pliant, Sather, Simula, Smalltalk <- OCaml _ (5) Squeak : BCPL, Rebol -> (6) Beta def PostScript setq Emacs Lisp setf setq set Common Lisp set Rebol set! Scheme is Prolog declaration
= Haskell, Mercury, Prolog, SML <- Haskell :- Prolog let v = e in OCaml let v = e BCPL def v := e / var v := e E my / our / local / use vars Perl my / our / temp Perl6 define Dylan define let let* letrec Scheme let let* flet labels defun defmethod defvar defparameter defsetf .. Common Lisp local V1 = e V2 = e2 in ... end Oz global Python :@ Beta : Ada, Eiffel, Pascal | v1 v2 | Smalltalk auto v1, v2; extrn v3, v4; B var JavaScript var gvar Pliant variable v (7) Forth <xsl:variable name="v" select="e"/> XSLT both
= merd, Python, Ruby := merd set, variable Tcl - grouping expressions
( ... ) Ada, Awk, B, BCPL, Beta, C, C#, C++, Classic REXX, E, Eiffel, Haskell, Java, JavaScript, Lua, merd, Modula-3, MSH, OCaml, Oz, Pascal, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, Smalltalk, SML, SQL92, Tcl, XPath, YCP [ ... ] Rebol indentation merd $ ... Haskell begin ... end OCaml, Ruby BEGIN ... END Modula-3 space (8) merd - block (grouping statements, especially when statements are not expressions)
{ ... } Awk, JavaScript, PHP, Pike, sh, Tcl { ... } (9) B, C, C#, C++, E, Haskell, Java, Modula-3, Perl, Perl6, YCP ( ... ) (9) sh [ x. y. ... ] Smalltalk begin ... end (9) Ada, Pascal do ... end Classic REXX do ... end (9) Lua, PL/I indentation Pliant, Python indentation (9) Haskell, merd foo ... end where foo in { if, do, ... } Modula-2, Ruby foo ... end where foo in { if, loop, ... } Eiffel foo ... end foo where foo in { if, do, ... } Ada, Fortran90 (* ... *) (10) BCPL (# ... #) Beta - use a block as a return value (when statements are not expressions)
valof BCPL do Perl, Perl6 - equality / inequality
shallow
== != Awk, B, C, C++, Java, OCaml, Perl, Perl6, Pike, Tcl = /= Eiffel, Fortran90 = <> Pliant, Rebol = # Modula-3 = != sh = <> # (11) Modula-2 == === != !== (12) JavaScript, PHP === !== PHP5 == ~= Lua == ~~ Smalltalk == ~== Dylan = ~= neqv (10) BCPL is_equal (13) Eiffel equal? Scheme eq ne Emacs Lisp, PostScript eq, eql Common Lisp eq? eqv? Scheme .EQ. .NE. Fortran is / is not Python deep
== != Awk, C#, C++, E, merd, PHP5, Python, Ruby, YCP == <> Python == /= Haskell == \= Oz == \== Classic REXX = /= Ada = != XPath = <> Beta, OCaml, Pascal, Rebol, SML, SQL92, Visual Basic = ~= Dylan, Smalltalk equal? Scheme equals Java equal Emacs Lisp equal, !equal Pike equal, equalp Common Lisp deep_is_equal Eiffel isEqual Objective-C - comparison
< > <= >= Ada, Awk, Awk, B, Beta, C, C#, C++, Classic REXX, Common Lisp, Dylan, E, Eiffel, Emacs Lisp, Haskell, Java, JavaScript, Lua, merd, Modula-3, OCaml, Pascal, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, Scheme, Smalltalk, SML, SQL92, Tcl, Visual Basic, XPath, YCP < > =< >= Mercury, Oz << >> <<= >>= (14) Classic REXX @< / @=< / @> / @>= Prolog lt gt le ge Perl, Perl6, PostScript -lt -gt -le -ge MSH, sh .LT. .GT. .LE. .GE. Fortran returns 3 values (i.e. inferior, equal or superior)
a <=> b merd, Perl, Perl6, Ruby cmp Perl, Perl6, Python compare Haskell, Mercury, OCaml, Pliant, Smalltalk strcmp PHP three_way_comparison Eiffel string compare Tcl compareTo Java returns 4 values (i.e. inferior, equal, superior or not comparable)
compare Pliant compareTo E min / max (binary or more)
min / max Ada, Beta, C++, Common Lisp, Dylan, E, Eiffel, Haskell, Java, Lua, merd, OCaml, Pike, Pliant, Python, Rebol, Scheme, Smalltalk, SQL92 min minstr / max maxstr (15) Perl Min / Max Oz MIN / MAX Classic REXX, Modula-3 measure-object -min / measure-object -max MSH - runtime evaluation
eval Common Lisp, Emacs Lisp, JavaScript, Perl, Perl6, PHP, Python, Ruby, Scheme, Tcl, YCP dostring Lua Compiler evaluate: Smalltalk runtime_compile / compile + execute Pliant Compiler.evalExpression or Compiler.parseOzVirtualString Oz compile_string Pike interpret Classic REXX do / reduce / compose / load Rebol [...] Tcl `...` sh - force garbage collection
doGC Beta GC.start Ruby gc() Pike System.gc() Java System.gcDo Oz System.GC.Collect() C# gc.collect() Python full_collect Eiffel garbage_collect Mercury collectgarbage Lua VM.garbageCollect() JavaScript Gc.full_major() OCaml Smalltalk garbageCollect Smalltalk incremental garbage collection => not needed Perl, Perl6 recycle Rebol interp.gc() E (ext:gc) Common Lisp
Functions
- function call
f(a,b,...) Ada, Awk, Awk, B, C, C#, C++, Dylan, E, Eiffel, Java, JavaScript, Lua, Mercury, merd, Modula-3, Pascal, Perl, Perl6, PHP, Pike, Prolog, Python, Ruby, XPath, YCP f(a,b,...f) or f[a,b,...] depending on the version BCPL f a b ... Haskell, MSH, OCaml, Pliant, Rebol, sh, SML, Tcl (f a b ...) (apply f l) Scheme (f a b ...) (apply f l) (funcall f a b ...) Common Lisp, Emacs Lisp {f a b} Oz f[a,b,...] or f.call(a,b,...) Ruby &$f(a,b,...) or $f->(a,b,...) Perl $f.(a,b,...) Perl6 v = f(a, b, ...) or call f a, b, ... Classic REXX a b ... f Forth, PostScript a f Smalltalk a f: b g: ... (16) Smalltalk (a,b,...)->&f or (a,b,...)->f Beta f:a FL f:a (17) Pliant .. [ 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, Eiffel, Haskell, Mercury, MSH, Pascal, Perl, Perl6, Pliant, PostScript, Prolog, Rebol, Ruby, sh, Tcl f() Awk, C, C#, C++, E, Java, JavaScript, Lua, Pike, Python, YCP f() (18) merd, OCaml, SML (f) Scheme (f) (funcall f) Common Lisp, Emacs Lisp {f} Oz f[] or f.call Ruby &$f or $f->() Perl $f.() Perl6 v = f() or call f Classic REXX f value (19) Smalltalk <xsl:call-template name="f">/ XSLT call f Fortran - partial application (in the examples below, a normal call is "f(a,b)")
give the first argument
f a Haskell, OCaml, SML f(a) Mercury f(a,) merd &f.assuming(var_name => a) Perl6 functional.partial(f, a) Python give the second argument
f(,b) merd &f.assuming(b => b) Perl6 give the first argument to operator ">"
(a >) Haskell, merd (>) a 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 = ... OCaml f(para1, para2, ...) = valof $( ... $) BCPL f(para1, para2, ...) = ... merd f ... or f: para1 ... Smalltalk f: func [para1 para2 ...] ... Rebol /f { ... } def PostScript typ0 f(typ1 para1, typ2 para2, ...) { ... } C, C#, C++, Pike, YCP function f(para1, para2) { ... } Awk, JavaScript function f(para1, para2) ... code ... end Lua 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 proc f {para1 para2} { ... } Tcl :- 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() { ... } sh f : procedure ... return retval
Classic REXX procedures
procedure f(para1 : typ1, para2 : 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 Sub f(para1, para2) ... End Sub Visual Basic f : procedure ... return
Classic REXX predicates
f(Para1, Para2, ....) :- ... . Prolog - anonymous function
sub { my ($a, $b) = @_; ... } Perl { my ($a, $b) = @_; ... } (20) Perl { ... } (arguments are in the stack PostScript { param(para1, [typ2]para2, ...) ... } MSH {|a, b| ... } (21) Ruby [:a :b| ... ] Smalltalk lambda a, b: ... Python lambda(typ1 para1, typ2, para2, ...) { ... }; Pike (a, b) => ... C#3 a, b -> ... merd -> $a, $b { ... } Perl6 \a b -> ... Haskell fn (a, b) => ... SML fun a b -> ... OCaml (func(A, B) = C :- ...) Mercury function(a, b) ... JavaScript function(a, b) ... end Lua fun(a, b) -> ... end Erlang fun {$ A B} ... end (22) 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 method(a, b) ... end method (23) Dylan create_function(',','...') PHP delegate(ta a, tb b) { ... } C#2 - function return value
breaks the control flow
return Ada, Awk, B, C, C#, C++, Classic REXX, ClassicREXX, E, Java, JavaScript, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, sh, Tcl, YCP return (24) Lua Return Visual Basic RETURN Modula-3 resultis / return (25) BCPL return from xxx / return Common Lisp ^ Smalltalk function body is the result
no syntax needed Common Lisp, Dylan, Emacs Lisp, Haskell, OCaml, Oz, Perl, Perl6, Rebol, Ruby, Scheme, SML setting the result
Result := val Eiffel <function name> := val Pascal - function called when a function is not defined (in dynamic languages)
AUTOLOAD Perl AUTOSCALAR, AUTOMETH, AUTOLOAD... Perl6 __getattr__ Python method_missing Ruby doesNotUnderstand Smalltalk unknown Tcl no-applicable-method Common Lisp doesNotRecognizeSelector Objective-C match [name, args] { ... } E the predicate fail Prolog - runtime inspecting the caller information
caller Perl, Perl6, Ruby inspect.stack()[1] Python backtrace Pike trace 'I' Classic REXX - function composition
. Haskell ~ merd o SML compose Dylan - identity function
id Haskell identity Common Lisp yourself Smalltalk
Control Flow
- sequence
, C, C++, JavaScript, Perl, Pike, Prolog . Smalltalk ; Ada, Awk, B, Beta, C, C#, C++, E, Haskell, Java, JavaScript, merd, Modula-3, OCaml, Pascal, Perl, Perl6, PHP, Pike, PL/I, Pliant, Python, Ruby, sh, SML, Tcl, YCP nothing, optionally ; Classic REXX, Lua space Eiffel, Rebol end-of-line Assembler, Awk, Basic, E, Fortran, Haskell, JavaScript, Lua, merd, Pliant, Python, Ruby, sh, Tcl (begin ...) Scheme (progn ...) (prog1 ...) (prog2 ...) Common Lisp, Emacs Lisp >> Haskell - if_then
if c then b merd, OCaml, Pascal if c then b end Eiffel, Lua, Oz, Ruby if c then b end if Ada if c; then b; fi sh if (c) then b end Dylan if c do b BCPL IF c THEN b END Modula-2, Modula-3 if (c) b Awk, B, C, C#, C++, Java, JavaScript, PHP, Pike, YCP if c: b Python if c b Pliant, Rebol, Tcl if (c): b endif PHP if c {b} Perl6 if (c) {b} E, Perl c -> b FL c b if PostScript b if c Perl, Ruby c if b1 then Forth (if c b) Common Lisp, Scheme (when c b) Emacs Lisp c ifTrue: b Smalltalk <xsl:if test="c">b</xsl:if> XSLT If c Then b Visual Basic If c b End If
Visual Basic if c; b end Ruby if c b end
Ruby if c then ; b if c then b if c then do b ... end
Classic REXX - if_then_else
if c then b1 else b2 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 ?then? b1 elsif 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; fi sh 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 (if c b1 b2) Common Lisp, Scheme (if c then b1 else b2) Mercury (c -> b1 ; c2 -> b2 ; b3) Mercury c -> b1 ; c2 FL c ifTrue: b1 ifFalse: b2 Smalltalk 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 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 (26) 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, YCP c ?? b1 :: b2 Perl6 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 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 then ; b1 ; else ; b2 if c then b1 else b2 if c then do b1 ... end else do b2 ... end
Classic REXX - ifnot_then (unless)
unless Emacs Lisp, Perl - multiple selection (switch)
switch (val) { case v1: expr1; break; case v2: case v3: expr23; break; default: expr_else; }
C, C++, Java, JavaScript, PHP, Pike switch val { case v1: expr1; goto done; case v2: case v3: expr23; goto done; } expr_else; done:
B switch (val) { case v1: expr1; break; case v2: case v3: expr23; break; default: expr_else; break; }
(27)C# switch (val) { match v1 { expr1 } match v2 { expr2 } match _ { expr_else } }
E switchon val case v1: expr1 case v2: expr2 default: expr_else
BCPL case val of v1 : expr1; v2, v3 : expr23 else expr_else end
Pascal case val in v1) statement1 ;; v2|v3) statement23 ;; *) statement_else ;; esac
sh (if val // v1 then expr1 // v2 then expr2 else expr_else if)
Beta match val with | v1 -> expr1 | v2 | v3 -> expr23 | _ -> expr_else
OCaml case val of v1 => expr1 | v2 => expr2 | _ => expr_else
SML CASE val OF v1 => expr1 | v2 => expr2 ELSE => expr_else END
Modula-3 case val of v1 -> expr1 v2 -> expr2 _ -> expr_else
Haskell val. v1 -> expr1 v2 -> expr2 _ -> expr_else
merd (case val ((v1) expr1) ((v2) expr2) (otherwise expr_else))
Common Lisp (case val ((v1) expr1) ((v2) expr2) (else expr_else))
Scheme case val is when v1 => expr1 when v2 | v3 => expr23 when others => expr_else end case;
Ada case val when v1; expr1 when v2, v3; expr23 else expr_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, expr1 ; X = v2, expr2 ; expr_else)
Mercury, Prolog my %case = ( v1 => sub { expr1 }, v2 => sub { expr2 }, ); if ($case{val}) { $case{val}->() } else { expr_else }
Perl use Switch; switch ($val) { case v1 { expr1 } case v2 { expr2 } else expr_else })
(28)Perl given $val { when v1 { expr1 } when v2 { expr2 } default { expr_else } }
Perl6 Select val Case v1 expr1 Case v2, v3 expr2 Case Else expr_else End Select
Visual Basic switch (val) { v1 { expr1 } v2 { expr2 } default { expr_else } }
MSH switch val [ v1 [expr1] v2 [expr2] ] switch/default [ v1 [expr1] v2 [expr2] ][expr_else]
Rebol val caseOf: {[v1]->[expr1]. [v2]->[expr2]} otherwise: expr_else Squeak select when v1 expr1 when v2 | v3 expr23 otherwise expr_else end
Classic REXX CASE val WHEN v1 THEN expr1 WHEN v2 THEN expr2 ELSE expr_else END
SQL92 - loop
forever loop
loop merd, PostScript, Ruby loop expr end loop Ada LOOP expr END Modula-3 (loop do expr) Common Lisp cycle (# do ... #) Beta repeat Squeak forever Rebol Do expr Loop
Visual Basic do forever ... end
Classic REXX while condition do something
while (cond) expr Awk, B, C, C#, C++, E, Java, JavaScript, Perl, Perl6, PHP, Pike, Python, Ruby, YCP while cond expr Tcl while cond loop expr end loop Ada while cond do expr BCPL, Pascal, SML while cond do expr done OCaml WHILE cond DO expr end Lua while cond; do expr; done sh while [cond][expr] Rebol cond whileTrue: expr Smalltalk (loop while cond do expr) Common Lisp loop (# while ::< (# do cond -> value #) do expr #) Beta begin cond while expr repeat Forth from until not cond loop expr end Eiffel while cond expr
Pliant Do While cond expr Loop
Visual Basic do while cond ... end
Classic REXX do something until condition
do expr until cond Perl6 do {expr} until cond Perl do {expr} while (!cond) Awk, C, C#, C++, Java, JavaScript, Pike begin expr end until cond Ruby REPEAT expr UNTIL cond Modula-3 loop (# until ::< (# do cond -> value #) do expr #) Beta loop expr exit when cond end loop Ada (loop do expr until cond) Common Lisp expr repeatuntil cond BCPL repeat expr until cond Lua, Pascal repeat expr until (29) YCP until [expr cond] Rebol [expr . cond] whileFalse Squeak Do expr Loop Until cond
Visual Basic for each value in a numeric range, 1 increment (see also the entries about ranges)
for (int i = 1; i <= 10; i++) expr C, C# foreach my $i (1 .. 10) { expr } Perl foreach ($i in 1..10) { expr } MSH for (1 .. 10) -> $i { expr } Perl6 for i := 1 to 10 do expr Pascal for i = 1 to 10 do expr done OCaml For i = 1 To 10 expr Next Visual Basic for i in 1 .. 10 loop ... end loop Ada for i in range(1, 11) Python for i in `seq 1 10`; do expr; done sh 1 1 10 expr for PostScript (1..10).each {|i| expr } Ruby 1.upto(10) {|i| expr } Ruby do i = 1 for 10 ... end
Classic REXX for each value in a numeric range, 1 decrement
for X := 10 downto 1 do expr Pascal for i = 10 downto 1 do expr done OCaml for i in reverse 1 .. 10 loop ... end loop Ada for (int i = 10; i >= 1; i--) expr C, C# for (my $i = 10; $i >= 1; $i--) { expr } Perl loop (my $i = 10; $i >= 1; $i--) { expr } Perl6 for i in range(10, 0, -1) Python for i in `seq 10 -1 1`; do expr; done sh 10 -1 1 expr for PostScript 10.downto(1) {|i| expr } Ruby do i = 10 to 1 by -1 ... end
Classic REXX for each value in a numeric range, free increment
for (int i = 1; i <= 10; i += 2) expr C, C# for (my $i = 1; $i <= 10; $i += 2) { expr } Perl loop (my $i = 1; $i <= 10; $i += 2) { expr } Perl6 for i in range(1, 11, 2) Python for i in `seq 1 2 10`; do expr; done sh 1 2 10 expr for PostScript (1..10).step(2) {|i| expr } Ruby do i = 1 to 10 by 2 ... end
Classic REXX for "a la C" (while + initialisation)
for Awk, C, C#, C++, Java, JavaScript, MSH, Perl, PHP, Pike, Tcl loop Perl6 for ((x = 0; x < 10; x++)); do ...; done sh from init_code until cond loop ... incr_statement end Eiffel - breaking control flow
returning a value
return Ada, Awk, B, C, C#, C++, Classic REXX, ClassicREXX, E, Java, JavaScript, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, sh, Tcl, YCP return (24) Lua Return Visual Basic RETURN Modula-3 resultis / return (25) BCPL return from xxx / return Common Lisp ^ Smalltalk goto (unconditional jump)
goto Ada, B, Basic, BCPL, C, C#, C++, Cobol, Fortran, Pascal, Perl go throw Common Lisp signal Classic REXX continue / break
continue / break Awk, C, C#, C++, E, Java, JavaScript, PHP, Pike, Python, YCP next / last Perl, Perl6 next / break (30) Ruby / break BCPL, Lua / break/return Rebol / exit Ada, PostScript restart / leave Beta, Pliant / Exit Do, Exit For Visual Basic / return from xxx or return Common Lisp iterate / leave Classic REXX redo / retry
redo/ Perl, Perl6 redo / retry Ruby - exception
throwing
raise Ada, Eiffel, merd, OCaml, Python, Ruby, Scheme-SRFI34, SML RAISE Modula-3 raise ... end Oz throw C#, C++, E, Erlang, Haskell, Java, JavaScript, Pike, Rebol throw/name Rebol die Perl, Perl6 return -code Tcl error Common Lisp, Dylan, Emacs Lisp, Lua, Lua, Pliant signal Common Lisp, Dylan, Smalltalk signal predefined_condition_name Classic REXX cerror warn Common Lisp [NSException raise:name ...] Objective-C catching
try: a except exn: b Python try a with exn -> b OCaml try a catch (exn) b C#, C++, Java, JavaScript try a catch e then b end Oz try { a CATCH e { b } } Perl6 TRY a EXCEPT exn => b END Modula-3 a handle exn => b SML a on: exception_name do: [:exn | b] Smalltalk ifCurtailed Smalltalk rescue Eiffel, Ruby eval {a}; if ($@) b Perl exception when exception_name => Ada catch a (\e -> b) Haskell catch Erlang, Rebol, Tcl catch/name Rebol catch(expr) or catch { ... }; Pike pcall Lua with-exception-handler or guard Scheme-SRFI34 block a exception(exn) b end Dylan ?, shy, safe Pliant handler-bind handler-case ignore-errors Common Lisp NS_DURING a NS_HANDLER b NS_ENDHANDLER Objective-C signal on predefined_condition_name ... predefined_condition_name : ...
Classic REXX cleanup: code executed before leaving
ensure Ruby, Smalltalk finally C#, Java, 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 continue Python resume execution where the exception took place
resume Smalltalk - call-with-current-continuation
call-with-current-continuation (31) Scheme callcc Ruby, SML-NJ
Types
- declaration
typedef t n C, C++, Pike type n is t Ada type n ... Pliant type n = t 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 n : t Beta (deftype n () 't) Common Lisp - annotation (or variable declaration)
: Ada, E, Eiffel, Modula-3, OCaml, SML :: Dylan, Haskell, Mercury !! merd t v C, C#, C++, Java, Perl6, Pike, Pliant, YCP (declare (v t)) Common Lisp v :@ t Beta - cast
upcast
(t) e C, C#, C++, Java, PHP t(e) Ada, Pascal [t] e Pike static_cast<t>(e) C++ e :> t OCaml CAST(e as t) SQL92 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# v ?= e (32) Eiffel NARROW(e, t) Modula-3 computed conversion (calls an internal or a user-defined function)
(t) e C++, Pike [t] e MSH t(e) C++ e : t E cast e t Pliant expr cast t Pliant make t e / to t e Rebol - mutability, constness
type of a mutable value
it is the default Ada, C, C#, C++, Java val x: T Pascal T ref OCaml, SML STRef a T Haskell type of a constant value
const T C++, C99 constant T Ada const x: T Pascal it is the default Haskell, OCaml, SML special cases
"readonly" fields (33) C# "final" fields, parameters, local variables (33) Java
Object Oriented & Reflexivity
- method invocation
object.method(para) Beta, C#, C++, Cecil, Delphi-Kylix, E, Eiffel, Icon, Java, JavaScript, merd, Modula-3, MSH, Perl6, Python, Ruby, Sather, Visual Basic object#method para OCaml object:method(para) Lua object method para Pliant, Tcl object method: para1 method_continuation: para2 Smalltalk object <- method(para) (34) 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 para->method Beta (send object method para) MzScheme with no parameter
object.method Eiffel, merd, Perl6, Ruby object.property (35) C# object.method() C#, C++, E, Java, JavaScript, Python object#method OCaml object:method Pliant object->method Perl object->method() Pike object/method Rebol object["method"]() Pike object method Smalltalk [ object method ] Objective-C method object Haskell, Mercury (method object) Common Lisp method(object) Ada, Dylan (send object method) MzScheme - object creation
new Ada, C#, C++, Java, JavaScript, OCaml, Perl, Perl6, PHP, Pliant, Ruby, Simula, Smalltalk class_name() Pike, Python !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 (36) Eiffel, Ruby o.deep_clone Eiffel o.clone() Java o.Clone() C# clone / copy or deepCopy Smalltalk dclone Perl [o copy] Objective-C copy.copy(o) (37) Python purecopy Emacs Lisp {< >} or Oo.copy o OCaml o2 = o (38) C++, PHP o2.all := o.all Ada make o [] Rebol - manually call an object's destructor
delete C++, JavaScript destroy Java, Pike DESTROY Perl dealloc Objective-C Dispose C# __del__ Python Requires instantiation of Ada.Unchecked_Deallocation Ada - class declaration
class C#, C++, Haskell, Java, MzScheme, OCaml, Perl6, PHP, Pike, Python, Ruby class c inherit p1 p2 ... feature decl decl ... end Eiffel defclass defstruct Common Lisp subclass Smalltalk type Pliant type c is tagged record ... end record Ada @interface c { ... } ... @end Objective-C : Beta - testing class membership
isa Perl is_a? kind_of? Ruby o.meta.isa Perl6 isKindOf Smalltalk isKindOfClass Objective-C dynamic_cast C++ instanceof Java, JavaScript isinstance Python in Ada is C# is_a PHP 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 (39) Eiffel - get the type/class corresponding to an object/instance/value
class Objective-C, Ruby, Smalltalk __class__ Python getClass Java typeid C++ typeof C#, JavaScript type-of Common Lisp ref Perl generator Eiffel meta Perl6 object_program Pike getAllegedType E - methods available
methods Ruby get_class_methods PHP getMethods Java get-member MSH indices Pike o.meta.getmethods Perl6 o.__class__.__dict__ (40) Python 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 Java 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 (defclass child (parent) ...) Common Lisp @interface child : parent { ... } ... @end Objective-C @ISA = qw(parent1 parent2) Perl - has the method
can Perl, Perl6 respond_to? Ruby respondsTo E, Smalltalk respondsToSelector Objective-C hasattr(obj, "meth") (41) Python object->method Pike all [in object 'method function? get in object 'method] Rebol find-method Common Lisp - current instance
this Beta, C#, C++, Java, JavaScript, PHP, Pike THIS Simula self Objective-C, Rebol, Ruby, Smalltalk object_name if defined as: def object_name { ... } E Current Eiffel first parameter Perl, Pliant, Python first parameter (42) Python dispatching parameter Ada, Common Lisp Me Visual Basic . Perl6 - accessing parent method
super E, Java, Objective-C, Ruby, Smalltalk super(Class, self).meth(args) Python base C# Precursor Eiffel $o.SUPER::method(...) Perl6 $o->SUPER::method(...) Perl method(parent(dispatching-parameter)) Ada call-next-method Common Lisp - accessing child method
inner Beta
Package, Module
- package scope
. Ada, C#, E, Haskell, Java, Modula-3, OCaml, Pascal, Python, Ruby, SML : XML :: C++, merd, Perl, Tcl, YCP : :: (43) Common Lisp ' Perl __ Mercury - declare
package p; Java, Perl namespace p { ... } C#, C++ module p where ... Haskell module P ... end Ruby { module "p"; ... } YCP :- module(p) Prolog (defpackage p ...) Common Lisp automatically done based on the file name OCaml, Python <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 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 (export 'name1 'name2) Common Lisp attached to each name (public, private...) Java, Pike append_features Ruby - import
everything into current namespace
use p (44) Perl uses p Pascal using p C# using namespace p; C++ (use-package 'p) Common Lisp open p 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 inherit c export {NONE} all end Eiffel include or even extend Ruby do Rebol 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 using p::name1; using p::name2; ... C++ with p; use type p.type1; ... Ada def name := <import:p.name> E :- use_module(name1, name2, ...) Prolog package (ie. load the package)
import p Python use p; (45) Perl require p Perl require "p" Ruby (require 'p) (46) Common Lisp with p; Ada automatically done (47) Java, OCaml
Strings
- type name
char[] C char const[] C++ string C#, C++, OCaml, Pascal, Pike, YCP string! Rebol String Ada, C#, Haskell, Java, JavaScript, merd, Smalltalk, Visual Basic STRING Eiffel str YAML Str Perl6, Pliant NSString * Objective-C CHAR, VARCHAR(size) SQL92 - character type name
char C, C#, C++, OCaml char! Rebol Char Haskell, merd, Perl6 Character Ada, Smalltalk CHARACTER Eiffel - character "z"
'z' Ada, B, C, C#, C++, Classic REXX, E, Eiffel, Haskell, OCaml, Pascal, Pike, Prolog "z" Classic REXX, merd, sh $z Smalltalk #\z Common Lisp, Scheme #"z" Rebol &z Oz ?z Emacs Lisp, Ruby - strings
verbatim
'...' Beta, Classic REXX, JavaScript, Lua, Pascal, Perl, Perl6, PHP, Prolog, Python, Ruby, sh, Smalltalk, SQL92, YAML "..." Ada, Awk, C, C#, C++, Classic REXX, Common Lisp, Dylan, E, Eiffel, Emacs Lisp, FL, Haskell, Java, JavaScript, Lua, Modula-3, OCaml, Oz, Pike, Pliant, Python, Rebol, Scheme, SML, YAML, YCP "..." or '...' XPath '''...''', """...""" Python [[ ... ]] Lua <<'MARK' ... MARK Perl, Ruby, sh {...{...}...} Tcl (...) PostScript q(...(...)...), q[...], q{...}, q<...>, q/.../ Perl, Perl6 %q(...(...)...), %q[...], %q{...}, %q<...>, %q/.../ Ruby q(...(...)...) merd @"...""..." C# @"..." Objective-C with interpolation
"... $v ..." Perl, Perl6, PHP, sh, Tcl "... {v} ..." merd "... #{v} ..." "... #$v ..." "... #@v ..." "... #@@v ..." Ruby <<MARK ... $v ... MARK Perl, sh <<MARK ... #{v} ... MARK Ruby <<<MARK ... $v ... MARK PHP [ subst {...{... $v ...}...} ] Tcl qq(...(... $v ...)...), qq[...], qq{...}, qq<...>, qq/.../ Perl, Perl6 %Q(...(... #{v} ...)...), %Q[...], %Q{...}, %Q<...>, %Q/.../ Ruby qq(...(... {v} ...)...) merd "... %(v)s ..." % vars() Python end-of-line (without writing the real CR or LF character)
"\n" C, C#, C++, Java, JavaScript, Lua, Perl, Perl6, Pike, Python, Ruby, YCP "*n" B, BCPL "%N" Eiffel "^/" Rebol "~%" (48) Common Lisp "[lf]" Pliant - multi-line
all strings allow multi-line strings Common Lisp, E, Emacs Lisp, OCaml, Pascal, Perl, Perl6, Ruby, Scheme, YCP @"..." C# '''...''', """...""" Python [[ ... ]] Lua {...} Rebol "...\n" "...\n"
C ... "...\n\ \...\n"
Haskell "...", "..."
Classic REXX - 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 Java, JavaScript ToString C# String JavaScript perl Perl6 Dumper Perl "" . e Perl "" ~ e Perl6 "" + e E, Java, JavaScript string Pliant str, `e`, repr Python out Eiffel cvs PostScript 'Image Ada asString printString Smalltalk as(<string>, e) Dylan (string) e Pike (coerce e 'string) Common Lisp prin1-to-string Emacs Lisp to string! / to-string / to "" Rebol description Objective-C - serialize (marshaling)
export-clixml MSH Marshal.to_string OCaml - unserialize (un-marshaling)
import-clixml MSH Marshal.from_string OCaml - sprintf-like
sprintf Awk, C, C++, merd, OCaml, Perl, Perl6, PHP, Pike, Ruby % Python, Ruby format (49) Common Lisp, Erlang, Scheme-SRFI28 Format C# putFormat Beta stringWithFormat Objective-C - simple print
on strings
puts C, Dylan print Awk, Basic, Java, merd, PHP, SML write JavaScript, Pascal, Pike putStr Haskell print_string 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 (50) OCaml println (50) Java, merd put_chars Erlang echo PHP echo (50) sh emit Forth putText Beta say Classic REXX on simple objects
print Perl, Perl6 say (50) Perl6 puts (50) Tcl on any objects
print Ruby print (50) Dylan, Haskell, Python, Rebol prin Rebol display write Scheme Put Ada p (50) Ruby puts (51) Ruby write Prolog write prin1 princ print Common Lisp princ prin1 Emacs Lisp WriteLine C# printf-like
printf Awk, C, C++, merd, OCaml, Perl, PHP, Ruby write Pike WriteLine C# putFormat Beta format (49) Common Lisp - string equality & inequality
eq ne Perl, Perl6, Tcl strcmp C == != JavaScript, Pike isEqualToString (52) Objective-C == != Awk, C#, C++, E, merd, Python, Ruby, YCP == /= Haskell == \= Oz = != sh, XPath = /= Ada = \= Classic REXX = <> Beta, OCaml, Pliant, SML = ~= Dylan, Smalltalk == \== or = <> \= Classic REXX equal? Ruby, Scheme equals Java equal, equalp Common Lisp is_equal Eiffel isEqual Objective-C - string size
length Awk, Beta, C++, Common Lisp, Eiffel, Haskell, Java, JavaScript, Objective-C, OCaml, Perl, PostScript, Ruby LENGTH Classic REXX 'Length Ada length? Rebol size C++, E, Ruby, Smalltalk, SML, YCP Length C#, Modula-3, Oz, Pascal len Pliant, Python, Visual Basic strlen C, PHP string-length Scheme, XPath sizeof Pike count Eiffel bytes chars Perl6 CHARACTER_LENGTH SQL92 - string concatenation
+ C#, C++, E, Eiffel, Java, JavaScript, merd, MSH, Pascal, Pike, Pliant, Python, Ruby, YCP . Perl, PHP , Smalltalk .. Lua ~ Perl6 & Ada, Modula-3, Visual Basic ^ OCaml, SML || Cecil, Classic REXX, Icon, PL/I, SQL92 ++ Haskell $a$b sh, Tcl concatenate Common Lisp, Dylan string-append Scheme Cat Modula-3 strcat C concat XPath append Beta, Rebol stringByAppendingString Objective-C Awk, Classic REXX - duplicate n times
* Ada, E, Pike, Python, Ruby x Perl, Perl6 times merd repeat Pliant str_repeat PHP string repeat Tcl strrep Lua insert/dup Rebol COPIES Classic REXX - upper / lower case character
upcase / downcase Emacs Lisp, Ruby uc / lc Perl, Perl6 upper / lower Pliant, Python toUpper / toLower Haskell to_upper / to_lower Eiffel To_Upper / To_Lower Ada toUpperCase / toLowerCase E, Java, JavaScript upper_case / lower_case Pike uppercase / lowercase OCaml strupper / strlower Lua upper / lower (53) Lua ToUpper / ToLower C#, Oz toupper / tolower Awk, C, C++ string toupper / string tolower Tcl asLowercase / asUppercase Smalltalk upCase / lowCase Beta uppercase form / lowercase form Rebol char-upcase / char-downcase Common Lisp, Scheme - uppercase / lowercase / capitalized string
upcase / downcase Emacs Lisp, Ruby upper / lower Python, SQL92 uppercase/lowercase OCaml, Rebol toUpperCase / toLowerCase E, Java, JavaScript ToUpper / ToLower C# to_upper / to_lower Ada, Eiffel toupper / tolower Awk, YCP uc / lc Perl, Perl6 UpperCase / LowerCase Pascal uppercaseString / lowercaseString / capitalizedString Objective-C UCase / LCase Visual Basic strtoupper / strtolower PHP strupper / strlower Lua string toupper / string tolower Tcl string-upcase / string-downcase Common Lisp, Scheme asLowercase / asUppercase Smalltalk makeLC / makeUC Beta parse upper var in_var out_var / parse lower var in_var out_var Classic REXX - ascii to character
chr Haskell, OCaml, Pascal, Perl, Perl6, PHP, Python, Ruby, SML format %c $c Tcl toChar E strchar Lua from_integer Eiffel fromCharCode JavaScript character Pliant Character value: c Smalltalk code-char Common Lisp integer->char Scheme 'Val Ada (char) c C, C#, C++, Java to char! / to-char Rebol X2C, D2C Classic REXX - character to ascii
ord Haskell, Pascal, Perl, Perl6, PHP, Python, SML getNumericValue Java charCodeAt JavaScript asciiValue Smalltalk code Eiffel, OCaml char-code Common Lisp char->integer Scheme s[0] Ruby s 0 get PostScript scan $s %c Tcl strbyte Lua toInteger E 'Pos Ada number Pliant (int) c C, C#, C++, Java to integer! / to-integer Rebol C2X, C2D Classic REXX - accessing n-th character
s[n] C, C#, C++, E, PHP, Pike, Python, Ruby s(n) Ada s:n Pliant s.[n] 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 at Smalltalk at (54) C++ aref Common Lisp char(s, i) B charAt Java, JavaScript characterAtIndex Objective-C n -> s.inxGet Beta string-ref Scheme - extract a substring
s[n..m] Pike, Ruby s(n..m) Ada s(n,m+1) E s[n:m+1] Python 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 OCaml SUB Modula-3 subseq Common Lisp slice JavaScript range Tcl 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 - locate a substring
index Perl, Perl6, Ruby indexOf Java, JavaScript IndexOf C# startOf E search Common Lisp, Pike, PostScript strstr / strchr / index C find Rebol, YCP find / index Python index / index_non_blank / find_token Ada substring_index Eiffel rangeOfString Objective-C POS Classic REXX POSITION(needle IN s) SQL92 - locate a substring (starting at the end)
rindex OCaml, Perl, Perl6, Ruby rfind C++ rfind / rindex Python find/last Rebol / strrchr / rindex C index(Going => Backward) Ada lastStartOf E lastIndexOf Java, JavaScript last_index_of (55) Eiffel LastIndexOf C# (search substring string :from-end t) Common Lisp [string rangeOfString:substring options:NSBackwardsSearch] Objective-C LASTPOS Classic REXX
Booleans
- type name
Bool Haskell, Perl6, Pliant bool C#, C++, C99, OCaml, Python, YAML Boolean Ada, Lua, Pascal, Smalltalk, Visual Basic boolean Common Lisp, Java, YCP BOOLEAN Eiffel logic! Rebol - false value
nil Common Lisp, Emacs Lisp, Lua undef / 0 / "0" / "" / () Perl, Perl6 False / None / 0 / "" / () / [] / {} Python false / 0 / "" PHP NULL / 0 / '\0' C NULL / 0 / '\0' / false C++, C99 0 / "0" / "" Awk 0 / NaN / "" / false() XPath 0 Classic REXX 0 (56) B, Pike 0 / False Visual Basic false / none Rebol false / null / undefined / 0 / NaN / "" JavaScript false / no / off / 0 Tcl false / no / off / n YAML false / nil Lua, Ruby false Ada, BCPL, Beta, C#, E, FL, Java, OCaml, Oz, Pascal, Pliant, PostScript, Smalltalk, SML, YCP False Eiffel, Haskell, merd FALSE Modula-3, SQL92 false / exit status different from 0 sh No / fail Prolog #f Dylan, Scheme - true value
anything not false Awk, B, C, Perl, Perl6, Pike true / anything not false C++, C99, JavaScript, Lua, PHP, Ruby true / anything not false Rebol True / anything not false Python true() / anything not false XPath #t / anything not false Dylan, Scheme t / anything not false Common Lisp, Emacs Lisp yes / on / true / non zero number Tcl yes / on / true / y YAML True Eiffel, Haskell, merd non-zero-numbers / True Visual Basic TRUE Modula-3, SQL92 true Ada, BCPL, Beta, C#, E, FL, Java, OCaml, Oz, Pascal, PHP, Pliant, PostScript, Smalltalk, SML, YCP true / exit status 0 sh Yes / true Prolog 1 Classic REXX - logical not
! Awk, B, C, C#, C++, E, Java, JavaScript, Perl, Perl6, PHP, Pike, Ruby, Tcl, YCP not Ada, Beta, Common Lisp, Eiffel, Emacs Lisp, Forth, Haskell, Lua, merd, OCaml, Pascal, Perl, Perl6, Pliant, PostScript, Prolog, Python, Rebol, Ruby, Scheme, Smalltalk, SML, XPath Not Oz, Visual Basic NOT Modula-3 ~ BCPL, Dylan, PL/I ^ PL/I \ Classic REXX - logical or / and
short circuit
|| / && Awk, C, C#, C++, E, Haskell, Java, JavaScript, merd, OCaml, Perl, Perl6, PHP, Pike, Ruby, Tcl, YCP | / & B, BCPL, Dylan or / and Common Lisp, Emacs Lisp, Lua, Modula-2, Perl, Perl6, PHP, Pliant, Python, Ruby, Scheme, Smalltalk or / & OCaml or / and & (57) Modula-2 OR / AND Modula-3 any / all Rebol orelse / andalso SML orelse / andthen Oz or else / and then Ada, Eiffel ; / , Prolog non short circuit (always evaluates both arguments)
| / & C#, Classic REXX, Java, Smalltalk or / and Ada, Beta, Eiffel, Forth, Pascal, PostScript, Rebol, SML, XPath Or / And Visual Basic Or / And (58) Oz \/ / /\ (10) BCPL ?| / Perl6
Bags and Lists
- type name
seq YAML a list OCaml [a] Haskell a[] C# List Pliant Array or List Perl6 - list concatenation
+ E, Eiffel, merd, Pike, Python, Ruby , Smalltalk , (59) Perl @ OCaml, SML ++ Haskell ||| Icon array_merge PHP merge YCP concat JavaScript, Tcl concatenate Dylan append nconc Common Lisp, Emacs Lisp append Beta, Rebol, Scheme Append Oz arrayByAddingObjectsFromArray Objective-C - list flattening
one level depth
concat Haskell, Mercury, SML flatten merd, OCaml, YCP Flatten Oz eval concat Tcl recursive
flatten Pike, Ruby - list constructor
[ a, b, c ] E, Haskell, JavaScript, merd, Perl, Perl6, PostScript, Prolog, Python, Ruby, SML, YAML, YCP ( a, b, c ) Perl, Perl6 { a, b, c } (60) C, C++, Lua #(a, b, c) Dylan #(a b c) (61) Smalltalk { a. b. c } Squeak [ a ; b ; c ] OCaml [ a b c ] Oz, Rebol ({ a, b, c }) Pike '(a b c) Common Lisp, Emacs Lisp, Scheme << a, b, c >> Eiffel list Common Lisp, Dylan, Emacs Lisp, Scheme, Tcl new t[] { a, b, c } C# new[] { a, b, c } C#3 new List<t> { a, b, c} C#3 Array(a, b, c) (62) JavaScript [NSArray arrayWithObjects:a, b, c, nil] Objective-C - a - b - c
YAML - list/array indexing
a[i] B, C, C#, C++, Dylan, E, Java, JavaScript, Lua, merd, Modula-3, MSH, Pascal, Perl, Perl6, PHP, Pike, Python, Ruby a*[i] or a!i or a*(i) depending on the version BCPL a[i]:default YCP a(i) Ada a:i Pliant a/:i Rebol a.(i) OCaml a !! i Haskell, Mercury a @ i Eiffel a i get (63) PostScript at (64) Smalltalk at (54) C++ lindex Tcl Nth Oz nth / aref Common Lisp, Emacs Lisp list-ref / vector-ref Scheme element Dylan slice Ruby node[i] XPath objectAtIndex Objective-C - adding an element at the beginning (list cons)
return the new list (no side-effect)
: Haskell, merd :: OCaml, SML | Oz [ e | l ] Erlang, Prolog cons Common Lisp, Emacs Lisp, Scheme pair Dylan side-effect
unshift JavaScript, Perl, Perl6, Ruby prepend YCP push_front C++ addFirst Smalltalk insert Rebol put_first Eiffel push Common Lisp array_unshift PHP - adding an element at index
return the new list (no side-effect)
side-effect
[a insertObject:e atIndex:i] Objective-C a.insert(i, e) Ruby - adding an element at the end
return the new list (no side-effect)
push merd arrayByAddingObject Objective-C side-effect
push JavaScript, Perl, Perl6, Ruby push_back C++ append Pliant, Python, Rebol += Pliant add Java, Smalltalk, YCP put_last Eiffel array_push PHP addObject Objective-C - first element
head Haskell hd OCaml car Common Lisp, Emacs Lisp, Scheme first Eiffel, Pliant, Rebol, Smalltalk iterator
head Beta begin C++ - all but the first element
tail Haskell tl OCaml cdr Common Lisp, Emacs Lisp, Scheme allButFirst Smalltalk - last element
last E, Eiffel, Haskell, Pliant, Rebol, Scheme, Smalltalk Last Oz lastObject Objective-C a[-1] Perl, Pike, Python, Ruby node[last()] XPath (car (last lst)) Common Lisp, Emacs Lisp iterator
- get the first element and remove it
shift JavaScript, Perl, Perl6, Ruby shift! merd pop Common Lisp removeFirst Smalltalk array_shift PHP - get the last element and remove it
pop E, JavaScript, Perl, Perl6, Python, Ruby pop! merd array_pop PHP removeLast Smalltalk - for each element do something
each merd, Pliant, Ruby for in E, JavaScript, Python, Ruby for Perl foreach 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 for_each C++ for-each Scheme forall PostScript ForAll Oz iter OCaml do Smalltalk do_all Eiffel app SML mapc Emacs Lisp mapM_ Haskell for (v in l) ... Awk, Dylan For Each v in l ... Next Visual Basic for v in range loop .. end loop Ada (dolist (v l) ...) (loop for v in l do ...) mapc Common Lisp list.iterate (# do current ... #) Beta - transform a list (or bag) in another one
map Dylan, Haskell, Mercury, merd, OCaml, Perl, Pike, Python, Ruby, Scheme, SML Map Oz mapcar Common Lisp, Emacs Lisp maplist YCP for-each XSLT foreach or selected MSH collect Ruby, Smalltalk transform C++ array_map PHP [ f x | x <- l ] (65) Haskell [ f(x) for x in l ] (65) Python - transform two lists in parallel
map2 OCaml zipWith Haskell Zip Oz map Dylan, Python, Scheme mapcar Common Lisp l1 with: l2 collect: ... Smalltalk transform C++ ListPair.map SML - find an element
find Haskell, merd, OCaml, Rebol, Ruby, Scheme-SRFI1, SML, YCP find find_if C++ find find-if Common Lisp first (15) Perl detect Ruby, Smalltalk search Pike lsearch Tcl indexOfObject, indexOfObjectIdenticalTo Objective-C - keep elements matching
find_all OCaml, Ruby filter Haskell, Mercury, merd, OCaml, Pike, Python, Scheme-SRFI1, SML, YCP filter! Scheme-SRFI1 Filter Oz grep Perl, Perl6 where MSH select Ruby, Smalltalk remove-if delete-if Common Lisp reject Ruby choose Dylan [ x | x <- l, p x ] (65) Haskell [ x for x in l if p(x) ] (65) Python - f(... f(f(init, e1), e2) ..., en)
foldl Haskell, Mercury, merd, SML FoldL Oz fold_left OCaml fold Scheme-SRFI1 reduce Common Lisp, Dylan, Perl6, Pike, Python reduce (15) Perl inject Ruby inject into Smalltalk - f(e1, f(e2, ... f(en, init) ...))
foldr Haskell, Mercury, merd, SML FoldR Oz fold-right Scheme-SRFI1 fold_right OCaml rreduce Pike (reduce f '(e1 e2 ... en) :from-right t :initial-value init) Common Lisp - split a list in 2 based on a predicate
partition Haskell, merd, OCaml, Ruby, Scheme-SRFI1, SML partition! Scheme-SRFI1 Partition Oz split-sequence (66) Common Lisp - is an element in the list
member? Dylan, merd, Ruby include? Ruby mem OCaml member Common Lisp member memq memv Scheme Member Oz contains E, YCP containsObject Objective-C in JavaScript, Python, SQL92 in_array PHP includes Smalltalk elem Haskell, Mercury has Eiffel has_value Pike - is the predicate true for an element
any Haskell, Mercury, Python, Scheme-SRFI1 any? Dylan, Ruby anySatisfy Smalltalk exists OCaml, SML exists? merd some Common Lisp Some Oz - is the predicate true for every element
all Haskell, Mercury, Python, SML All Oz all? merd, Ruby allSatisfy Smalltalk every Common Lisp, Scheme-SRFI1 every? Dylan for_all OCaml - smallest / biggest element
min / max Common Lisp, Eiffel, Java, Perl6, Pike, Python, Ruby, Scheme, Smalltalk minimum / maximum Haskell, Mercury, merd minimum-of / maximum-of Rebol min minstr / max maxstr (15) Perl min_element / max_element C++ - join a list of strings in a string using a glue string
join JavaScript, Perl, Perl6, PHP, Python, Rebol, Ruby Join C# rjoin E concat OCaml l * glue Pike, Ruby (macpconcat 'identity l glue) Emacs Lisp componentsJoinedByString Objective-C - list size
size C++, Dylan, E, Java, merd, Pliant, Ruby, Smalltalk, YCP sizeof Pike length C#, Common Lisp, Emacs Lisp, Haskell, Java, JavaScript, Mercury, OCaml, PostScript, Prolog, Ruby, Scheme, SML Length Oz length? Rebol len Python llength Tcl elems Perl6 getn Lua count Eiffel, Objective-C, PHP, SQL92, XPath scalar @l Perl - iterate with index
each_with_index merd, Ruby foreach($l as $i => $v) PHP 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 (loop for v in l as i upfrom 0 do ...) Common Lisp - remove duplicates
uniq merd, Perl6, Ruby uniq or uniq2 Pike unique Rebol unique (67) C++ nub Haskell array_unique PHP delete-duplicates delete-duplicates! Scheme-SRFI1 remove-duplicates Dylan remove-duplicates delete-duplicates Common Lisp lsort -unique Tcl toset YCP distinct SQL92 - sort
sort C#, C++, Common Lisp, E, Eiffel, Haskell, Java, JavaScript, Lua, merd, OCaml, Perl, Perl6, PHP, Pike, Python, Rebol, Ruby, XSLT, YCP sort (68) Scheme sorted Python Sort Oz sort_by merd, Ruby sortBy Haskell, Smalltalk order by SQL92 lsort Tcl asort Awk sort-object MSH sortedArrayUsingSelector, sortUsingSelector Objective-C - reverse
reverse C++, Common Lisp, Dylan, Emacs Lisp, Haskell, Java, JavaScript, Mercury, merd, Perl, Perl6, Pike, Python, Rebol, Ruby, Scheme Reverse C#, Oz reversed Smalltalk reverse_copy C++ rev OCaml, SML array_reverse PHP - list of couples from 2 lists
combine OCaml zip Haskell, merd, Perl6, Python, Ruby, Scheme-SRFI1, SML pairlis (69) Common Lisp transpose Ruby - 2 lists from a list of couples
split OCaml unzip Haskell, merd, SML unzip2 Scheme-SRFI1 transpose Ruby zip(*l) Python - lookup an element in a association list
lookup Haskell assoc Common Lisp, OCaml, Ruby assoc assq Emacs Lisp assoc assq assv Scheme select Rebol - list out of a bag
to_a Ruby toArray Java asArray Smalltalk to_list merd map-as(<list>, bag) Dylan
Various Data Types
- tuple type
t1 * ... * tn OCaml (t1, ..., tn) Haskell t1, ..., tn merd tuple! Rebol Tuple[T1, T2, T3] E - tuple constructor
a, b, c Lua, merd, OCaml, Python, Ruby ( a, b, c ) Ada, Haskell, Perl, Prolog, SML { a. b. c } Smalltalk [ 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 {} or #() 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 - reference (pointer)
creation
& B, C, C#, C++ \ Perl AddressOf Visual Basic addr (70) Pascal @ (70) Pascal lv BCPL ref C#, OCaml, SML newSTRef Haskell NewCell Oz 'access Ada :> :>> Pliant dereference
* (71) B, C, C#, C++ $ @ % & (71) Perl ->[...] ->{...} ->(...) (72) Perl -> (73) C, C++ ^ (72) Modula-3, Pascal ! (71) OCaml, SML rv BCPL readSTRef Haskell Access Oz .[all] Ada @ Forth assigning (when dereferencing doesn't give a lvalue)
writeSTRef Haskell Assign Oz := OCaml, SML ! Forth - optional value
null value
0 C++ NULL C, SQL92 nil Common Lisp, Emacs Lisp, Lua, Objective-C, Ruby null C#, Java, JavaScript, Smalltalk Null (74) Ada undef Perl None OCaml, Python Nothing Haskell #f () Emacs Lisp (empty) / ~ / null YAML value
v Ada, C, C#, C++, Common Lisp, Emacs Lisp, Java, JavaScript, Lua, Perl, Perl, Python, Ruby, Scheme, Smalltalk Just v Haskell Some v OCaml type name
option OCaml Maybe Haskell - record selector
. Ada, Beta, C, C#, C++, E, Eiffel, Java, JavaScript, Lua, Modula-2, Modula-3, OCaml, Oz, Pascal, Python, Ruby :: XPath % Fortran90 ' (75) Ada ^ Mercury r { field } merd r:field Pliant field r Haskell -> C, C++ r["field"] JavaScript #field r SML normal function call Common Lisp, Dylan, Haskell, Smalltalk - dictionary
type name
map YAML (k, v) Hashtbl.t OCaml Dictionary Pliant Hash Perl6 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 } JavaScript, Python, YAML $[ 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 >> PostScript Hash[ a, b, c, d ] Ruby define table foo a => b; c => d end Dylan [NSDictionary dictionaryWithObjectsAndKeys:b, a, d, c, nil] Objective-C a: b c: d
YAML access: read/write
h[k] Awk, C#, C++, Dylan, E, JavaScript, Lua, MSH, PHP, Python, Ruby $h{k} Perl %h{k} or %h<s> Perl6 $h(k) Tcl h.k JavaScript, Lua h:k Pliant h["k"] or h->k Pike (gethash k h) Common Lisp access: read
h k get PostScript find OCaml fetch Ruby get Java at Smalltalk h@k or h.at(k) Eiffel h[k]:default YCP h.get(k, returned_value_when_k_unfound) Python objectForKey Objective-C access: write
h k o put PostScript put Eiffel, Java add, replace OCaml store Ruby h[k] YCP h at: k put: o Smalltalk [h setObject:o forKey:k] Objective-C has the key ?
exists $h{k} Perl exists Perl6, Pliant has Eiffel haskey YCP has_key Python has_key?, include?, key?, member? Ruby Contains C# containsKey Java includesKey Smalltalk k in h Python k not in h Python in Awk mem OCaml find (76) C++ h[k] Pike (gethash k h) Common Lisp maps E known PostScript remove by key
delete $h{k} Perl del h[k] Python remove Eiffel, Java, OCaml, YCP Remove C# removeKey E, Smalltalk remhash Common Lisp delete JavaScript, Perl6, Ruby erase C++ m_delete Pike removeObjectForKey Objective-C undef PostScript list of keys
keys MSH, Perl, Perl6, Python, Ruby, Smalltalk keySet Java allKeys Objective-C AllKeys C# indices Pike current_keys Eiffel getKeys E array_keys PHP list of values
values Java, Perl, Perl6, Pike, Python, Ruby, Smalltalk getValues E content Eiffel array_values PHP - range
inclusive .. inclusive
a .. b Ada, E, merd, MSH, Pascal, Perl, Ruby [ a .. b ] Haskell to Smalltalk seq sh range PHP range(from: a, to: b, by: step) Dylan List.number A B Step Oz inclusive .. exclusive
a ... b Ruby a ..! b E range Python
Mathematics
- type name
integers
short, int, long C, C# int YAML Int Perl6 Int, uInt, Int8, Int16... Pliant INTEGER, INT, SMALLINT SQL92 decimal
float, double C, C# float YAML Float, Float32, Float64 Pliant NUMERIC, DECIMAL, DOUBLE PRECISION SQL92 Rat Perl6 - numbers syntax
integers
1000 Ada, Awk, B, C, C#, C++, E, Eiffel, Haskell, Java, JavaScript, merd, OCaml, Oz, Pascal, Perl, Perl6, Pike, Pliant, Python, Rebol, Ruby, Scheme, sh, Smalltalk, SQL92, Tcl 1000, 1000. Common Lisp, Emacs Lisp 1000, 1000., 1000.0 Awk 1000, '1000'D Classic REXX integers in base 2, octal and hexadecimal
0b1, 07, 0xf Oz, Perl, Pike, Ruby 0b1, 0o7, 0xf OCaml, Perl6 07, 0xf Awk, C, C++, JavaScript, Python, Tcl 0xf C#, E 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 #2r1, #8r7, #16rf Common Lisp, Emacs Lisp 1b, Fh Pliant '1'B, 'F'X Classic REXX B'1', X'F' SQL92 integer thousand-seperator
1_000, 10_00, 100_0 E, Eiffel, OCaml, Perl, Perl6, Ruby 1'000, 10'00, 100'0 Rebol 1_000 Ada, merd decimals
1000., 1E3 Ada, C, C++, Classic REXX, E, Java, JavaScript, OCaml, Python, Scheme, SQL92, Tcl 1000., 1E3, 1,0 Rebol 1000., 1.E3 Oz 1000.0, 1E3 C#, Common Lisp, Emacs Lisp, Pike, Ruby, Smalltalk 1000.0, 1.0E3 Haskell 1000, 1000.0, 1E3 (77) Awk, merd, Perl, Perl6 - addition / subtraction / multiplication / division
+ / - / * / / C, C#, C++, Classic REXX, Common Lisp, Emacs Lisp, Haskell, Java, merd, Perl, Perl6, Pliant, Python, Ruby, Scheme, sh, Smalltalk, SQL92, Tcl + +. / - -. / * *. / / /. (78) OCaml add / sub / mul / idiv div PostScript - exponentiation (power)
** Ada, Classic REXX, E, Fortran, merd, OCaml, Perl, Perl6, PL/I, Prolog, Python, Rebol, Ruby ^ Awk, Dylan, Eiffel, Lua, Pliant * (79) APL **, ^ and ^^ (80) Haskell pow C, C++, Java, JavaScript, PHP, Pike, Python, SML, Tcl Pow C#, Oz power Delphi-Kylix, Rebol exp PostScript expt Common Lisp, Emacs Lisp, Scheme raisedTo Smalltalk - negation
- Ada, Awk, B, BCPL, C, C#, C++, Classic REXX, Common Lisp, E, Eiffel, Emacs Lisp, Haskell, Java, JavaScript, merd, Perl, Perl6, Pike, Pliant, Prolog, Python, Rebol, Ruby, Scheme, sh, Smalltalk, Tcl - -. OCaml ~ Oz neg PostScript negate Rebol - random
random number
rand Perl, Perl6 seed the pseudo random generator
srand Perl, Perl6 - operator priorities and associativities
addition vs multiplication
mathematical C, C#, C++, Classic REXX, Haskell, Java, merd, Perl, Perl6, Python, Ruby, sh, Tcl same priorities Smalltalk exponentiation vs negation (is -3^2 equal to 9 or -9)
mathematical Classic REXX, Haskell, Perl, Perl6, Python, Ruby negation first OCaml - square root / e-exponential / absolute value
sqrt / exp / abs Ada, C, C++, Common Lisp, E, Eiffel, Emacs Lisp, Haskell, Java, JavaScript, Lua, OCaml, Pascal, Perl, Perl6, PHP, Python, Ruby, Scheme, Smalltalk, SML, Tcl sqrt / exp / Awk Sqrt / Exp / Abs C#, 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 - trigonometry
basic
sin / cos / tan Ada, C, C++, Common Lisp, E, Emacs Lisp, Haskell, Java, JavaScript, Lua, OCaml, Pascal, Perl, Perl6, PHP, Pike, Pliant, Python, Ruby, Scheme, Smalltalk, SML, Tcl Sin / Cos / Tan C#, Classic REXX, Oz sin / cos / Awk, PostScript sine / cosine / tangent Eiffel, Rebol inverse
asin / acos / atan (81) Ada, C, C++, Common Lisp, JavaScript, OCaml, Perl, Perl6, Pike, Pliant, Python, Ruby, Scheme Asin / Acos / Atan C#, Oz ASin / ACos / ATan Classic REXX arcSin / arcCos / arcTan Smalltalk arcsine / arccosine / arctangent Rebol arc_sine / arc_cosine / arc_tangent Eiffel / / atan PostScript - logarithm
log / log10 C, C++, Eiffel, Lua, OCaml, Perl, Perl6, PHP, Pliant, Python, Ruby, Tcl log / Awk, E, Emacs Lisp, Java, JavaScript, Pike, Scheme log / logBase 10 Haskell Log / Log10 C#, Classic REXX Log / Oz Log / Log(X => val, Base => 10.0) Ada log / (82) Common Lisp ln / Pascal ln / log10 Delphi-Kylix ln / log PostScript, SML ln / log: 10 Smalltalk log-e / log-10 / log-2 Rebol - euclidian division (both quotient and modulo)
divmod Python, Ruby divMod Haskell div ldiv lldiv C IntInf.quotrem SML floor Common Lisp, Dylan - modulo
modulo of -3 / 2 is 1
% Classic REXX, Perl, Perl6, Pike, Python, Ruby, Tcl %% E \\ Smalltalk mod Ada, Common Lisp, Emacs Lisp, Haskell, Prolog, SML MOD Modula-3 modulo Dylan, Ruby modulo of -3 / 2 is -1
% Awk, B, C, C#, C++, E, Java, JavaScript, PHP, Pliant mod Lua, OCaml, Oz, Pascal, PostScript, XPath remainder Ruby, Scheme rem Ada, BCPL, Smalltalk // Classic REXX, Rebol - truncate / round / floor / ceil
trunc / round / floor / ceil C, C++ truncate / round / floor / ceiling Common Lisp, Perl6, PostScript, Scheme int / round / floor / ceil JavaScript, Pike, Python to_i, Integer() / round / floor / ceil Ruby TRUNC / FORMAT / Floor / Ceil Classic REXX / round / floor / ceil E, Java, Lua, PHP, SML, Tcl / Round / Floor / Ceiling C# / Round / Floor / Ceil Oz / round / floor / ceiling Dylan, Emacs Lisp, Haskell, PostScript, XPath / ROUND / FLOOR / CEILING Modula-3 / rounded / floor / ceiling Eiffel, Smalltalk int / / floor / ceil Perl int_of_float / / floor / ceil OCaml / / floor / ceil Lua / Rounding / Floor / Ceiling Ada to-integer / / / Rebol - bitwise operators
and / or / xor
& / | / ^ C, C#, C++, E, Eiffel, Java, JavaScript, Perl, Pike, Python, Ruby & / | YCP +& / +| / +^ Perl6 and / or / xor PostScript, Rebol land / lor / lxor OCaml logand / logior / logxor (83) Common Lisp BITAND / BITOR / BITXOR Classic REXX negation
~ C, C#, C++, Java, JavaScript, Perl, Pike, Python, Ruby, YCP not Eiffel, PostScript lnot OCaml lognot (84) Common Lisp bitnot Eiffel complement Rebol left shift / right shift / unsigned right shift
<< / >> / >>> Java, JavaScript << / >> C, C#, C++, Perl, Pike, Python, Ruby, YCP |<< / |>> Eiffel lsl / lsr or asr OCaml bitshift PostScript (ash x positive-integer) / (ash x negative-integer) / Common Lisp
Threads
- thread definition
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 ... fork Smalltalk 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 - thread object creation
MyTask : task_type_name; Ada class_name MyThread = new class_name() Java - starting / stopping threads
start() / stop() (85) Java resume / suspend / terminate Smalltalk Tasks are started when created / call Stop entry or "abort task-object-name" Ada - passing data directly between threads
call an entry with paramters Ada call any public method Java common variables are copied at thread creation, in abscence of a "share" statement Pliant - 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
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 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 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 - 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) for C, it is not a standard convention, but it is the more widespread
- (2) any string literal would work
- (3) see also =head1, =head2, =over, etc
- (4) need "file: %script-header.r" in file header
- (5) displayed <- with a special character
- (6) variable on the right
- (7) the variable behaves like a pointer
- (8) cf horizontal layout
- (9) introduce scope
- (10) ascii representation, original uses a special charset
- (11) <> and # are synonyms
- (12) === and !== differ from == and != when the objects' type differ
- (13) for objects
- (14) deep comparison
- (15) in List::Util
- (16) the function is "f: g:"
- (17) special sugar for only one parameter
- (18) there really is a parameter which is the empty tuple
- (19) f is a block
- (20) when callee has special "&" prototype
- (21) this is a block, not precisely a function, but it's alike
- (22) also works for procedures: proc {$ A B} ... end
- (23) method is optional
- (24) in Lua, "return xxx" can only appear before a block end
- (25) "return" is used when there is no value to return
- (26) the result goes to "e"
- (27) "break"s are mandatory, even for "default"!
- (28) Perl >= 5.8.0
- (29) cond
- (30) see also catch/throw
- (31) often provided in the abbreviated form call/cc
- (32) expression "e" is cast to the type of "v"
- (33) quite bad: only the reference is non-mutable whereas the object is still mutable
- (34) eventual send
- (35) properties are something alike attributes, but really are methods
- (36) one level depth
- (37) general deep copy function
- (38) object cloning is the default, uses the copy constructor in C++
- (39) assignment attempt
- (40) does not work on builtin types
- (41) see also callable(obj.meth) for unbound methods
- (42) usually called self
- (43) ":" is for external symbols only, recommended
- (44) if names are exported using @EXPORT
- (45) if names are not exported or are exported using @EXPORT_OK
- (46) deprecated in ANSI Common Lisp, but used in ASDF
- (47) using a correspondance from the package name to the file name
- (48) when using format
- (49) but not using the C-like %-syntax
- (50) adding an end-of-line
- (51) adding an end-of-line unless already newline-terminated
- (52) faster than isEqual
- (53) Lua 5.0
- (54) is range-checked whereas a[i] is not
- (55) ESI dialect
- (56) beware of 0.0 which is true in Pike!
- (57) &, and synonyms
- (58) simple functions, not operators
- (59) flattened
- (60) restricted to initialisation of a local variable in C and C++
- (61) a b c must be constants
- (62) beware, if you give only one integer argument, it is the size!
- (63) for write access: a i o put
- (64) for write access: a :at i :put o
- (65) list comprehension
- (66) not in standard
- (67) in place
- (68) not standard, but nearly standard
- (69) the result is not guaranteed to be the same as the order in the input
- (70) Borland Pascal extension
- (71) prefix
- (72) postfix
- (73) infix
- (74) only for "access" types
- (75) attribute selector
- (76) returns an iterator
- (77) integers are decimals
- (78) with mathematical priorities
- (79) APL uses a real multiplication sign for multiplication from a special character set
- (80) for each various types
- (81) Ruby >= 1.7
- (82) log x 10
- (83) see also bit-and / bit-or / bit-xor
- (84) see also bit-not
- (85) "stop" is now deprecated
Similar Pages
- Comments and Literals in programming languages
- The Surface of Programming Languages
- Delphi, VisualBasic, C++, Java
- SML, OCaml
- Java, Smalltalk
- Java, C++, Smalltalk
- Java, C#
- Java, C#
- Java, C#
- Ruby, Java, Perl
- Python, Perl
- Python, Lisp
- PL/I, C
- Perl, PHP
- EmacsLisp, Perl
References
Credits
- Yoann 'Pad' Padioleau (Haskell additions, Beta, various fixes)
- Jakub Travnik (Pascal, Delphi-Kylix)
- Robert Feldt (Ruby additions)
- Pascal Terjan (PHP)
- Carlos 'angus' (PostScript)
- Axel Kittenberger (various)
- Guido van Rossum (block vs scoping)
- Jeffrey Hobbs (Tcl)
- Mark-Jason Dominus (SML, various)
- Ash Searle (Java, PHP, JavaScript)
- Mark S. Miller (E)
- Pete Jinks (various)
- Steve Tolkin (various)
- Franck Arnaud (Eiffel)
- Tom Murphy (SML)
- Guy Steele (Fortran, and many various)
- Carl Gay (Dylan, CommonLisp)
- Jay nop@nop.com (Lua)
- Philippe Lhoste (Lua, JavaScript)
- Jim Rogers (Ada, Java, Threads section)
- Ketil Z. Malde (Haskell)
- Mark Carroll (Modula-3)
- Keith Wansbrough (Haskell and a few SML)
- Remi Vanicat (OCaml)
- Matthieu Villeneuve (CommonLisp)
- Joachim Durchholz (Eiffel)
- Walter Vannini (C, "breaking lines" idea)
- Peter Lewerin (Tcl)
- Patrice Ossona de Mendez (Pliant)
- Bert Freudenberg (Smalltalk & Squeak additions corrections)
- Dennis Haney (Perl, C#)
- Fergus Henderson (Mercury)
- Ralph Becket (Mercury)
- Bill Thornton (Java)
- Nik Crabtree (C#)
- Neal Holtz (Python)
- Donald Chai (Python)
- Fred Spiessens (Oz)
- Martin Nilsson (Pike)
- Theodore Eastman (VisualBasic)
- George Herson (Eiffel)
- Lee Denison (Tcl)
- Anton Rolls (Rebol)
- Pedro (Lua)
- Nathan Sharfi (C99, C#, C++)
- Dirk Gerrits (Common Lisp, Scheme, Emacs Lisp)
- Tabitha Arrowny (Ruby, Python, Perl, ...)
- Péter Varga (sh, Common Lisp)
- Ian Henderson (Objective C)
- Anthony Borla (Classic REXX)
- Paul McJones (Modula-3 fixes)
- Uwe Kolb (Smalltalk fixes)
- Ciaran McNulty (PHP)
This document is licensed under GFDL (GNU Free Documentation License).