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

    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
    remBasic
    'Visual Basic
    \Forth
    !Assembler, Fortran90
    C or * in column 1Fortran

    nestable

    (* ... *)Beta, Modula-3, OCaml, Pascal, SML
    /* ... */Classic REXX, Dylan, Oz, SQL99
    { ... }Pascal
    {- ... -}Haskell
    #| ... |#Common Lisp
    #if 0 ... #endifC
    comment { ... }Rebol
    comment [ ... ]Rebol
    { ... } or [ ... ] when unusedRebol
    --[[ ... ]]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 $?FILEPerl6
    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 . SOURCENAMEClassic REXX

  • tokens

    case-sensitivity (keywords, variable identifiers...)

    case-sensitiveAwk, B, C, C#, C++, Haskell, Java, JavaScript, Lua, merd, Modula-3, OCaml, Perl, Perl6, Pike, Pliant, Python, Ruby, sh, Smalltalk, Tcl, XML, YAML
    case-insensitiveAda, 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: keywords
    E

    if case sensitive, what is the standard way for scrunching together multiple words

    CamelCaseC#, E, Haskell, Java, JavaScript, Pascal, Smalltalk, Tcl
    underscoresmerd
    hyphensCommon Lisp, Rebol
    underscores for functions, unclear for modules / types / constructorsOCaml
    UPPER_CASEsh
    underscores, UPPER_CASE for class namesEiffel
    CamelCase for classes, underscores for methodsPython
    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 variablesPike
    CamelCase for modules, ALL_CAPS for constants, unclear for functions / variablesPerl, Perl6
    usually lowercase or underscores, ALL_CAPS for macrosC
    usually underscoresC++
    Camel_CaseAda

    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 neededAda, 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
    defPostScript
    setqEmacs Lisp
    setf setq setCommon Lisp
    setRebol
    set!Scheme
    isProlog

    declaration

    =Haskell, Mercury, Prolog, SML
    <-Haskell
    :-Prolog
    let v = e inOCaml
    let v = eBCPL
    def v := e / var v := eE
    my / our / local / use varsPerl
    my / our / tempPerl6
    defineDylan
    define let let* letrecScheme
    let let* flet labels defun defmethod defvar defparameter defsetf ..Common Lisp
    local V1 = e V2 = e2 in ... endOz
    globalPython
    :@Beta
    :Ada, Eiffel, Pascal
    | v1 v2 |Smalltalk
    auto v1, v2; extrn v3, v4;B
    varJavaScript
    var gvarPliant
    variable v (7)Forth
    <xsl:variable name="v" select="e"/>XSLT

    both

    =merd, Python, Ruby
    :=merd
    set, variableTcl

  • 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
    indentationmerd
    $ ...Haskell
    begin ... endOCaml, Ruby
    BEGIN ... ENDModula-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 ... endClassic REXX
    do ... end (9)Lua, PL/I
    indentationPliant, 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)

    valofBCPL
    doPerl, 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 neEmacs Lisp, PostScript
    eq, eqlCommon Lisp
    eq? eqv?Scheme
    .EQ. .NE.Fortran
    is / is notPython

    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
    equalsJava
    equalEmacs Lisp
    equal, !equalPike
    equal, equalpCommon Lisp
    deep_is_equalEiffel
    isEqualObjective-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 gePerl, Perl6, PostScript
    -lt -gt -le -geMSH, sh
    .LT. .GT. .LE. .GE.Fortran

    returns 3 values (i.e. inferior, equal or superior)

    a <=> bmerd, Perl, Perl6, Ruby
    cmpPerl, Perl6, Python
    compareHaskell, Mercury, OCaml, Pliant, Smalltalk
    strcmpPHP
    three_way_comparisonEiffel
    string compareTcl
    compareToJava

    returns 4 values (i.e. inferior, equal, superior or not comparable)

    comparePliant
    compareToE

    min / max (binary or more)

    min / maxAda, 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 / MaxOz
    MIN / MAXClassic REXX, Modula-3
    measure-object -min / measure-object -maxMSH

  • runtime evaluation

    evalCommon Lisp, Emacs Lisp, JavaScript, Perl, Perl6, PHP, Python, Ruby, Scheme, Tcl, YCP
    dostringLua
    Compiler evaluate:Smalltalk
    runtime_compile / compile + executePliant
    Compiler.evalExpression or Compiler.parseOzVirtualStringOz
    compile_stringPike
    interpretClassic REXX
    do / reduce / compose / loadRebol
    [...]Tcl
    `...`sh

  • force garbage collection

    doGCBeta
    GC.startRuby
    gc()Pike
    System.gc()Java
    System.gcDoOz
    System.GC.Collect()C#
    gc.collect()Python
    full_collectEiffel
    garbage_collectMercury
    collectgarbageLua
    VM.garbageCollect()JavaScript
    Gc.full_major()OCaml
    Smalltalk garbageCollectSmalltalk
    incremental garbage collection => not neededPerl, Perl6
    recycleRebol
    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 versionBCPL
    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 ... fForth, PostScript
    a fSmalltalk
    a f: b g: ... (16)Smalltalk
    (a,b,...)->&f or (a,b,...)->fBeta
    f:aFL
    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

    fAda, 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.callRuby
    &$f or $f->()Perl
    $f.()Perl6
    v = f() or call fClassic REXX
    f value (19)Smalltalk
    <xsl:call-template name="f">/XSLT
    call fFortran

  • partial application (in the examples below, a normal call is "f(a,b)")

    give the first argument

    f aHaskell, 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
    (>) aOCaml

    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, ...) ... endRuby
    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 { ... } defPostScript
    typ0 f(typ1 para1, typ2 para2, ...) { ... }C, C#, C++, Pike, YCP
    function f(para1, para2) { ... }Awk, JavaScript
    function f(para1, para2) ... code ... endLua
    function f { param(para1, [typ2]para2, ...) ... }MSH
    (define (f para1 para2) ...)Scheme
    (defun f (para1 para2) ...)Common Lisp, Emacs Lisp
    fun { F Para1 Para2 } ... endOz
    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 FunctionVisual 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 } ... endOz
    Sub f(para1, para2) ... End SubVisual 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 stackPostScript
    { 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) ... endLua
    fun(a, b) -> ... endErlang
    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

    returnAda, 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
    ReturnVisual Basic
    RETURNModula-3
    resultis / return (25)BCPL
    return from xxx / returnCommon Lisp
    ^Smalltalk

    function body is the result

    no syntax neededCommon Lisp, Dylan, Emacs Lisp, Haskell, OCaml, Oz, Perl, Perl6, Rebol, Ruby, Scheme, SML

    setting the result

    Result := valEiffel
    <function name> := valPascal

  • function called when a function is not defined (in dynamic languages)

    AUTOLOADPerl
    AUTOSCALAR, AUTOMETH, AUTOLOAD...Perl6
    __getattr__Python
    method_missingRuby
    doesNotUnderstandSmalltalk
    unknownTcl
    no-applicable-methodCommon Lisp
    doesNotRecognizeSelectorObjective-C
    match [name, args] { ... }E
    the predicate failProlog

  • runtime inspecting the caller information

    callerPerl, Perl6, Ruby
    inspect.stack()[1]Python
    backtracePike
    trace 'I'Classic REXX

  • function composition

    .Haskell
    ~merd
    oSML
    composeDylan

  • identity function

    idHaskell
    identityCommon Lisp
    yourselfSmalltalk


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
    spaceEiffel, Rebol
    end-of-lineAssembler, 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 bmerd, OCaml, Pascal
    if c then b endEiffel, Lua, Oz, Ruby
    if c then b end ifAda
    if c; then b; fish
    if (c) then b endDylan
    if c do bBCPL
    IF c THEN b ENDModula-2, Modula-3
    if (c) bAwk, B, C, C#, C++, Java, JavaScript, PHP, Pike, YCP
    if c: bPython
    if c bPliant, Rebol, Tcl
    if (c): b endifPHP
    if c {b}Perl6
    if (c) {b}E, Perl
    c -> bFL
    c b ifPostScript
    b if cPerl, Ruby
    c if b1 thenForth
    (if c b)Common Lisp, Scheme
    (when c b)Emacs Lisp
    c ifTrue: bSmalltalk
    <xsl:if test="c">b</xsl:if>XSLT
    If c Then bVisual Basic
    If c
      b
    End If
    Visual Basic
    if c; b endRuby
    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 b2Haskell, merd, OCaml, SML
    if c then b1 else b2 endEiffel, Lua, Ruby
    if c then b1 elsif c2 then b2 else b3 end ifAda
    if c then b1 elseif c2 then b2 else b3 endEiffel, Oz
    if (c) then b1 elseif (c2) then b2 else b3 endDylan
    IF c THEN b1 ELSIF c2 THEN b2 ELSE b3 ENDModula-3
    If c Then b1 ElseIf c2 Then b2 Else b3 End IfModula-2
    if (c) b1 else b2Awk, B, C, C#, C++, Java, JavaScript, Pike, YCP
    if c ?then? b1 elsif c2 ?then? b2 ?else? b3Tcl
    if c then begin b1 end else begin b2 endPascal
    if c b1 eif c2 b2 else b3Pliant
    if c; then b1; elif c2; then b2; else b3; fish
    if (c) b1 elseif (c2) b2 else b3PHP
    if (c): b1 elseif (c2): b2 else: b3 endifPHP
    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 ; c2FL
    c ifTrue: b1 ifFalse: b2Smalltalk
    shunt c b1 c2 b2 b3Pliant
    either c b1 b2 / if/else c b1 b2Rebol
    (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 endRuby
    test c then b1 or b2BCPL
    e | c = b1 | c2 = b2 | otherwise = b3 (26)Haskell
    c b1 b2 ifelsePostScript
    c if b1 else b2 thenForth
    c ? b1 : b2Awk, B, C, C#, C++, Java, JavaScript, Perl, PHP, Ruby, YCP
    c ?? b1 :: b2Perl6
    c -> b1, b2BCPL
    (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 b2Visual 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)

    unlessEmacs 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_elseSqueak
    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

    loopmerd, PostScript, Ruby
    loop expr end loopAda
    LOOP expr ENDModula-3
    (loop do expr)Common Lisp
    cycle (# do ... #)Beta
    repeatSqueak
    foreverRebol
    Do
        expr
    Loop
    Visual Basic
    do forever
      ...
    end
    Classic REXX

    while condition do something

    while (cond) exprAwk, B, C, C#, C++, E, Java, JavaScript, Perl, Perl6, PHP, Pike, Python, Ruby, YCP
    while cond exprTcl
    while cond loop expr end loopAda
    while cond do exprBCPL, Pascal, SML
    while cond do expr doneOCaml
    WHILE cond DO expr endLua
    while cond; do expr; donesh
    while [cond][expr]Rebol
    cond whileTrue: exprSmalltalk
    (loop while cond do expr)Common Lisp
    loop (# while ::< (# do cond -> value #) do expr #)Beta
    begin cond while expr repeatForth
    from until not cond loop expr endEiffel
    while cond
        expr
    Pliant
    Do While cond 
        expr
    Loop
    Visual Basic
    do while cond
      ...
    end
    Classic REXX

    do something until condition

    do expr until condPerl6
    do {expr} until condPerl
    do {expr} while (!cond)Awk, C, C#, C++, Java, JavaScript, Pike
    begin expr end until condRuby
    REPEAT expr UNTIL condModula-3
    loop (# until ::< (# do cond -> value #) do expr #)Beta
    loop expr exit when cond end loopAda
    (loop do expr until cond)Common Lisp
    expr repeatuntil condBCPL
    repeat expr until condLua, Pascal
    repeat expr until (29)YCP
    until [expr cond]Rebol
    [expr . cond] whileFalseSqueak
    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++) exprC, 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 exprPascal
    for i = 1 to 10 do expr doneOCaml
    For i = 1 To 10 expr NextVisual Basic
    for i in 1 .. 10 loop ... end loopAda
    for i in range(1, 11)Python
    for i in `seq 1 10`; do expr; donesh
    1 1 10 expr forPostScript
    (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 exprPascal
    for i = 10 downto 1 do expr doneOCaml
    for i in reverse 1 .. 10 loop ... end loopAda
    for (int i = 10; i >= 1; i--) exprC, 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; donesh
    10 -1 1 expr forPostScript
    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) exprC, 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; donesh
    1 2 10 expr forPostScript
    (1..10).step(2) {|i| expr }Ruby
    do i = 1 to 10 by 2
      ...
    end
    Classic REXX

    for "a la C" (while + initialisation)

    forAwk, C, C#, C++, Java, JavaScript, MSH, Perl, PHP, Pike, Tcl
    loopPerl6
    for ((x = 0; x < 10; x++)); do ...; donesh
    from init_code until cond loop ... incr_statement endEiffel

  • breaking control flow

    returning a value

    returnAda, 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
    ReturnVisual Basic
    RETURNModula-3
    resultis / return (25)BCPL
    return from xxx / returnCommon Lisp
    ^Smalltalk

    goto (unconditional jump)

    gotoAda, B, Basic, BCPL, C, C#, C++, Cobol, Fortran, Pascal, Perl
    go throwCommon Lisp
    signalClassic REXX

    continue / break

    continue / breakAwk, C, C#, C++, E, Java, JavaScript, PHP, Pike, Python, YCP
    next / lastPerl, Perl6
    next / break (30)Ruby
    / breakBCPL, Lua
    / break/returnRebol
    / exitAda, PostScript
    restart / leaveBeta, Pliant
    / Exit Do, Exit ForVisual Basic
    / return from xxx or returnCommon Lisp
    iterate / leaveClassic REXX

    redo / retry

    redo/Perl, Perl6
    redo / retryRuby

  • exception

    throwing

    raiseAda, Eiffel, merd, OCaml, Python, Ruby, Scheme-SRFI34, SML
    RAISEModula-3
    raise ... endOz
    throwC#, C++, E, Erlang, Haskell, Java, JavaScript, Pike, Rebol
    throw/nameRebol
    diePerl, Perl6
    return -codeTcl
    errorCommon Lisp, Dylan, Emacs Lisp, Lua, Lua, Pliant
    signalCommon Lisp, Dylan, Smalltalk
    signal predefined_condition_nameClassic REXX
    cerror warnCommon Lisp
    [NSException raise:name ...]Objective-C

    catching

    try: a except exn: bPython
    try a with exn -> bOCaml
    try a catch (exn) bC#, C++, Java, JavaScript
    try a catch e then b endOz
    try { a CATCH e { b } }Perl6
    TRY a EXCEPT exn => b ENDModula-3
    a handle exn => bSML
    a on: exception_name do: [:exn | b]Smalltalk
    ifCurtailedSmalltalk
    rescueEiffel, Ruby
    eval {a}; if ($@) bPerl
    exception when exception_name =>Ada
    catch a (\e -> b)Haskell
    catchErlang, Rebol, Tcl
    catch/nameRebol
    catch(expr) or catch { ... };Pike
    pcallLua
    with-exception-handler or guardScheme-SRFI34
    block a exception(exn) b endDylan
    ?, shy, safePliant
    handler-bind handler-case ignore-errorsCommon Lisp
    NS_DURING a NS_HANDLER b NS_ENDHANDLERObjective-C
    signal on predefined_condition_name
    ...
    predefined_condition_name :
      ...
    
    Classic REXX

    cleanup: code executed before leaving

    ensureRuby, Smalltalk
    finallyC#, Java, Python
    FINALLYModula-3
    unwind-protectCommon Lisp, Emacs Lisp
    cleanupDylan
    dynamic-windScheme

    retrying: after catching an exception, tell the snippet to be re-run

    retryEiffel, Ruby, Smalltalk
    restartDylan
    continuePython

    resume execution where the exception took place

    resumeSmalltalk

  • call-with-current-continuation

    call-with-current-continuation (31)Scheme
    callccRuby, SML-NJ


Types

  • declaration

    typedef t nC, C++, Pike
    type n is tAda
    type n ...Pliant
    type n = tHaskell, OCaml, Pascal, SML
    TYPE n = tModula-3
    using n = ...C#
    data n = tHaskell
    datatype n = tSML
    newtype n = tHaskell
    n = tmerd
    n : tBeta
    (deftype n () 't)Common Lisp

  • annotation (or variable declaration)

    :Ada, E, Eiffel, Modula-3, OCaml, SML
    ::Dylan, Haskell, Mercury
    !!merd
    t vC, C#, C++, Java, Perl6, Pike, Pliant, YCP
    (declare (v t))Common Lisp
    v :@ tBeta

  • cast

    upcast

    (t) eC, C#, C++, Java, PHP
    t(e)Ada, Pascal
    [t] ePike
    static_cast<t>(e)C++
    e :> tOCaml
    CAST(e as t)SQL92

    downcast (need runtime checking)

    (t) eJava
    t(e)Ada
    e : tE
    [t] ePike
    dynamic_cast<t>(e)C++
    e as tC#
    v ?= e (32)Eiffel
    NARROW(e, t)Modula-3

    computed conversion (calls an internal or a user-defined function)

    (t) eC++, Pike
    [t] eMSH
    t(e)C++
    e : tE
    cast e tPliant
    expr cast tPliant
    make t e / to t eRebol

  • mutability, constness

    type of a mutable value

    it is the defaultAda, C, C#, C++, Java
    val x: TPascal
    T refOCaml, SML
    STRef a THaskell

    type of a constant value

    const TC++, C99
    constant TAda
    const x: TPascal
    it is the defaultHaskell, 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 paraOCaml
    object:method(para)Lua
    object method paraPliant, Tcl
    object method: para1 method_continuation: para2Smalltalk
    object <- method(para) (34)E
    [ object method: para ]Objective-C
    object->method(para)C++, Perl, PHP, Pike
    object["method"](para)Pike
    object/method paraRebol
    method object paraHaskell, Mercury
    (method object para)Common Lisp
    method(object, para)Ada, Dylan
    para->methodBeta
    (send object method para)MzScheme

    with no parameter

    object.methodEiffel, merd, Perl6, Ruby
    object.property (35)C#
    object.method()C#, C++, E, Java, JavaScript, Python
    object#methodOCaml
    object:methodPliant
    object->methodPerl
    object->method()Pike
    object/methodRebol
    object["method"]()Pike
    object methodSmalltalk
    [ object method ]Objective-C
    method objectHaskell, Mercury
    (method object)Common Lisp
    method(object)Ada, Dylan
    (send object method)MzScheme

  • object creation

    newAda, C#, C++, Java, JavaScript, OCaml, Perl, Perl6, PHP, Pliant, Ruby, Simula, Smalltalk
    class_name()Pike, Python
    !class_name!constructor_name(...)Eiffel
    &Beta
    make-objectMzScheme
    (make-instance class_name ...)Common Lisp
    [class_name alloc]Objective-C
    make class_name! ...Rebol
    def object_name { ... }E

  • object cloning

    o.clonePerl6
    o.clone (36)Eiffel, Ruby
    o.deep_cloneEiffel
    o.clone()Java
    o.Clone()C#
    clone / copy or deepCopySmalltalk
    dclonePerl
    [o copy]Objective-C
    copy.copy(o) (37)Python
    purecopyEmacs Lisp
    {< >} or Oo.copy oOCaml
    o2 = o (38)C++, PHP
    o2.all := o.allAda
    make o []Rebol

  • manually call an object's destructor

    deleteC++, JavaScript
    destroyJava, Pike
    DESTROYPerl
    deallocObjective-C
    DisposeC#
    __del__Python
    Requires instantiation of Ada.Unchecked_DeallocationAda

  • class declaration

    classC#, C++, Haskell, Java, MzScheme, OCaml, Perl6, PHP, Pike, Python, Ruby
    class c inherit p1 p2 ... feature decl decl ... endEiffel
    defclass defstructCommon Lisp
    subclassSmalltalk
    typePliant
    type c is tagged record ... end recordAda
    @interface c { ... } ... @endObjective-C
    :Beta

  • testing class membership

    isaPerl
    is_a? kind_of?Ruby
    o.meta.isaPerl6
    isKindOfSmalltalk
    isKindOfClassObjective-C
    dynamic_castC++
    instanceofJava, JavaScript
    isinstancePython
    inAda
    isC#
    is_aPHP
    Program.inherits or Program.implementsPike
    entry_typePliant
    typepCommon Lisp
    ISTYPEModula-3
    object## < classname##Beta
    type.accepts(object) / object =~ v : typeE
    var ?= val (39)Eiffel

  • get the type/class corresponding to an object/instance/value

    classObjective-C, Ruby, Smalltalk
    __class__Python
    getClassJava
    typeidC++
    typeofC#, JavaScript
    type-ofCommon Lisp
    refPerl
    generatorEiffel
    metaPerl6
    object_programPike
    getAllegedTypeE

  • methods available

    methodsRuby
    get_class_methodsPHP
    getMethodsJava
    get-memberMSH
    indicesPike
    o.meta.getmethodsPerl6
    o.__class__.__dict__ (40)Python
    o class selectors / o class allSelectorsSmalltalk
    o.__getAllegedType().getMessageTypes()E

  • inheritance

    child :< parentBeta
    class child : parentC#, C++
    class child < parent endRuby
    class child is parent { ... }Perl6
    class child extends parentJava
    class child(parent):Python
    class child inherit parent endEiffel
    parent subclass: childSmalltalk
    make parent ...Rebol
    inheritOCaml, Pike
    def child extends makeSuperObject(parent, ...) { ... }E
    type child is new parent with record ... end recordAda
    (defclass child (parent) ...)Common Lisp
    @interface child : parent { ... } ... @endObjective-C
    @ISA = qw(parent1 parent2)Perl

  • has the method

    canPerl, Perl6
    respond_to?Ruby
    respondsToE, Smalltalk
    respondsToSelectorObjective-C
    hasattr(obj, "meth") (41)Python
    object->methodPike
    all [in object 'method function? get in object 'method]Rebol
    find-methodCommon Lisp

  • current instance

    thisBeta, C#, C++, Java, JavaScript, PHP, Pike
    THISSimula
    selfObjective-C, Rebol, Ruby, Smalltalk
    object_name if defined as: def object_name { ... }E
    CurrentEiffel
    first parameterPerl, Pliant, Python
    first parameter (42)Python
    dispatching parameterAda, Common Lisp
    MeVisual Basic
    .Perl6

  • accessing parent method

    superE, Java, Objective-C, Ruby, Smalltalk
    super(Class, self).meth(args)Python
    baseC#
    PrecursorEiffel
    $o.SUPER::method(...)Perl6
    $o->SUPER::method(...)Perl
    method(parent(dispatching-parameter))Ada
    call-next-methodCommon Lisp

  • accessing child method

    innerBeta


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 ... endRuby
    { module "p"; ... }YCP
    :- module(p)Prolog
    (defpackage p ...)Common Lisp
    automatically done based on the file nameOCaml, 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_featuresRuby

  • import

    everything into current namespace

    use p (44)Perl
    uses pPascal
    using pC#
    using namespace p;C++
    (use-package 'p)Common Lisp
    open pOCaml
    importPike
    import pHaskell
    IMPORT p;Modula-2
    import p.*Java
    import "p"YCP
    from p import *Python
    with p; use p;Ada
    inherit c export {NONE} all endEiffel
    include or even extendRuby
    doRebol

    selectively

    import p (name1, name2, ...)Haskell
    import p.name1; import p.name2Java
    (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 pPython
    use p; (45)Perl
    require pPerl
    require "p"Ruby
    (require 'p) (46)Common Lisp
    with p;Ada
    automatically done (47)Java, OCaml


Strings

  • type name

    char[]C
    char const[]C++
    stringC#, C++, OCaml, Pascal, Pike, YCP
    string!Rebol
    StringAda, C#, Haskell, Java, JavaScript, merd, Smalltalk, Visual Basic
    STRINGEiffel
    strYAML
    StrPerl6, Pliant
    NSString *Objective-C
    CHAR, VARCHAR(size)SQL92

  • character type name

    charC, C#, C++, OCaml
    char!Rebol
    CharHaskell, merd, Perl6
    CharacterAda, Smalltalk
    CHARACTEREiffel

  • character "z"

    'z'Ada, B, C, C#, C++, Classic REXX, E, Eiffel, Haskell, OCaml, Pascal, Pike, Prolog
    "z"Classic REXX, merd, sh
    $zSmalltalk
    #\zCommon Lisp, Scheme
    #"z"Rebol
    &zOz
    ?zEmacs 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' ... MARKPerl, 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 ... MARKPerl, sh
    <<MARK ... #{v} ... MARKRuby
    <<<MARK ... $v ... MARKPHP
    [ 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 stringsCommon 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)

    showHaskell
    to_s, to_str, inspect, String()Ruby
    to_stringmerd, Pliant
    tostringLua, YCP
    toStringJava, JavaScript
    ToStringC#
    StringJavaScript
    perlPerl6
    DumperPerl
    "" . ePerl
    "" ~ ePerl6
    "" + eE, Java, JavaScript
    stringPliant
    str, `e`, reprPython
    outEiffel
    cvsPostScript
    'ImageAda
    asString printStringSmalltalk
    as(<string>, e)Dylan
    (string) ePike
    (coerce e 'string)Common Lisp
    prin1-to-stringEmacs Lisp
    to string! / to-string / to ""Rebol
    descriptionObjective-C

  • serialize (marshaling)

    export-clixmlMSH
    Marshal.to_stringOCaml

  • unserialize (un-marshaling)

    import-clixmlMSH
    Marshal.from_stringOCaml

  • sprintf-like

    sprintfAwk, C, C++, merd, OCaml, Perl, Perl6, PHP, Pike, Ruby
    %Python, Ruby
    format (49)Common Lisp, Erlang, Scheme-SRFI28
    FormatC#
    putFormatBeta
    stringWithFormatObjective-C

  • simple print

    on strings

    putsC, Dylan
    printAwk, Basic, Java, merd, PHP, SML
    writeJavaScript, Pascal, Pike
    putStrHaskell
    print_stringOCaml
    consolePliant
    writelnJavaScript, Pascal
    write-stringCommon Lisp
    putStrLnHaskell
    Put_LineAda
    displayCobol
    messageEmacs Lisp
    put_stringEiffel
    showSmalltalk
    print_endline (50)OCaml
    println (50)Java, merd
    put_charsErlang
    echoPHP
    echo (50)sh
    emitForth
    putTextBeta
    sayClassic REXX

    on simple objects

    printPerl, Perl6
    say (50)Perl6
    puts (50)Tcl

    on any objects

    printRuby
    print (50)Dylan, Haskell, Python, Rebol
    prinRebol
    display writeScheme
    PutAda
    p (50)Ruby
    puts (51)Ruby
    writeProlog
    write prin1 princ printCommon Lisp
    princ prin1Emacs Lisp
    WriteLineC#

    printf-like

    printfAwk, C, C++, merd, OCaml, Perl, PHP, Ruby
    writePike
    WriteLineC#
    putFormatBeta
    format (49)Common Lisp

  • string equality & inequality

    eq nePerl, Perl6, Tcl
    strcmpC
    == !=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
    equalsJava
    equal, equalpCommon Lisp
    is_equalEiffel
    isEqualObjective-C

  • string size

    lengthAwk, Beta, C++, Common Lisp, Eiffel, Haskell, Java, JavaScript, Objective-C, OCaml, Perl, PostScript, Ruby
    LENGTHClassic REXX
    'LengthAda
    length?Rebol
    sizeC++, E, Ruby, Smalltalk, SML, YCP
    LengthC#, Modula-3, Oz, Pascal
    lenPliant, Python, Visual Basic
    strlenC, PHP
    string-lengthScheme, XPath
    sizeofPike
    countEiffel
    bytes charsPerl6
    CHARACTER_LENGTHSQL92

  • 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$bsh, Tcl
    concatenateCommon Lisp, Dylan
    string-appendScheme
    CatModula-3
    strcatC
    concatXPath
    appendBeta, Rebol
    stringByAppendingStringObjective-C
    Awk, Classic REXX

  • duplicate n times

    *Ada, E, Pike, Python, Ruby
    xPerl, Perl6
    timesmerd
    repeatPliant
    str_repeatPHP
    string repeatTcl
    strrepLua
    insert/dupRebol
    COPIESClassic REXX

  • upper / lower case character

    upcase / downcaseEmacs Lisp, Ruby
    uc / lcPerl, Perl6
    upper / lowerPliant, Python
    toUpper / toLowerHaskell
    to_upper / to_lowerEiffel
    To_Upper / To_LowerAda
    toUpperCase / toLowerCaseE, Java, JavaScript
    upper_case / lower_casePike
    uppercase / lowercaseOCaml
    strupper / strlowerLua
    upper / lower (53)Lua
    ToUpper / ToLowerC#, Oz
    toupper / tolowerAwk, C, C++
    string toupper / string tolowerTcl
    asLowercase / asUppercaseSmalltalk
    upCase / lowCaseBeta
    uppercase form / lowercase formRebol
    char-upcase / char-downcaseCommon Lisp, Scheme

  • uppercase / lowercase / capitalized string

    upcase / downcaseEmacs Lisp, Ruby
    upper / lowerPython, SQL92
    uppercase/lowercaseOCaml, Rebol
    toUpperCase / toLowerCaseE, Java, JavaScript
    ToUpper / ToLowerC#
    to_upper / to_lowerAda, Eiffel
    toupper / tolowerAwk, YCP
    uc / lcPerl, Perl6
    UpperCase / LowerCasePascal
    uppercaseString / lowercaseString / capitalizedStringObjective-C
    UCase / LCaseVisual Basic
    strtoupper / strtolowerPHP
    strupper / strlowerLua
    string toupper / string tolowerTcl
    string-upcase / string-downcaseCommon Lisp, Scheme
    asLowercase / asUppercaseSmalltalk
    makeLC / makeUCBeta
    parse upper var in_var out_var / parse lower var in_var out_varClassic REXX

  • ascii to character

    chrHaskell, OCaml, Pascal, Perl, Perl6, PHP, Python, Ruby, SML
    format %c $cTcl
    toCharE
    strcharLua
    from_integerEiffel
    fromCharCodeJavaScript
    characterPliant
    Character value: cSmalltalk
    code-charCommon Lisp
    integer->charScheme
    'ValAda
    (char) cC, C#, C++, Java
    to char! / to-charRebol
    X2C, D2CClassic REXX

  • character to ascii

    ordHaskell, Pascal, Perl, Perl6, PHP, Python, SML
    getNumericValueJava
    charCodeAtJavaScript
    asciiValueSmalltalk
    codeEiffel, OCaml
    char-codeCommon Lisp
    char->integerScheme
    s[0]Ruby
    s 0 getPostScript
    scan $s %cTcl
    strbyteLua
    toIntegerE
    'PosAda
    numberPliant
    (int) cC, C#, C++, Java
    to integer! / to-integerRebol
    C2X, C2DClassic REXX

  • accessing n-th character

    s[n]C, C#, C++, E, PHP, Pike, Python, Ruby
    s(n)Ada
    s:nPliant
    s.[n]OCaml
    s !! nHaskell
    s @ nEiffel
    s/:nRebol
    string index s nTcl
    subSML
    char, aref, schar, svrefCommon Lisp
    GetCharModula-3
    atSmalltalk
    at (54)C++
    arefCommon Lisp
    char(s, i)B
    charAtJava, JavaScript
    characterAtIndexObjective-C
    n -> s.inxGetBeta
    string-refScheme

  • 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 lenPliant
    strndup(s + n, len)C
    substringEiffel, Java, Scheme, SML, XPath, YCP
    SubstringC#
    substrC++, Perl, Perl6, PHP
    SUBSTRClassic REXX
    subOCaml
    SUBModula-3
    subseqCommon Lisp
    sliceJavaScript
    rangeTcl
    copy/part at s n lenRebol
    copy/part at s n at s mRebol
    s copyFrom: n to: mSmalltalk
    (n,m)->s.subBeta
    [s substringWithRange:NSMakeRange(n, len)]Objective-C
    SUBSTRING(s FROM n len)SQL92

  • locate a substring

    indexPerl, Perl6, Ruby
    indexOfJava, JavaScript
    IndexOfC#
    startOfE
    searchCommon Lisp, Pike, PostScript
    strstr / strchr / indexC
    findRebol, YCP
    find / indexPython
    index / index_non_blank / find_tokenAda
    substring_indexEiffel
    rangeOfStringObjective-C
    POSClassic REXX
    POSITION(needle IN s)SQL92

  • locate a substring (starting at the end)

    rindexOCaml, Perl, Perl6, Ruby
    rfindC++
    rfind / rindexPython
    find/lastRebol
    / strrchr / rindexC
    index(Going => Backward)Ada
    lastStartOfE
    lastIndexOfJava, JavaScript
    last_index_of (55)Eiffel
    LastIndexOfC#
    (search substring string :from-end t)Common Lisp
    [string rangeOfString:substring options:NSBackwardsSearch]Objective-C
    LASTPOSClassic REXX


Booleans

  • type name

    BoolHaskell, Perl6, Pliant
    boolC#, C++, C99, OCaml, Python, YAML
    BooleanAda, Lua, Pascal, Smalltalk, Visual Basic
    booleanCommon Lisp, Java, YCP
    BOOLEANEiffel
    logic!Rebol

  • false value

    nilCommon Lisp, Emacs Lisp, Lua
    undef / 0 / "0" / "" / ()Perl, Perl6
    False / None / 0 / "" / () / [] / {}Python
    false / 0 / ""PHP
    NULL / 0 / '\0'C
    NULL / 0 / '\0' / falseC++, C99
    0 / "0" / ""Awk
    0 / NaN / "" / false()XPath
    0Classic REXX
    0 (56)B, Pike
    0 / FalseVisual Basic
    false / noneRebol
    false / null / undefined / 0 / NaN / ""JavaScript
    false / no / off / 0Tcl
    false / no / off / nYAML
    false / nilLua, Ruby
    falseAda, BCPL, Beta, C#, E, FL, Java, OCaml, Oz, Pascal, Pliant, PostScript, Smalltalk, SML, YCP
    FalseEiffel, Haskell, merd
    FALSEModula-3, SQL92
    false / exit status different from 0sh
    No / failProlog
    #fDylan, Scheme

  • true value

    anything not falseAwk, B, C, Perl, Perl6, Pike
    true / anything not falseC++, C99, JavaScript, Lua, PHP, Ruby
    true / anything not falseRebol
    True / anything not falsePython
    true() / anything not falseXPath
    #t / anything not falseDylan, Scheme
    t / anything not falseCommon Lisp, Emacs Lisp
    yes / on / true / non zero numberTcl
    yes / on / true / yYAML
    TrueEiffel, Haskell, merd
    non-zero-numbers / TrueVisual Basic
    TRUEModula-3, SQL92
    trueAda, BCPL, Beta, C#, E, FL, Java, OCaml, Oz, Pascal, PHP, Pliant, PostScript, Smalltalk, SML, YCP
    true / exit status 0sh
    Yes / trueProlog
    1Classic REXX

  • logical not

    !Awk, B, C, C#, C++, E, Java, JavaScript, Perl, Perl6, PHP, Pike, Ruby, Tcl, YCP
    notAda, Beta, Common Lisp, Eiffel, Emacs Lisp, Forth, Haskell, Lua, merd, OCaml, Pascal, Perl, Perl6, Pliant, PostScript, Prolog, Python, Rebol, Ruby, Scheme, Smalltalk, SML, XPath
    NotOz, Visual Basic
    NOTModula-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 / andCommon Lisp, Emacs Lisp, Lua, Modula-2, Perl, Perl6, PHP, Pliant, Python, Ruby, Scheme, Smalltalk
    or / &OCaml
    or / and & (57)Modula-2
    OR / ANDModula-3
    any / allRebol
    orelse / andalsoSML
    orelse / andthenOz
    or else / and thenAda, Eiffel
    ; / ,Prolog

    non short circuit (always evaluates both arguments)

    | / &C#, Classic REXX, Java, Smalltalk
    or / andAda, Beta, Eiffel, Forth, Pascal, PostScript, Rebol, SML, XPath
    Or / AndVisual Basic
    Or / And (58)Oz
    \/ / /\ (10)BCPL
    ?| /Perl6


Bags and Lists

  • type name

    seqYAML
    a listOCaml
    [a]Haskell
    a[]C#
    ListPliant
    Array or ListPerl6

  • list concatenation

    +E, Eiffel, merd, Pike, Python, Ruby
    ,Smalltalk
    , (59)Perl
    @OCaml, SML
    ++Haskell
    |||Icon
    array_mergePHP
    mergeYCP
    concatJavaScript, Tcl
    concatenateDylan
    append nconcCommon Lisp, Emacs Lisp
    appendBeta, Rebol, Scheme
    AppendOz
    arrayByAddingObjectsFromArrayObjective-C

  • list flattening

    one level depth

    concatHaskell, Mercury, SML
    flattenmerd, OCaml, YCP
    FlattenOz
    eval concatTcl

    recursive

    flattenPike, 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
    listCommon 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 versionBCPL
    a[i]:defaultYCP
    a(i)Ada
    a:iPliant
    a/:iRebol
    a.(i)OCaml
    a !! iHaskell, Mercury
    a @ iEiffel
    a i get (63)PostScript
    at (64)Smalltalk
    at (54)C++
    lindexTcl
    NthOz
    nth / arefCommon Lisp, Emacs Lisp
    list-ref / vector-refScheme
    elementDylan
    sliceRuby
    node[i]XPath
    objectAtIndexObjective-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
    consCommon Lisp, Emacs Lisp, Scheme
    pairDylan

    side-effect

    unshiftJavaScript, Perl, Perl6, Ruby
    prependYCP
    push_frontC++
    addFirstSmalltalk
    insertRebol
    put_firstEiffel
    pushCommon Lisp
    array_unshiftPHP

  • 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)

    pushmerd
    arrayByAddingObjectObjective-C

    side-effect

    pushJavaScript, Perl, Perl6, Ruby
    push_backC++
    appendPliant, Python, Rebol
    +=Pliant
    addJava, Smalltalk, YCP
    put_lastEiffel
    array_pushPHP
    addObjectObjective-C

  • first element

    headHaskell
    hdOCaml
    carCommon Lisp, Emacs Lisp, Scheme
    firstEiffel, Pliant, Rebol, Smalltalk

    iterator

    headBeta
    beginC++

  • all but the first element

    tailHaskell
    tlOCaml
    cdrCommon Lisp, Emacs Lisp, Scheme
    allButFirstSmalltalk

  • last element

    lastE, Eiffel, Haskell, Pliant, Rebol, Scheme, Smalltalk
    LastOz
    lastObjectObjective-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

    shiftJavaScript, Perl, Perl6, Ruby
    shift!merd
    popCommon Lisp
    removeFirstSmalltalk
    array_shiftPHP

  • get the last element and remove it

    popE, JavaScript, Perl, Perl6, Python, Ruby
    pop!merd
    array_popPHP
    removeLastSmalltalk

  • for each element do something

    eachmerd, Pliant, Ruby
    for inE, JavaScript, Python, Ruby
    forPerl
    foreachLua, 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_eachC++
    for-eachScheme
    forallPostScript
    ForAllOz
    iterOCaml
    doSmalltalk
    do_allEiffel
    appSML
    mapcEmacs Lisp
    mapM_Haskell
    for (v in l) ...Awk, Dylan
    For Each v in l ... NextVisual Basic
    for v in range loop .. end loopAda
    (dolist (v l) ...) (loop for v in l do ...) mapcCommon Lisp
    list.iterate (# do current ... #)Beta

  • transform a list (or bag) in another one

    mapDylan, Haskell, Mercury, merd, OCaml, Perl, Pike, Python, Ruby, Scheme, SML
    MapOz
    mapcarCommon Lisp, Emacs Lisp
    maplistYCP
    for-eachXSLT
    foreach or selectedMSH
    collectRuby, Smalltalk
    transformC++
    array_mapPHP
    [ f x | x <- l ] (65)Haskell
    [ f(x) for x in l ] (65)Python

  • transform two lists in parallel

    map2OCaml
    zipWithHaskell
    ZipOz
    mapDylan, Python, Scheme
    mapcarCommon Lisp
    l1 with: l2 collect: ...Smalltalk
    transformC++
    ListPair.mapSML

  • find an element

    findHaskell, merd, OCaml, Rebol, Ruby, Scheme-SRFI1, SML, YCP
    find find_ifC++
    find find-ifCommon Lisp
    first (15)Perl
    detectRuby, Smalltalk
    searchPike
    lsearchTcl
    indexOfObject, indexOfObjectIdenticalToObjective-C

  • keep elements matching

    find_allOCaml, Ruby
    filterHaskell, Mercury, merd, OCaml, Pike, Python, Scheme-SRFI1, SML, YCP
    filter!Scheme-SRFI1
    FilterOz
    grepPerl, Perl6
    whereMSH
    selectRuby, Smalltalk
    remove-if delete-ifCommon Lisp
    rejectRuby
    chooseDylan
    [ x | x <- l, p x ] (65)Haskell
    [ x for x in l if p(x) ] (65)Python

  • f(... f(f(init, e1), e2) ..., en)

    foldlHaskell, Mercury, merd, SML
    FoldLOz
    fold_leftOCaml
    foldScheme-SRFI1
    reduceCommon Lisp, Dylan, Perl6, Pike, Python
    reduce (15)Perl
    injectRuby
    inject intoSmalltalk

  • f(e1, f(e2, ... f(en, init) ...))

    foldrHaskell, Mercury, merd, SML
    FoldROz
    fold-rightScheme-SRFI1
    fold_rightOCaml
    rreducePike
    (reduce f '(e1 e2 ... en) :from-right t :initial-value init)Common Lisp

  • split a list in 2 based on a predicate

    partitionHaskell, merd, OCaml, Ruby, Scheme-SRFI1, SML
    partition!Scheme-SRFI1
    PartitionOz
    split-sequence (66)Common Lisp

  • is an element in the list

    member?Dylan, merd, Ruby
    include?Ruby
    memOCaml
    memberCommon Lisp
    member memq memvScheme
    MemberOz
    containsE, YCP
    containsObjectObjective-C
    inJavaScript, Python, SQL92
    in_arrayPHP
    includesSmalltalk
    elemHaskell, Mercury
    hasEiffel
    has_valuePike

  • is the predicate true for an element

    anyHaskell, Mercury, Python, Scheme-SRFI1
    any?Dylan, Ruby
    anySatisfySmalltalk
    existsOCaml, SML
    exists?merd
    someCommon Lisp
    SomeOz

  • is the predicate true for every element

    allHaskell, Mercury, Python, SML
    AllOz
    all?merd, Ruby
    allSatisfySmalltalk
    everyCommon Lisp, Scheme-SRFI1
    every?Dylan
    for_allOCaml

  • smallest / biggest element

    min / maxCommon Lisp, Eiffel, Java, Perl6, Pike, Python, Ruby, Scheme, Smalltalk
    minimum / maximumHaskell, Mercury, merd
    minimum-of / maximum-ofRebol
    min minstr / max maxstr (15)Perl
    min_element / max_elementC++

  • join a list of strings in a string using a glue string

    joinJavaScript, Perl, Perl6, PHP, Python, Rebol, Ruby
    JoinC#
    rjoinE
    concatOCaml
    l * gluePike, Ruby
    (macpconcat 'identity l glue)Emacs Lisp
    componentsJoinedByStringObjective-C

  • list size

    sizeC++, Dylan, E, Java, merd, Pliant, Ruby, Smalltalk, YCP
    sizeofPike
    lengthC#, Common Lisp, Emacs Lisp, Haskell, Java, JavaScript, Mercury, OCaml, PostScript, Prolog, Ruby, Scheme, SML
    LengthOz
    length?Rebol
    lenPython
    llengthTcl
    elemsPerl6
    getnLua
    countEiffel, Objective-C, PHP, SQL92, XPath
    scalar @lPerl

  • iterate with index

    each_with_indexmerd, Ruby
    foreach($l as $i => $v)PHP
    for i => v in lE
    for (v in l, i from 0) ... endDylan
    forAllIndOz
    foreachiLua
    foreach(l; typ0 i; typ1 v) { ... }Pike
    withIndexDoSqueak
    (loop for v in l as i upfrom 0 do ...)Common Lisp

  • remove duplicates

    uniqmerd, Perl6, Ruby
    uniq or uniq2Pike
    uniqueRebol
    unique (67)C++
    nubHaskell
    array_uniquePHP
    delete-duplicates delete-duplicates!Scheme-SRFI1
    remove-duplicatesDylan
    remove-duplicates delete-duplicatesCommon Lisp
    lsort -uniqueTcl
    tosetYCP
    distinctSQL92

  • sort

    sortC#, C++, Common Lisp, E, Eiffel, Haskell, Java, JavaScript, Lua, merd, OCaml, Perl, Perl6, PHP, Pike, Python, Rebol, Ruby, XSLT, YCP
    sort (68)Scheme
    sortedPython
    SortOz
    sort_bymerd, Ruby
    sortByHaskell, Smalltalk
    order bySQL92
    lsortTcl
    asortAwk
    sort-objectMSH
    sortedArrayUsingSelector, sortUsingSelectorObjective-C

  • reverse

    reverseC++, Common Lisp, Dylan, Emacs Lisp, Haskell, Java, JavaScript, Mercury, merd, Perl, Perl6, Pike, Python, Rebol, Ruby, Scheme
    ReverseC#, Oz
    reversedSmalltalk
    reverse_copyC++
    revOCaml, SML
    array_reversePHP

  • list of couples from 2 lists

    combineOCaml
    zipHaskell, merd, Perl6, Python, Ruby, Scheme-SRFI1, SML
    pairlis (69)Common Lisp
    transposeRuby

  • 2 lists from a list of couples

    splitOCaml
    unzipHaskell, merd, SML
    unzip2Scheme-SRFI1
    transposeRuby
    zip(*l)Python

  • lookup an element in a association list

    lookupHaskell
    assocCommon Lisp, OCaml, Ruby
    assoc assqEmacs Lisp
    assoc assq assvScheme
    selectRebol

  • list out of a bag

    to_aRuby
    toArrayJava
    asArraySmalltalk
    to_listmerd
    map-as(<list>, bag)Dylan


Various Data Types

  • tuple type

    t1 * ... * tnOCaml
    (t1, ..., tn)Haskell
    t1, ..., tnmerd
    tuple!Rebol
    Tuple[T1, T2, T3]E

  • tuple constructor

    a, b, cLua, merd, OCaml, Python, Ruby
    ( a, b, c )Ada, Haskell, Perl, Prolog, SML
    { a. b. c }Smalltalk
    [ a, b, c ]E
    a . b . cRebol
    (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
    NothingProlog

    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

    tmerd, Perl
    *tPython, Ruby

  • reference (pointer)

    creation

    &B, C, C#, C++
    \Perl
    AddressOfVisual Basic
    addr (70)Pascal
    @ (70)Pascal
    lvBCPL
    refC#, OCaml, SML
    newSTRefHaskell
    NewCellOz
    'accessAda
    :> :>>Pliant

    dereference

    * (71)B, C, C#, C++
    $ @ % & (71)Perl
    ->[...] ->{...} ->(...) (72)Perl
    -> (73)C, C++
    ^ (72)Modula-3, Pascal
    ! (71)OCaml, SML
    rvBCPL
    readSTRefHaskell
    AccessOz
    .[all]Ada
    @Forth

    assigning (when dereferencing doesn't give a lvalue)

    writeSTRefHaskell
    AssignOz
    :=OCaml, SML
    !Forth

  • optional value

    null value

    0C++
    NULLC, SQL92
    nilCommon Lisp, Emacs Lisp, Lua, Objective-C, Ruby
    nullC#, Java, JavaScript, Smalltalk
    Null (74)Ada
    undefPerl
    NoneOCaml, Python
    NothingHaskell
    #f ()Emacs Lisp
    (empty) / ~ / nullYAML

    value

    vAda, C, C#, C++, Common Lisp, Emacs Lisp, Java, JavaScript, Lua, Perl, Perl, Python, Ruby, Scheme, Smalltalk
    Just vHaskell
    Some vOCaml

    type name

    optionOCaml
    MaybeHaskell

  • 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:fieldPliant
    field rHaskell
    ->C, C++
    r["field"]JavaScript
    #field rSML
    normal function callCommon Lisp, Dylan, Haskell, Smalltalk

  • dictionary

    type name

    mapYAML
    (k, v) Hashtbl.tOCaml
    DictionaryPliant
    HashPerl6

    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 endDylan
    [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.kJavaScript, Lua
    h:kPliant
    h["k"] or h->kPike
    (gethash k h)Common Lisp

    access: read

    h k getPostScript
    findOCaml
    fetchRuby
    getJava
    atSmalltalk
    h@k or h.at(k)Eiffel
    h[k]:defaultYCP
    h.get(k, returned_value_when_k_unfound)Python
    objectForKeyObjective-C

    access: write

    h k o putPostScript
    putEiffel, Java
    add, replaceOCaml
    storeRuby
    h[k]YCP
    h at: k put: oSmalltalk
    [h setObject:o forKey:k]Objective-C

    has the key ?

    exists $h{k}Perl
    existsPerl6, Pliant
    hasEiffel
    haskeyYCP
    has_keyPython
    has_key?, include?, key?, member?Ruby
    ContainsC#
    containsKeyJava
    includesKeySmalltalk
    k in hPython
    k not in hPython
    inAwk
    memOCaml
    find (76)C++
    h[k]Pike
    (gethash k h)Common Lisp
    mapsE
    knownPostScript

    remove by key

    delete $h{k}Perl
    del h[k]Python
    removeEiffel, Java, OCaml, YCP
    RemoveC#
    removeKeyE, Smalltalk
    remhashCommon Lisp
    deleteJavaScript, Perl6, Ruby
    eraseC++
    m_deletePike
    removeObjectForKeyObjective-C
    undefPostScript

    list of keys

    keysMSH, Perl, Perl6, Python, Ruby, Smalltalk
    keySetJava
    allKeysObjective-C
    AllKeysC#
    indicesPike
    current_keysEiffel
    getKeysE
    array_keysPHP

    list of values

    valuesJava, Perl, Perl6, Pike, Python, Ruby, Smalltalk
    getValuesE
    contentEiffel
    array_valuesPHP

  • range

    inclusive .. inclusive

    a .. bAda, E, merd, MSH, Pascal, Perl, Ruby
    [ a .. b ]Haskell
    toSmalltalk
    seqsh
    rangePHP
    range(from: a, to: b, by: step)Dylan
    List.number A B StepOz

    inclusive .. exclusive

    a ... bRuby
    a ..! bE
    rangePython


Mathematics

  • type name

    integers

    short, int, longC, C#
    intYAML
    IntPerl6
    Int, uInt, Int8, Int16...Pliant
    INTEGER, INT, SMALLINTSQL92

    decimal

    float, doubleC, C#
    floatYAML
    Float, Float32, Float64Pliant
    NUMERIC, DECIMAL, DOUBLE PRECISIONSQL92
    RatPerl6

  • numbers syntax

    integers

    1000Ada, 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.0Awk
    1000, '1000'DClassic REXX

    integers in base 2, octal and hexadecimal

    0b1, 07, 0xfOz, Perl, Pike, Ruby
    0b1, 0o7, 0xfOCaml, Perl6
    07, 0xfAwk, C, C++, JavaScript, Python, Tcl
    0xfC#, E
    07B
    0o7, 0xfHaskell
    1bEiffel
    2#1#, 8#7#, 16#f#Ada
    2#{1}, #{F}Rebol
    #b1, #o7, #xfCommon Lisp, Emacs Lisp, Scheme
    #2r1, #8r7, #16rfCommon Lisp, Emacs Lisp
    1b, FhPliant
    '1'B, 'F'XClassic REXX
    B'1', X'F'SQL92

    integer thousand-seperator

    1_000, 10_00, 100_0E, Eiffel, OCaml, Perl, Perl6, Ruby
    1'000, 10'00, 100'0Rebol
    1_000Ada, merd

    decimals

    1000., 1E3Ada, C, C++, Classic REXX, E, Java, JavaScript, OCaml, Python, Scheme, SQL92, Tcl
    1000., 1E3, 1,0Rebol
    1000., 1.E3Oz
    1000.0, 1E3C#, Common Lisp, Emacs Lisp, Pike, Ruby, Smalltalk
    1000.0, 1.0E3Haskell
    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 divPostScript

  • 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
    powC, C++, Java, JavaScript, PHP, Pike, Python, SML, Tcl
    PowC#, Oz
    powerDelphi-Kylix, Rebol
    expPostScript
    exptCommon Lisp, Emacs Lisp, Scheme
    raisedToSmalltalk

  • 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
    negPostScript
    negateRebol

  • random

    random number

    randPerl, Perl6

    seed the pseudo random generator

    srandPerl, Perl6

  • operator priorities and associativities

    addition vs multiplication

    mathematicalC, C#, C++, Classic REXX, Haskell, Java, merd, Perl, Perl6, Python, Ruby, sh, Tcl
    same prioritiesSmalltalk

    exponentiation vs negation (is -3^2 equal to 9 or -9)

    mathematicalClassic REXX, Haskell, Perl, Perl6, Python, Ruby
    negation firstOCaml

  • square root / e-exponential / absolute value

    sqrt / exp / absAda, 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 / AbsC#, Oz
    sqrt / / absPostScript
    Sqrt / / ABSModula-3
    / exp / absPliant
    sqrt / /Pike
    square-root / exp / abs or absoluteRebol
    Sqrt / Exp / ABSClassic REXX

  • trigonometry

    basic

    sin / cos / tanAda, 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 / TanC#, Classic REXX, Oz
    sin / cos /Awk, PostScript
    sine / cosine / tangentEiffel, Rebol

    inverse

    asin / acos / atan (81)Ada, C, C++, Common Lisp, JavaScript, OCaml, Perl, Perl6, Pike, Pliant, Python, Ruby, Scheme
    Asin / Acos / AtanC#, Oz
    ASin / ACos / ATanClassic REXX
    arcSin / arcCos / arcTanSmalltalk
    arcsine / arccosine / arctangentRebol
    arc_sine / arc_cosine / arc_tangentEiffel
    / / atanPostScript

  • logarithm

    log / log10C, C++, Eiffel, Lua, OCaml, Perl, Perl6, PHP, Pliant, Python, Ruby, Tcl
    log /Awk, E, Emacs Lisp, Java, JavaScript, Pike, Scheme
    log / logBase 10Haskell
    Log / Log10C#, Classic REXX
    Log /Oz
    Log / Log(X => val, Base => 10.0)Ada
    log / (82)Common Lisp
    ln /Pascal
    ln / log10Delphi-Kylix
    ln / logPostScript, SML
    ln / log: 10Smalltalk
    log-e / log-10 / log-2Rebol

  • euclidian division (both quotient and modulo)

    divmodPython, Ruby
    divModHaskell
    div ldiv lldivC
    IntInf.quotremSML
    floorCommon Lisp, Dylan

  • modulo

    modulo of -3 / 2 is 1

    %Classic REXX, Perl, Perl6, Pike, Python, Ruby, Tcl
    %%E
    \\Smalltalk
    modAda, Common Lisp, Emacs Lisp, Haskell, Prolog, SML
    MODModula-3
    moduloDylan, Ruby

    modulo of -3 / 2 is -1

    %Awk, B, C, C#, C++, E, Java, JavaScript, PHP, Pliant
    modLua, OCaml, Oz, Pascal, PostScript, XPath
    remainderRuby, Scheme
    remAda, BCPL, Smalltalk
    //Classic REXX, Rebol

  • truncate / round / floor / ceil

    trunc / round / floor / ceilC, C++
    truncate / round / floor / ceilingCommon Lisp, Perl6, PostScript, Scheme
    int / round / floor / ceilJavaScript, Pike, Python
    to_i, Integer() / round / floor / ceilRuby
    TRUNC / FORMAT / Floor / CeilClassic REXX
    / round / floor / ceilE, Java, Lua, PHP, SML, Tcl
    / Round / Floor / CeilingC#
    / Round / Floor / CeilOz
    / round / floor / ceilingDylan, Emacs Lisp, Haskell, PostScript, XPath
    / ROUND / FLOOR / CEILINGModula-3
    / rounded / floor / ceilingEiffel, Smalltalk
    int / / floor / ceilPerl
    int_of_float / / floor / ceilOCaml
    / / floor / ceilLua
    / Rounding / Floor / CeilingAda
    to-integer / / /Rebol

  • bitwise operators

    and / or / xor

    & / | / ^C, C#, C++, E, Eiffel, Java, JavaScript, Perl, Pike, Python, Ruby
    & / |YCP
    +& / +| / +^Perl6
    and / or / xorPostScript, Rebol
    land / lor / lxorOCaml
    logand / logior / logxor (83)Common Lisp
    BITAND / BITOR / BITXORClassic REXX

    negation

    ~C, C#, C++, Java, JavaScript, Perl, Pike, Python, Ruby, YCP
    notEiffel, PostScript
    lnotOCaml
    lognot (84)Common Lisp
    bitnotEiffel
    complementRebol

    left shift / right shift / unsigned right shift

    << / >> / >>>Java, JavaScript
    << / >>C, C#, C++, Perl, Pike, Python, Ruby, YCP
    |<< / |>>Eiffel
    lsl / lsr or asrOCaml
    bitshiftPostScript
    (ash x positive-integer) / (ash x negative-integer) /Common Lisp


Threads

  • thread definition

    task task_name is [entry entry_name[(parameter ...)]...] end task_nameAda
    task type task_type_name is [entry entry_name[(parameter ...)]...] end task_type_nameAda
    class class_name extends Thread {[override run method] }Java
    ... forkSmalltalk
    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 / terminateSmalltalk
    Tasks are started when created / call Stop entry or "abort task-object-name"Ada

  • passing data directly between threads

    call an entry with paramtersAda
    call any public methodJava
    common variables are copied at thread creation, in abscence of a "share" statementPliant

  • 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_NameAda
    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 terminationAda
    OtherThread.join();Java

    Suspending a Thread Until Another Thread Establishes An Internal State

    Call a task entry on the other threadAda

  • 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

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). }