syntax across languages (One Big Page) (original) (raw)
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/...?
This is of course incomplete. I welcome contributions!
You may also have a look at this information sorted by languages.
Light Version
Same content split into multiple html files
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
- manual memory allocation
- 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 (marshalling)
- unserialize (un-marshalling)
- 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
- all but the 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
- partition a list: elements matching, elements non matching
- split a list
- 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
- f(... f(f(init, e1), e2) ..., en)
- f(e1, f(e2, ... f(en, init) ...))
- 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
- euclidean division (both quotient and modulo)
- modulo
- truncate / round / floor / ceil
- bitwise operators
- Threads
Various
- commenting
until end of line
| # | Awk, BourneShell, CoffeeScript, E, FishShell, GNU-bc, GNU-sed, Icon, Io, Julia, Maple, merd, Perl, Perl6, PHP, Pliant, Python, Ruby, Tcl, YAML |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| // | BCPL, C#, C++, C99, Dylan, F#, Go, Io, Java, JavaScript, PHP, Pike, Scilab, YCP, Yorick |
| -- | Ada, Cecil, Eiffel, Haskell, Lua, Sather, Simula, SQL92 |
| ; | Assembler, Common Lisp, Emacs Lisp, Logo, MUMPS, Rebol, Scheme |
| % | Erlang, Matlab, Mercury, Oz, PostScript, Prolog, TeX |
| rem | Basic |
| ' | Visual Basic |
| " | Vimscript |
| \ | Forth |
| ! | Assembler, Fortran90 |
| NB. | J |
| C or * in column 1 | Fortran |
nestable
(* ... *) | Beta, F#, Mathematica, Modula-3, OCaml, Pascal, SML | |
---|---|---|
%( ... %) | Matlab | |
/* ... */ | Classic REXX, Dylan, Io, Oz, SQL99 | |
{ ... } | Pascal, Rebol | |
{- ... -} | Haskell | |
#| ... | #(1) | Common Lisp, Scheme |
#= ... =# | Julia | |
#[ ... ] | Perl6 | |
#if 0 ... #endif | C | |
comment { ... } | Rebol | |
comment [ ... ] | Rebol | |
[ ... ](2) | Rebol | |
--[[ ... ]] | Lua | |
non nestable | ||
" ... " | Smalltalk | |
------------ | --------------------------------------------------------------------------------------- | |
/* ... */ | B, C, C#, C++, CSS, GNU-bc, Go, Java, JavaScript, Mercury, PHP, Pike, PL/I, YCP, Yorick | |
HTML, XML | ||
( ... ) | Forth | |
### ... ### | CoffeeScript |
- documentation comment
until end of line/// C#, F#, Java -- | Haskell -- ^ Haskell non nestable /** ... */(3) C, C#, E, Java, JavaScript, PHP ---------------------- ------------------------------- (** ... *) F# {-| ... -} Haskell ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------- (** ... *) OCaml /* DOCUMENT ... */ Yorick indexing identifier: "..."; Eiffel someClass comment: '...' Smalltalk rebol [ Note: "..." ] Rebol func ["..." arg] ... Rebol class X: """... """ def x(): """... """ (4) Python (define (f para1 para2) "..." ...) Scheme (defun f (para1 para2) "..." ...) Common Lisp, Emacs Lisp =pod ... =cut(5) Perl, Perl6 =begin ... =end Ruby function MYFUNCTION %MYFUNCTION the very first comment line is displayed in the help table of contents % % the remaining lines are displayed when getting help for MYFUNCTION % Matlab - information about the current line and file
__LINE__ __FILE__ C, C++, Perl, PHP, Pike, Ruby __LINE__ __SOURCE_FILE__ F# ?LINE?LINE ?LINE?FILE Perl6 __file__ Python (new System.Diagnostics.StackFrame(true)).GetFileLineNumber() (new System.Diagnostics.StackFrame(true)).GetFileName() C# Thread.currentThread().getStackTrace()[1].getLineNumber(); Thread.currentThread().getStackTrace()[1].getFileName(); Java system/script/header/file(6) Rebol SOURCELINE() / parse source OS . SOURCENAME Classic REXX info frame 0 Tcl8.5 thisContext lineNumber / thisContext method source Smalltalk runtime.Caller(0) Go - tokens
case-sensitivity (keywords, variable identifiers...)case-sensitive Awk, B, BourneShell, C, C#, C++, CoffeeScript, F#, FishShell, Go, Haskell, Io, Java, JavaScript, Lua, Maple, Mathematica, Matlab, merd, Modula-3, OCaml, Perl, Perl6, Pike, Pliant, Prolog, Python, Ruby, Smalltalk, Tcl, XML, YAML, Yorick case-insensitive Ada, Assembler, Classic REXX, Common Lisp, CSS, Eiffel, Forth, HTML, Logo, Pascal, PL/I, Rebol, SGML, SQL92, Visual Basic case-sensitive: variablescase-insensitive: keywords, functions, constants... PHP case-sensitive: identifierscase-insensitive: keywords E case-sensitive: identifierscase-insensitive: commands MUMPS case-sensitive: upper case disallowed GNU-bc what is the standard way for scrunching together multiple words camelCase CoffeeScript, JavaScript ------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- CamelCase or camelCase C#, E, Go, Haskell, Io, Java, JavaScript, Mathematica, Pascal, Smalltalk, Tcl, Visual Basic underscores FishShell, GNU-bc, merd dots Logo hyphens Common Lisp, Emacs Lisp, Rebol, Scheme underscores for functions / types, unclear for modules / constructors OCaml UPPER_CASE BourneShell lowercasenoseparator Matlab underscores, UPPER_CASE for class names Eiffel CamelCase for classes, underscores for methods Python CamelCase for types, underscores for functions, variables, ... Pliant CamelCase for methods, types and modules, underscore for functions F# CamelCase for modules and classes, ALL_CAPS for constants, underscores for functions, variables, ... Ruby CamelCase for modules and classes, ALLCAPS for macros, underscores for methods, constants and variables Pike CamelCase for modules, ALL_CAPS for constants, unclear for functions / variables Perl, Perl6 CamelCase for variables, underscores for predicates Prolog usually lowercase or underscores, ALL_CAPS for macros C usually underscores C++ Camel_Case Ada variable identifier regexp [a-zA-Z][a-zA-Z0-9]* FishShell, Mathematica, PL/I, Smalltalk ---------------------------------------------------------------------------------------------------------- -------------------------------------------------- [a-zA-Z][_a-zA-Z0-9]* Eiffel, Matlab, Vimscript [a-zA-Z](_?[a-zA-Z0-9])* Ada [_a-zA-Z][_a-zA-Z0-9]* Awk, B, C, C#, C++, E, Go, Maple, PHP, Python, Tcl [_a-zA-Z0-9]+ BourneShell, Perl, Perl6 [a-zA-Z0-9]+ FishShell [_a-zA-Z][_a-zA-Z0-9]* or '[^']*' Pliant [_a-zA-Z$][_a-zA-Z0-9$]* Java [$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]* CoffeeScript, JavaScript [a-zA-Z%][a-zA-Z0-9]* MUMPS [_a-z][_a-zA-Z0-9]* Ruby [_a-z][_a-zA-Z0-9]*[!?']* merd [_a-z][_a-zA-Z0-9']* Haskell, OCaml, SML [_a-zA-Z][_a-zA-Z0-9']* F# [_A-Z][_a-zA-Z0-9]* Mercury, Prolog [_a-zA-Z!0&*/:<=>?^][_a-zA-Z!0&*/:<=>?^0-9.+-]* Scheme [a-zA-Z!?@#][a-zA-Z0-9!?@#]* Classic REXX [_a-zA-Z?!.'+*&|=~-][_a-zA-Z0-9?!.'+*& =~-]* or [^0-9[](){}":;/][^ \n\t[](){}":;/]* [a-z][a-z0-9_]* GNU-bc anything without a space and is not a number Common Lisp, 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 [A-Z][_a-zA-Z0-9]*(7) Vimscript [^ \t\n\r\f]+ Tcl [^ \t\n\r\f/]+ FishShell keyword regexp (if different from variable identifier regexp) 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, D, Eiffel, Emacs Lisp, F#, Forth, Go, Haskell, Java, JavaScript, Maple, Mathematica, OCaml, Oz, Pascal, Perl, Perl6, PHP, PostScript, Rebol, Scheme, Smalltalk, SML, XSLT, YCP \ Awk, BourneShell, C, CoffeeScript, E, FishShell, GNU-bc, Io, Python, Ruby, Tcl _ Visual Basic , Classic REXX ~ Logo ... Matlab - variable assignment or declaration
assignment= Awk, B, Basic, BourneShell, C, C#, C++, Classic REXX, Erlang, Go, Icon, Io, Java, JavaScript, Lua, Mathematica, Matlab, Oz, Perl, Perl6, PHP, Pike, YCP, Yorick := Ada, BCPL, Cecil, Dylan, E, Eiffel, Maple, Mathematica, Modula-3, Pascal, Pliant, Sather, Simula, Smalltalk, SML <- F#, OCaml _(8) Squeak : BCPL, Rebol ->(9) Beta def PostScript setq Common Lisp, Emacs Lisp setf Common Lisp set Common Lisp, FishShell, Rebol SET v=... MUMPS set! Scheme is Prolog make "v e Logo e v ! Forth declaration = Haskell, Mercury, Prolog ---------------------------------------------------------- ------------------------ <- Haskell :- Prolog := Io let v = e in F#, OCaml let val v = e in SML let v = e(10) BCPL, F#, Vimscript def v := e / var v := e E my / our / local / use vars Perl my / our / temp Perl6 define Dylan, Scheme let let* Common Lisp, Scheme letrec Scheme flet labels defun defmethod defvar defparameter defsetf .. Common Lisp local V1 = e V2 = e2 in ... end Oz global v1, v2 Python global v1 v2 Matlab, Scilab :@ Beta NEW v MUMPS v: t Ada, Eiffel, Pascal t v C, C#, C++, Java var v t Go | v1 v2 auto v1, v2; extrn v3, v4; B auto GNU-bc var JavaScript, Pliant gvar Pliant variable v(11) Forth e value v Forth Module[{x, y = v}, ... ] Mathematica Block[{x, y = v}, ... ] Mathematica With[{c1 = v1, c2 = v2, ... }, ...] Mathematica <xsl:variable name="v" select="e"/> XSLT both = CoffeeScript, GNU-bc, merd, Python, Ruby ------------- ---------------------------------------- := Go, merd set, variable Tcl - grouping expressions
( ... ) Ada, Awk, B, BCPL, Beta, C, C#, C++, Classic REXX, CoffeeScript, D, E, Eiffel, F#, GNU-bc, Go, Haskell, Io, Java, JavaScript, Julia, Logo, Lua, Maple, Mathematica, Matlab, merd, Modula-3, MSH, MUMPS, OCaml, Oz, Pascal, Perl, Perl6, PHP, Pike, Pliant, Prolog, Python, Rebol, Ruby, Scilab, Smalltalk, SML, SQL92, Tcl, Vimscript, XPath, YCP, Yorick [ ... ] Rebol indentation merd $ ... Haskell begin ... end F#, FishShell, OCaml, Ruby space(12) merd - block (grouping statements, especially when statements are not expressions)
{ ... } Awk, BCPL, BourneShell, GNU-bc, GNU-sed, JavaScript, PHP, Pike, Tcl, Yorick { ... }(13) B, C, C#, C++, E, Go, Haskell, Java, Modula-3, Perl, Perl6, YCP ( ... )(13) BourneShell [ ... ](14) Logo, Smalltalk "..." Tcl begin ... end(13) Ada, Pascal (begin ...) Scheme BEGIN ... END Modula-3 do ... end Classic REXX do ... end(13) Lua, PL/I indentation CoffeeScript, F#, MUMPS, Pliant, Python indentation(13) Haskell, merd foo ... end where foo in { if, do, ... } Modula-2, Ruby foo ... end where foo in { if, for, while, ... } Matlab, Scilab foo ... end where foo in { if, loop, ... } Eiffel foo ... end foo where foo in { if, do, ... } Ada, Fortran90 (* ... *)(15) BCPL (# ... #) Beta - use a block as a return value (when statements are not expressions)
valof BCPL do Perl, Perl6 proc() .. end proc Maple - equality / inequality
shallow== != Awk, B, C, C++, CoffeeScript, F#, Go, Io, Java, OCaml, Perl, Perl6, Pike, Yorick = /= Eiffel, Fortran90 = <> Forth, Logo, Maple, Modula-2, Pliant, Rebol = #(16) Modula-2, Modula-3 = != BourneShell, FishShell == === != !==(17) JavaScript, PHP === !== Perl6, PHP5 == ~= Lua == ~~ Smalltalk == ~== Dylan = '= MUMPS = ~= neqv(15) BCPL f= f<> Forth is_equal(18) Eiffel eq ne Emacs Lisp, PostScript eq, eql Common Lisp eq? eqv? Scheme .EQ. .NE. Fortran is / is not Python is / isnot Vimscript deep == != Awk, C#, C++, E, merd, PHP5, Python, Ruby, Tcl, Vimscript, YCP ------------------------------------------ -------------------------------------------------------------- == <> Python == /= Haskell == \= Oz == \== Classic REXX, Prolog = /= Ada = != Maple, XPath = <> Beta, F#, OCaml, Pascal, Rebol, SML, SQL92, Visual Basic = ~= Dylan, Smalltalk == ~= eq ne isequal isequalwithequalnans Matlab == ~= eq ne isequal Scilab =@= \=@= / = \= / =:= =\=(19) Prolog === =!= / == !=(20) Mathematica .eq Logo equal? Scheme equals Java equal Common Lisp, Emacs Lisp, Pike equalp Common Lisp eqv Perl6 deep_is_equal Eiffel isEqual Objective-C - comparison
< > <= >= Ada, Awk, Awk, B, Beta, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, Dylan, E, Eiffel, Emacs Lisp, F#, Forth, Go, Haskell, Io, Java, JavaScript, Logo, Lua, Maple, Mathematica, Matlab, merd, Modula-3, OCaml, Pascal, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, Scheme, Scilab, Smalltalk, SML, SQL92, Tcl, Vimscript, Visual Basic, XPath, YCP, Yorick < > =< >= Mercury, Oz < > '> '< MUMPS << >> <<= >>=(21) Classic REXX @< / @=< / @> / @>= Prolog lt gt le ge Perl, Perl6, PostScript -lt -gt -le -ge BourneShell, FishShell, MSH .LT. .GT. .LE. .GE. Fortran u< u> u<= u>= Forth f< f> Forth returns 3 values (i.e. inferior, equal or superior) a <=> b merd, Perl, Perl6, Ruby ---------------------- ------------------------------------------------------------- cmp Perl, Perl6, Python compare F#, Forth, Haskell, Mercury, OCaml, Pliant, Prolog, Smalltalk strcmp C, PHP three_way_comparison Eiffel string compare Tcl compareTo Java strings.Compare() Go returns 4 values (i.e. inferior, equal, superior or not comparable) min / max (binary or more) min / max Beta, C++, Common Lisp, Dylan, E, Eiffel, F#, Forth, Haskell, Io, Java, Lua, Maple, Matlab, merd, OCaml, PHP5, Pike, Pliant, Prolog, Python, Rebol, Scheme, Scilab, Smalltalk, SQL92, Tcl8.5, Yorick ----------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- min minstr / max maxstr(22) Perl Min / Max Mathematica, Oz MIN / MAX Classic REXX, Modula-3 measure-object -min / measure-object -max MSH fmin / fmax Forth Integer'min / Integer'max Ada - runtime evaluation
eval BourneShell, Common Lisp, Emacs Lisp, FishShell, JavaScript, Matlab, Perl, Perl6, PHP, Python, Ruby, Scheme, Tcl, YCP CoffeeScript.eval(23) CoffeeScript exec Python evstr / execstr Scilab dostring Lua doString Io evaluate Forth Compiler evaluate: Smalltalk runtime_compile / compile + execute Pliant Compiler.evalExpression or Compiler.parseOzVirtualString Oz compile_string Pike interpret Classic REXX ToExpression Mathematica run Logo XECUTE MUMPS do / reduce / compose / load Rebol [...] Tcl =..(24) Prolog - manual memory allocation
allocationmalloc C allocate throw Forth new Ada deallocation - force garbage collection
doGC Beta GC.start Ruby gc Logo, Maple, Pike System.gc() Java System.gcDo Oz System.GC.Collect() C#, F# gc.collect() Python gc_collect_cycles(25) PHP5 full_collect Eiffel garbage_collect Mercury, Prolog collectgarbage Lua Collector collect Io VM.garbageCollect() JavaScript Gc.full_major() OCaml Smalltalk garbageCollect Smalltalk System.Mem.performGC Haskell incremental garbage collection => not needed Perl, Perl6 recycle Rebol interp.gc() E (ext:gc) Common Lisp runtime.GC() Go
Functions
- function call
f(a,b,...) Ada, Awk, Awk, B, C, C#, C++, CoffeeScript, CSS, Dylan, E, Eiffel, Erlang, Go, Io, Java, JavaScript, Lua, Maple, Matlab, Mercury, merd, Modula-3, Pascal, Perl, Perl6, PHP, Pike, Prolog, Python, Ruby, XPath, YCP, Yorick f a b ... BourneShell, F#, FishShell, Haskell, Logo, Matlab, MSH, OCaml, Pliant, Rebol, SML, Tcl f(a,b,...f) or f[a,b,...] depending on the version BCPL (f a b ...) (apply f l) Common Lisp, Emacs Lisp, Scheme (funcall f a b ...) Common Lisp, Emacs Lisp {f a b} Oz [apply f a b] Tcl8.5 f[a,b,...] Mathematica f[a,b,...] or f.call(a,b,...) Ruby &$f(a,b,...) or $f->(a,b,...) Perl $f.(a,b,...) Perl6 f a, b, ... CoffeeScript, Perl f, a, b, ...(26) Yorick v = f(a, b, ...) or call f a, b, ... Classic REXX a b ... f Forth, PostScript (a,b,...)->&f; or (a,b,...)->f Beta f:a(27) FL f@a(28) Mathematica a // f(28) Mathematica a ~ f ~ b(29) Mathematica .. [ f, A, B, ...] Prolog <xsl:call-template name="f"> <xsl:with-param name="a" select=a/> <xsl:with-param name="b" select=b/> XSLT with no parameter f Ada, BourneShell, Eiffel, Forth, Haskell, Io, Logo, Matlab, Mercury, MSH, Pascal, Perl, Perl6, Pliant, PostScript, Prolog, Rebol, Ruby, Tcl, Yorick ----------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------- f() Awk, C, C#, C++, CoffeeScript, E, Erlang, F#, Go, Java, JavaScript, Lua, Maple, merd, OCaml, Perl, PHP, Pike, Python, SML, YCP (f) Common Lisp, Emacs Lisp, Scheme (funcall f) Common Lisp, Emacs Lisp {f} Oz f[] Mathematica f[] or f.call Ruby &$f or $f->() Perl $f.() Perl6 v = f() Classic REXX call f Classic REXX, Fortran f value(30) Smalltalk <xsl:call-template name="f">/ XSLT - partial application (in the examples below, a normal call is "f(a,b)")
give the first argumentf a F#, Haskell, OCaml, SML f(a) Mercury f(a,) merd &f.assuming;(var_name => a) Perl6 functools.partial(f, a)(31) Python interp alias {} f_a {} f a Tcl give the second argument f(,b) merd -------------------- ------- &f.assuming;(b => b) Perl6 flip f b(32) Haskell give the first argument to operator ">" (a >) Haskell, merd ----- ------------- (>) a F#, OCaml give the second argument to operator ">" - function definition
sub f { ... } Perl, Perl6 sub f($para1, $para2, ...) { ... } Perl6 def f(para1, para2, ...): ... Python def f(para1, para2, ...) ... end Ruby def f(para1, para2, ...) ... { ... } E f para1 para2 = ... Haskell let f para1 para2 = ... F#, OCaml f(para1, para2, ...) = valof (...( ... (...) BCPL f(para1, para2, ...) = ... merd f[para1_, para2_, ...] := ... para1 ... Mathematica f ... or f: para1 ... Smalltalk f: func [para1 para2 ...] ... Rebol /f { ... } def PostScript f := (para1, para2, ...) -> ... Maple f := method(para1, para2, ..., code) Io func f(a, b, c...) { ... } Yorick typ0 f(typ1 para1, typ2 para2, ...) { ... } C, C#, C++, Pike, YCP function f(para1, para2) { ... } Awk, JavaScript, PHP5 function f(para1, para2) ... code ... end Lua function f; ...; end FishShell function f { ... } KornShell function f { param(para1, [typ2]para2, ...) ... } MSH (define (f para1 para2) ...) Scheme (defun f (para1 para2) ...) Common Lisp, Emacs Lisp fun { F Para1 Para2 } ... end Oz fun f para1 para2 = ... SML proc f {para1 para2} { ... } Tcl function retval = f(para1, para2) retval = ... Matlab, Scilab :- func f(typ1, typ2, ...) = typ0. f(Para1, Para2, ...) = ... Mercury function f(para1 : type1; para2 : typ2; ...) return retval is begin ... end f; Ada function f para1 para2 -> retval arg typ1 para1; arg typ2 para2; arg rettyp retval; ... Pliant function f(para1 : typ1, para2 : typ2, ...) : retval; var retval : typ0; begin ... end Pascal f (para1 : typ1; para2, para3 : typ2; ...) : rettyp is do ... end Eiffel <xsl:template name="f"> <xsl:param name="para1"/> <xsl:param name="para2"/> ... XSLT Function f(para1, para2) ... End Function Visual Basic : f ... ; Forth f() { ... } BourneShell, KornShell f : procedure ... return retval Classic REXX to f :para1 :para2 ... end Logo func f(para1 typ1, para2 typ2, ...) (typ3, ...) { ... } Go procedures procedure f(para1 : typ1; para2, para3 : typ2); begin ... end Pascal ----------------------------------------------------------------------------------------- ---------------- f (para1 : typ1; para2, para3 : typ2; ...) is do ... end Eiffel procedure f(para1 : typ1; para2 : MODE type2; ...) is begin ... end f; MODE ::= | OUT IN OUT void f(typ1 para1, typ2 para2, ...) { ... } C, C#, C++, Pike let f(para1, para2, ...) be (...( ... (...) BCPL proc { F Para1 Para2 } ... end Oz f := proc(para1, para2, ...) ... end proc Maple Sub f(para1, para2) ... End Sub Visual Basic function f(para1, para2) ... Matlab, Scilab f : procedure ... return Classic REXX func f(para1 typ1, para2 typ2, ...) { ... } Go variable number of arguments one can use overloading on different number of arguments C++, Java --------------------------------------------------------- ------------ sub f { ... @_ } Perl sub f; ... $argv; end FishShell f() { ... $@ } BourneShell f := ... ## & Mathematica f[params___] := ... params ... Mathematica function f(varargin) for i=1:nargin ...(varargin{i}) end Matlab function f(varargin) for e=varargin ...(e) end Scilab (args...) -> ... CoffeeScript (lambda x ...) or(33) Scheme f(args ...typ0)(34) Go predicates f(Para1, Para2, ....) :- ... . Prolog ------------------------------ ------ - anonymous function
sub { my ($a, $b) = @_; ... } Perl { my ($a, $b) = @_; ... }(35) Perl { ... } (arguments are in the stack PostScript [ ... ] Logo { param(para1, [typ2]para2, ...) ... } MSH {|a, b ... }(36) [:a :b| ... ] Smalltalk [list {a b} {...}] Tcl8.5 lambda a, b: ... Python lambda(typ1 para1, typ2, para2, ...) { ... }; Pike (a, b) => ... C#3, CoffeeScript (a, b) -> ... CoffeeScript, Maple a, b -> ... merd -> a,a, a,b { ... } Perl6 \a b -> ... Haskell :noname ... Forth fn (a, b) => ... SML fun a b -> ... F#, OCaml (func(A, B) = C :- ...) Mercury function(a, b) { ... } JavaScript, PHP5 function(a, b) use (&$v1, $v2) { ... }(37) PHP5 function(a, b) ... end Lua Function[{a, b}, ....](38) Mathematica fun(a, b) -> ... end Erlang fun {$ A B} ... end(39) Oz func [a b ...] ... Rebol def _(para1, para2, ...) ... { ... } E proc {|a, b ...} lambda {|a, b ...} (lambda (a b) ...) Common Lisp, Emacs Lisp, Scheme inline('...x...y...')(40) Matlab method(a, b, ...) Io method(a, b) ... end method(41) Dylan create_function(',','...') PHP delegate(ta a, tb b) { ... } C#2 [](ta a, tb b) { ... } C++-0x [](ta a, tb b) -> typ { ... } C++-0x func(para1 typ1, ...) (typ2, ...) { ... } Go - function return value
breaks the control flowreturn(42) Ada, Awk, B, BCPL, BourneShell, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, E, FishShell, Go, Io, Java, JavaScript, Lua, Maple, Matlab, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, Tcl, Vimscript, YCP, Yorick Return Mathematica, Visual Basic RETURN Modula-3 resultis(43) BCPL return-from xxx Common Lisp ^ Smalltalk Exit Function / Exit Sub Visual Basic exit Forth output Logo function body is the result no syntax needed(44) CoffeeScript, Common Lisp, Dylan, Emacs Lisp, Erlang, F#, Haskell, Io, Maple, Mathematica, Matlab, OCaml, Oz, Perl, Perl6, Rebol, Ruby, Scheme, SML, Tcl --------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------- setting the result Result := val Eiffel ---------------------- ------------ = val Visual Basic := val Pascal = val; Ada, Matlab - function called when a function is not defined (in dynamic languages)
AUTOLOAD Perl AUTOSCALAR, AUTOMETH, AUTOLOAD... Perl6 __autoload PHP5 __getattr__ Python method_missing Ruby doesNotUnderstand Smalltalk __noSuchMethod__(45) CoffeeScript, JavaScript unknown Tcl no-applicable-method Common Lisp doesNotRecognizeSelector Objective-C TryInvokeMember(46) C# match [name, args] { ... } E the predicate fail Prolog forward Io - runtime inspecting the caller information
caller Perl, Perl6, Ruby call Io inspect.stack()[1] Python backtrace Pike debug_backtrace PHP5 trace 'I' Classic REXX evalin('caller', ...) Matlab current_predicate Prolog thisContext sender Smalltalk where(2) Maple info level Tcl runtime.Caller(0) Go - function composition
. Haskell ~ merd o SML @ Maple compose Dylan Composition Mathematica << F# >> F# - identity function
id Haskell identity Common Lisp Identity Mathematica yourself Smalltalk
Control Flow
- sequence
, C, C++, Go, JavaScript, Matlab, Perl, Pike, Prolog, Scilab . Smalltalk ; Ada, Awk, B, Beta, BourneShell, C, C#, C++, E, F#, FishShell, GNU-sed, Go, Haskell, Io, Java, JavaScript, Maple, Mathematica, Matlab, merd, Modula-3, OCaml, Pascal, Perl, Perl6, PHP, Pike, PL/I, Pliant, Python, Ruby, SML, Tcl, YCP : Maple nothing, optionally ; Classic REXX, Lua space Eiffel, Rebol end-of-line Assembler, Awk, Basic, BourneShell, CoffeeScript, E, F#, FishShell, Fortran, GNU-sed, Haskell, Io, JavaScript, Lua, Matlab, merd, Pliant, Python, Ruby, Tcl (begin ...) Scheme (progn ...) (prog1 ...) (prog2 ...) Common Lisp, Emacs Lisp >> Haskell - if_then
if c then ... CoffeeScript, F#, merd, OCaml, Pascal, Tcl if c then ... end Eiffel, Lua, Oz, Ruby if c then ... end if Ada, Maple if c then ... fi Maple if c; then ... fi BourneShell if (c) then ... end Dylan if c do ... BCPL IF c THEN ... END Modula-2, Modula-3 if (c) ... Awk, B, C, C#, C++, Java, JavaScript, PHP, Pike, YCP if c: ... Python if c ... Pliant, Rebol, Tcl if (c): ... endif PHP if c {...} Go, Perl6 if c [...] Logo if (c) {...} E, Perl, Yorick IF c ... MUMPS c -> ... FL c ... if PostScript ... if c Perl, Ruby c if b1 then Forth (if c ...) Common Lisp, Scheme (when c ...) Emacs Lisp c and ... Perl, Ruby if(c, ...) Io If[c, ...] Mathematica if(c) then(...) Io c ifTrue(...) Io c ifTrue: ... Smalltalk <xsl:if test="c">... XSLT if c ... endif Vimscript If c Then ... Visual Basic If c ... End If Visual Basic if c; ... end Ruby if c; ...; end FishShell if c, ..., end Matlab if c ... end Matlab, Ruby if c then ; ... if c then ... if c then do ... end Classic REXX c and ... Perl t label GNU-sed if c ... CoffeeScript - if_then_else
if c then b1 else b2 CoffeeScript, F#, Haskell, merd, OCaml, SML if c then b1 else b2 end Eiffel, Lua, Ruby if c then b1 elsif c2 then b2 else b3 end if Ada if c then b1 elseif c2 then b2 else b3 end Eiffel, Oz if (c) then b1 elseif (c2) then b2 else b3 end Dylan IF c THEN b1 ELSIF c2 THEN b2 ELSE b3 END Modula-3 If c Then b1 ElseIf c2 Then b2 Else b3 End If Modula-2 if (c) b1 else b2 Awk, B, C, C#, C++, Java, JavaScript, Pike, YCP if c b1 elsif c2 b2 b3 Tcl if c then b1 elseif c2 then b2 else b3 Tcl if c then begin b1 end else begin b2 end Pascal if c b1 eif c2 b2 else b3 Pliant if c then b1 elif c2 then b2 else b3 end if Maple if c; then b1; elif c2; then b2; else b3; fi BourneShell if c; b1; else b2; end FishShell if c1, b1, elseif c2, b2, else, b3, end Matlab if (c) b1 elseif (c2) b2 else b3 PHP if (c): b1 elseif (c2): b2 else: b3 endif PHP if (c) {b1} elsif (c2) {b2} else {b3} Perl if (c) {b1} else {b2} E, Yorick (if c b1 b2) Common Lisp, Scheme (if c then b1 else b2) Mercury (c -> b1 ; c2 -> b2 ; b3) Mercury c -> b1 ; b2 FL if(c, b1, b2) Io If[c, b1, b2] Mathematica if(c) then(b1) else(b2) Io c ifTrue: b1 ifFalse: b2 Smalltalk ifelse c [b1] [b2] Logo shunt c b1 c2 b2 b3 Pliant either c b1 b2 / if/else c b1 b2 Rebol (cond (c b1) (c2 b2) (t b3)) Common Lisp, Emacs Lisp (cond (c b1) (c2 b2) (else b3)) Scheme Which[c, b1, c2, b2, True, b3] Mathematica c -> b1 ; c2 -> b2 ; b3 Prolog case when c; b1 when c2; b2 else b3 end Ruby test c then b1 or b2 BCPL e | c = b1 c2 = b2 otherwise = b3(47) Haskell c b1 b2 ifelse PostScript c if b1 else b2 then Forth c ? b1 : b2 Awk, B, C, C#, C++, Java, JavaScript, Perl, PHP, Ruby, Tcl, YCP, Yorick c ?? b1 !! b2 Perl6 b1 if c else b2(31) Python $SELECT(c:b1,c2:b2,1:b3) MUMPS c -> b1, b2 BCPL (if c then b1 else b2 fi) Beta xsl:choose <xsl:when test="c"> b1 <xsl:when test="c2"> b2 xsl:otherwise b3 XSLT if c1 ... elseif c2 ... else ... endif Vimscript If c Then b1 Else b2 Visual Basic If c b1 Else b2 End If Visual Basic if c: b1 elif c2: b2 else: b3 Python if c b1 elsif c2 b2 else b3 end Ruby if c b1 elseif c2 b2 else b3 end Matlab if c then ; b1 ; else ; b2 if c then b1 else b2 if c then do b1 ... end else do b2 ... end Classic REXX IF c ... ELSE ... MUMPS if c b1 else if c2 b2 else b3 CoffeeScript if c {b1} else if c2 {b2} else {b3} Go - ifnot_then (unless)
unless CoffeeScript, Emacs Lisp, Perl ifFalse Smalltalk if(c) not then(...) Io - multiple selection (switch)
switch (val) { case v1: ...; break; case v2: case v3: ...; break; default: ...; } C, C++, Java, JavaScript, PHP, Pike switch val { case v1: ...; goto done; case v2: case v3: ...; goto done; } ...; done: B switch (val) { case v1: ...; break; case v2: case v3: ...; break; default: ...; break; }(48) C# switch (val) { match v1 { ... } match v2 { ... } match _ { ... } } E switchon val case v1: ... case v2: ... default: ... BCPL switch val case v1 ... case v2 v3 ... case '*' ... end FishShell switch val case v1 ... case {v2,v3} ... otherwise ... end Matlab case val of v1 : ...; v2, v3 : ... else ... end Pascal switch val { v1 {...} v2 - v3 {...} default {...} } Tcl case val in v1) statement1 ;; v2|v3) statement23 ;; *) statement_else ;; esac BourneShell (if val // v1 then ... // v2 then ... else ... if) Beta match val with | v1 -> ... v2 v3 -> ... _ -> ... F#, OCaml case val of v1 => ... | v2 => ... _ => ... SML CASE val OF v1 => ... | v2 => ... ELSE => ... END Modula-3 case val of v1 -> ... v2 -> ... _ -> ... Haskell val case v1 of ... endof v2 of ... endof ... endcase Forth val. v1 -> ... v2 -> ... _ -> ... merd (case val ((v1) ...) ((v2) ...) (otherwise ...)) Common Lisp (case val ((v1) ...) ((v2) ...) (else ...)) Scheme case val is when v1 => ... when v2 | v3 => ... when others => ... end case; Ada case val when v1; ... when v2, v3; ... else ... end Ruby inspect val when v1 then statement1 when v2, v3 => statement23 else statement_else end Eiffel select (val); when (v1) statement1; when (v2, v3) statement23; otherwise statement_else; end; PL/I X = val, (X = v1, ... ; X = v2, ... ; ...) Mercury, Prolog my %case = ( v1 => sub { ... }, v2 => sub { ... }, ); if ($case{val}) { $case{val}->() } else { ... } Perl use Switch; switch ($val) { case v1 { ... } case v2 { ... } else ... })(49) Perl given $val { when v1 { ... } when v2 { ... } default { ... } } Perl6 Select val Case v1 ... Case v2, v3 ... Case Else ... End Select Visual Basic switch (val) { v1 { ... } v2 { ... } default { ... } } MSH switch val [ v1 [...] v2 [...] ] switch/default [ v1 [...] v2 [...] ][...] Rebol val caseOf: {[v1]->[...]. [v2]->[...]} otherwise: ... Squeak Switch[val, v1, ..., v2, ..., _, ...] Mathematica select when v1 ... when v2 | v3 ... otherwise ... end Classic REXX CASE val WHEN v1 THEN ... WHEN v2 THEN ... ELSE ... END SQL92 switch val { case v1, v2, ...: ... fallthrough case v3: ... default: ... } Go - loop
forever looploop CoffeeScript, merd, Perl6, PostScript, Ruby loop(...) Io loop ... end loop Ada LOOP ... END Modula-3 (loop do ...) Common Lisp cycle (# do ... #) Beta repeat Squeak begin ... again Forth forever Logo, Rebol Do ... Loop Visual Basic do forever ... end Classic REXX for {} Go while condition do something while (c) ... Awk, B, C, C#, C++, E, Java, JavaScript, Perl, PHP, Pike, Ruby, YCP, Yorick ----------------------------------------------- --------------------------------------------------------------------------- while c ... CoffeeScript, Perl6, Tcl while c loop ... end loop Ada while c do ... BCPL, Pascal, SML while c do ... done F#, OCaml while c do ... end do Maple while c do ... end Lua WHILE c DO ... END Modula-3 while c: ... Python while c; do ...; done BourneShell while c; ...; end FishShell while c, ..., end Matlab while [c][...] Rebol while c [...] Logo while(c, ...) Io While[c, ...] Mathematica do.while [...] c Logo c whileTrue: ... Smalltalk (loop while c do ...) Common Lisp loop (# while ::< (# do c -> value #) do ... #) Beta begin c while ... repeat Forth from until not c loop ... end Eiffel while c ... Pliant while c do ... F# Do While c ... Loop Visual Basic while c ... endwhile Vimscript do while c ... end Classic REXX for c {...} Go do something until condition do ... until c Perl6 ----------------------------------------------- ----------------------------------------------- do {...} until c Perl do ... while (!c) Awk, C, C#, C++, Java, JavaScript, Pike, Yorick begin ... end until c Ruby begin ... c until Forth REPEAT ... UNTIL c Modula-3 loop (# until ::< (# do c -> value #) do ... #) Beta loop ... exit when c; end loop Ada (loop do ... until c) Common Lisp ... repeatuntil c BCPL repeat ... until c Lua, Pascal repeat ... until (c) YCP repeat, ..., c Prolog until [... c] Rebol until c [...] Logo do.while [...] c Logo While[...; c] Mathematica [...] whileFalse: [c] Smalltalk Do ... Loop Until c Visual Basic for each value in a numeric range, 1 increment (see also the entries about ranges) for (int i = 1; i <= 10; i++) ... C, C#, C++ --------------------------------------- --------------- for (i = 1; i <= 10; i++) ... Awk, JavaScript for ($i = 1; i<=10;i <= 10; i<=10;i++) ... PHP foreach my $i (1 .. 10) { ... } Perl foreach ($i in 1..10) { ... } MSH for (1 .. 10) -> $i { ... } Perl6 for i = 1:10, ..., end Matlab for i = 1, 10 do ... end Lua for i := 1 to 10 do ... Pascal for i = 1 to 10 do ... done F#, OCaml For i = 1 To 10 ... Next Visual Basic for i in 1 .. 10 loop ... end loop Ada for i in 1 .. 10 do ... done F# for i in [1..10] ... CoffeeScript for i in xrange(1, 11) Python for i in (seq 10); ...; end FishShell FOR I=1:1:10 ... MUMPS for i from 1 to 10 do ... end do Maple for [i 1 10 +1] [...] Logo for {set i 1} {$i <= 10} {incr i} {...} Tcl 1 1 10 ... for PostScript 11 1 do ... loop Forth (1..10).each {|i ... } 1.upto(10) {|i ... } 1 to(10) foreach(...) Io 1 to: 10 do: [...] Smalltalk (loop for i from 1 to 10 do ...) Common Lisp do label i = 1, 10 Fortran Do[..., {i, 1, 10}](50) Mathematica do i = 1 for 10 ... end Classic REXX for i := 1; i <= 10; i++ {...} Go for each value in a numeric range, 1 decrement for X := 10 downto 1 do ... Pascal ------------------------------------------------ --------------- for i = 10 downto 1 do ... done F#, OCaml for i in reverse 1 .. 10 loop ... end loop Ada for i in 10 .. -1 .. 1 do ... done F# for (int i = 10; i >= 1; i--) ... C, C#, C++ for (my i=10;i = 10; i=10;i >= 1; $i--) { ... } Perl loop (my i=10;i = 10; i=10;i >= 1; $i--) { ... } Perl6 for (i = 10; i >= 1; i--) ... Awk, JavaScript for ($i = 10; i>=1;i >= 1; i>=1;i--) ... PHP from i := 10 until i < 1 loop ... i := i - 1 end Eiffel for i = 10:-1:1, ..., end Matlab for i = 10, 1, -1 do ... end Lua For i = 10 To 1 Step -1 ... Next Visual Basic for i in xrange(10, 0, -1) Python for i in `seq 10 -1 1`; do ...; done BourneShell for i in (seq 10 -1 1); ...; end FishShell for i from 10 to 1 by -1 do ... end do Maple for [i 1 10 -1] [...] Logo FOR I=10:-1:1 ... MUMPS for {set i 10} {$i >= 1} {incr i -1} {...} Tcl 10 -1 1 ... for PostScript 1 10 do ... -1 +loop Forth 1 to: 10 by: -1 do: [...] Smalltalk 10 to(1) foreach(...) Io 10.downto(1) {|i ... } (loop for i from 1 to 10 by -1 do ...) Common Lisp do label i = 10, 1, -1 Fortran Do[..., {i, 10, 1, -1}] Mathematica do i = 10 to 1 by -1 ... end Classic REXX for i in [10..1] ... CoffeeScript for i := 10; i >= 1; i-- {...} Go for each value in a numeric range, free increment for (int i = 1; i <= 10; i += 2) ... C, C#, C++, Pike ------------------------------------------------ ---------------- for (i = 1; i <= 10; i += 2) ... Awk, JavaScript for ($i = 1; i<=10;i <= 10; i<=10;i += 2) ... PHP for (my i=1;i = 1; i=1;i <= 10; $i += 2) { ... } Perl loop (my i=1;i = 1; i=1;i <= 10; $i += 2) { ... } Perl6 from i := 1 until i > 10 loop ... i := i + 2 end Eiffel for i = 1:3:10, ..., end Matlab for i = 1, 10, 2 do ... end Lua For i = 1 To 10 Step 2 ... Next Visual Basic for i in 1 .. 2 .. 10 do ... done F# for i in xrange(1, 11, 2) Python for i in (seq 1 2 10); ...; end FishShell for i from 1 to 10 by 2 do ... end do Maple for [i 1 10 2] [...] Logo FOR I=1:2:10 ... MUMPS for {set i 0} {$i <= 10} {incr i 2} {...} Tcl 1 2 10 ... for PostScript 11 1 do ... 2 +loop Forth 1 to: 10 by: 2 do: [...] Smalltalk (1..10).step(2) {|i ... } 1 to (9,2) foreach(...) Io (loop for i from 1 to 10 by 2 do ...) Common Lisp do label i = 1, 10, 2 Fortran Do[..., {i, 1, 10, 2}] Mathematica do i = 1 to 10 by 2 ... end Classic REXX for i in [1..10] by 2 ... CoffeeScript for i := 1; i <= 10; i += 2 {...} Go for "a la C" (while + initialisation) for Awk, C, C#, C++, Go, Java, JavaScript, Mathematica, MSH, Perl, PHP, Pike, Tcl, Yorick ------------------------------------------------------------------------- ------------------------------------------------------------------------------------- loop Perl6 for ((x = 0; x < 10; x++)); do ...; done BourneShell from init_code until c loop ... incr_statement end Eiffel (loop with VAR = INITIAL-VALUE ... while CONDITION finally INCREMENT ...) Common Lisp - breaking control flow
returning a valuereturn(42) Ada, Awk, B, BCPL, BourneShell, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, E, FishShell, Go, Io, Java, JavaScript, Lua, Maple, Matlab, Perl, Perl6, PHP, Pike, Pliant, Python, Rebol, Ruby, Tcl, Vimscript, YCP, Yorick Return Mathematica, Visual Basic RETURN Modula-3 resultis(43) BCPL return-from xxx Common Lisp ^ Smalltalk Exit Function / Exit Sub Visual Basic exit Forth output Logo goto (unconditional jump) goto Ada, B, Basic, BCPL, C, C#, C++, Cobol, Fortran, Go, Logo, MUMPS, Pascal, Perl, PHP5, Yorick ----------- -------------------------------------------------------------------------------------------- Goto Mathematica go throw Common Lisp signal Classic REXX b GNU-sed b, bra, jmp Assembler continue / break continue / break Awk, C, C#, C++, CoffeeScript, E, FishShell, Go, Io, Java, JavaScript, Matlab, PHP, Pike, Python, Tcl, YCP, Yorick --------------------------- ------------------------------------------------------------------------------------------------------------------ Continue / Break Mathematica next / last Perl, Perl6 next / break(51) Maple, Ruby / break BCPL, Lua / break/return Rebol / exit Ada, PostScript / stop Logo restart / leave Beta, Pliant / Exit Do, Exit For Visual Basic / return-from xxx or return Common Lisp iterate / leave Classic REXX / leave Forth redo / retry redo/ Perl, Perl6 ------------ ----------- redo / retry Io, Ruby - exception
throwingraise Ada, Eiffel, F#, merd, OCaml, Python, Ruby, Scheme-SRFI34, SML RAISE Modula-3 raise ... end Oz Exception raise Io throw C#, C++, CoffeeScript, E, Erlang, Forth, Haskell, Java, JavaScript, Logo, PHP5, Pike, Prolog, Rebol Throw Mathematica throw/name Rebol die Perl, Perl6 return -code Tcl error Common Lisp, Dylan, Emacs Lisp, Lua, Lua, Maple, Matlab, Pliant, Yorick signal Common Lisp, Dylan, Smalltalk signal predefined_condition_name Classic REXX cerror warn Common Lisp [NSException raise:name ...] Objective-C panic(v) Go catching try: a except exn: ... Python ----------------------------------------------------------------------------- --------------------------------------- try a with exn -> ... F#, OCaml try a catch (exn) ... C#, C++, Java, JavaScript try a ... catch exn ... CoffeeScript try { ... } catch(t $v) { ... } PHP5 try a catch exn then ... end Oz try a catch exn: ... end try Maple try(a) ; catch(...) Io try { a CATCH exn { ... } } Perl6 TRY a EXCEPT exn => ... END Modula-3 a handle exn => ... SML a on: exception_name do: [:exn | ...] Smalltalk ifCurtailed Smalltalk rescue Eiffel, Ruby eval {a}; if ($@) ... Perl exception when exception_name => Ada catch a (\exn -> ...) Haskell catch Erlang, Forth, Logo, Prolog, Rebol, Tcl Catch Mathematica catch/name Rebol catch(...) or catch { ... }; Pike if (catch(exn)) { ... } a Yorick pcall Lua with-exception-handler or guard Scheme-SRFI34 block a exception(exn) ... end Dylan ?, shy, safe Pliant handler-bind handler-case ignore-errors Common Lisp NS_DURING a NS_HANDLER ... NS_ENDHANDLER Objective-C try a catch ... end Matlab signal on predefined_condition_name ... predefined_condition_name : ... Classic REXX recover() Go cleanup: code executed before leaving ensure Ruby, Smalltalk -------------- --------------------------- finally C#, F#, Java, Maple, Python FINALLY Modula-3 unwind-protect Common Lisp, Emacs Lisp cleanup Dylan dynamic-wind Scheme retrying: after catching an exception, tell the snippet to be re-run retry Eiffel, Ruby, Smalltalk ------- ----------------------- restart Dylan resume execution where the exception took place - call-with-current-continuation
call-with-current-continuation(52) Scheme callcc Ruby, SML-NJ
Types
- declaration
typedef t n C, C++, Pike type n is t Ada type n ... Pliant type n = t F#, Haskell, OCaml, Pascal, SML TYPE n = t Modula-3 using n = ... C# data n = t Haskell datatype n = t SML newtype n = t Haskell n = t merd, Python n : t Beta (deftype n () 't) Common Lisp type n t Go - annotation (or variable declaration)
: Ada, E, Eiffel, F#, Modula-3, OCaml, Pascal, SML :: Dylan, Haskell, Mercury !! merd t v C, C#, C++, Java, Perl6, Pike, Pliant, YCP (declare (t v)) Common Lisp v :@ t Beta _t(53) Mathematica var n t Go - cast
upcast(t) e C, C#, C++, Java, PHP t(e) Ada, Pascal [t] e Pike static_cast(e) C++ e :> t OCaml e : t F# upcast e F# CAST(e as t) SQL92 typecast(e,t) Matlab (t)(e) Go downcast (need runtime checking) (t) e Java --------------------- -------- t(e) Ada e : t E [t] e Pike dynamic_cast(e) C++ e as t C# e :?> t F# downcast e(54) F# v ?= e(55) Eiffel NARROW(e, t) Modula-3 typecast(e,t) Matlab computed conversion (calls an internal or a user-defined function) (t) e C++, Pike ----------------- ------------------- [t] e MSH t(e) C++, Matlab, Python t e F# e : t E e :: t Haskell cast e t Pliant ... cast t Pliant make t e / to t e Rebol - mutability, constness
type of a mutable valuemutability is the default C, C#, C++, Go, Java, Matlab val x: T Pascal T ref F#, OCaml, SML STRef a T Haskell in out T(56) Ada type of a constant value const T C++, C99 ------------------------ ----------------------- constant T Ada const x: T Pascal constness is the default F#, Haskell, OCaml, SML const e t Go special cases "readonly" fields(57) C# ------------------------------------------------------ ---- "final" fields, parameters, local variables(57) Java
Object Oriented & Reflexivity
- method invocation
object.method(para) Ada, Beta, C#, C++, Cecil, CoffeeScript, Delphi-Kylix, E, Eiffel, F#, Icon, Java, JavaScript, merd, Modula-3, MSH, Perl6, Python, Ruby, Sather, Visual Basic object#method para OCaml object:method(para) Lua object method(para) Io object method para Pliant, Tcl object method: para1 method_continuation: para2 Smalltalk object <- method(para)(58) E [ object method: para ] Objective-C object->method(para) C++, Perl, PHP, Pike object["method"](para) Pike object/method para Rebol method object para Haskell, Mercury (method object para) Common Lisp method(object, para) Ada, Dylan, Matlab para->method Beta (send object method para) MzScheme with no parameter object.method Ada, Eiffel, F#, merd, Perl6, Ruby -------------------------- -------------------------------------------------- object.property(59) C# object.method() C#, C++, CoffeeScript, E, Java, JavaScript, Python object#method OCaml object:method Pliant object->method Perl object->method() PHP5, Pike object/method Rebol object["method"]() Pike object method Io, Smalltalk [ object method ] Objective-C method object Haskell, Mercury (method object) Common Lisp method(object) Ada, Dylan, Matlab (send object method) MzScheme - object creation
new PHP, Pliant, Simula new class_name(...) C#, C++, CoffeeScript, F#, Java, JavaScript, Perl, PHP, Visual Basic new class_name ... CoffeeScript, OCaml class_name.new(...) Perl6, Ruby class_name new Smalltalk class_name(...) F#, Matlab, Pike, Python class_name v(...) C++ v : class_name Ada class_name.Create Delphi-Kylix !class_name!constructor_name(...) Eiffel & Beta make-object MzScheme (make-instance class_name ...) Common Lisp [class_name alloc] Objective-C make class_name! ... Rebol def object_name { ... } E - object cloning
o.clone Perl6 o.clone(60) Eiffel, Ruby o.deep_clone Eiffel o.clone() Java o.Clone() C# clone $o PHP5 o clone Io clone / copy or deepCopy Smalltalk Storable::dclone Perl [o copy] Objective-C copy.copy(o)(61) Python purecopy Emacs Lisp {< >} or Oo.copy o OCaml o2 = o(62) C++, Matlab, PHP o2=o2 = o2=o PHP o2.all := o.all Ada make o [] Rebol o_ : T'Class := o(63) Ada - manually call an object's destructor
delete C++, JavaScript destroy Pike DESTROY Perl dealloc Objective-C Dispose C#, F# del, __del__ Python __destruct PHP5 Requires instantiation of Ada.Unchecked_Deallocation Ada - class declaration
class C#, C++, CoffeeScript, Haskell, Java, Matlab, MzScheme, OCaml, Perl6, PHP, Pike, Python, Ruby class c inherit p1 p2 ... feature decl decl ... end Eiffel defclass defstruct Common Lisp subclass Smalltalk struct C++ type Pliant type c is tagged record ... end record(64) Ada @interface c { ... } ... @end Objective-C : Beta type c() = class ... end F# type c() = ... F# - testing class membership
isa Matlab, Perl is_a? kind_of? Ruby o.meta.isa Perl6 isKindOf(65) Smalltalk isKindOfClass Objective-C dynamic_cast C++ instanceof CoffeeScript, Java, JavaScript, PHP5 isinstance Python in Ada is C# is_a PHP :? F# Program.inherits or Program.implements Pike entry_type Pliant typep Common Lisp ISTYPE Modula-3 object## < classname## Beta type.accepts(object) / object =~ v : type E var ?= val(66) Eiffel - get the type/class corresponding to an object/instance/value
class Matlab, Objective-C, Ruby, Smalltalk __class__ Python getClass Java get_class PHP GetType F# typeid C++ typeof C#, CoffeeScript, JavaScript type-of Common Lisp type Io ref Perl generator Eiffel meta Perl6 object_program Pike getAllegedType E - methods available
methods Matlab, Ruby get_class_methods PHP getMethods Java get-member MSH indices Pike o.meta.getmethods Perl6 dir Python slotNames Io o.GetType().GetMethods() F# o class selectors / o class allSelectors Smalltalk o.__getAllegedType().getMessageTypes() E - inheritance
child :< parent Beta class child : parent C#, C++ class child < parent end Ruby class child is parent { ... } Perl6 class child extends parent CoffeeScript, Java, PHP5 class child(parent): Python class child inherit parent end Eiffel parent subclass: child Smalltalk make parent ... Rebol inherit OCaml, Pike def child extends makeSuperObject(parent, ...) { ... } E type child is new parent with record ... end record Ada type child = inherit parent ... F# (defclass child (parent) ...) Common Lisp @interface child : parent { ... } ... @end Objective-C @ISA = qw(parent1 parent2) Perl clone , setProtos, setProto, prependProto, appendProto Io instance Parent Child where ... Haskell - has the method
can Perl, Perl6 respond_to? Ruby respondsTo E, Smalltalk respondsToSelector Objective-C hasattr(obj, "meth")(67) Python object->method Pike all [in object 'method function? get in object 'method] Rebol find-method Common Lisp ismethod Matlab hasSlot Io try obj.GetType().GetMethod("meth") with ... F# obj.meth? instanceof Function CoffeeScript method_exists PHP5 - current instance
this Beta, C#, C++, CoffeeScript, Java, JavaScript, PHP, Pike THIS Simula self Io, Objective-C, Rebol, Ruby, Smalltalk object_name if defined as: def object_name { ... } E Current Eiffel first parameter(68) Matlab, Perl, Pliant, Python the object variable F# dispatching parameter Ada, Common Lisp Me Visual Basic . Perl6 - accessing parent method
super CoffeeScript, E, Java, Objective-C, Ruby, Smalltalk super(Class, self).meth(args) Python base C# resend Io Precursor Eiffel $o.SUPER::method(...) Perl6 $o->SUPER::method(...) Perl method(parent(dispatching-parameter)) Ada parent(dispatching-parameter).method Ada parent::method PHP5 call-next-method Common Lisp type foo2 = inherit foo as parent ... member ... = ... parent.meth F# - accessing child method
Package, Module
- package scope
. Ada, C#, CoffeeScript, E, F#, Go, Haskell, Java, Modula-3, OCaml, Pascal, Python, Ruby, SML, Squeak : XML :: C++, merd, Perl, Ruby, Squeak, Tcl, YCP : ::(69) Common Lisp :- Maple ' Perl ` Mathematica __ Mercury / Matlab - declare
package p; Java, Perl namespace p { ... } C#, C++ namespace p ... F# namespace P; PHP5 namespace eval p ... Tcl module p where ... Haskell module P ... end Ruby module P = struct ... end OCaml { module "p"; ... } YCP :- module(p) Prolog p = module() ... end module Maple (defpackage p ...) Common Lisp automatically done based on the file name OCaml, Python, Tcl8.5 package declare(70) Matlab Begin["p`"] ... End[] Mathematica BeginPackage["p`"] ... EndPackage[] Mathematica ... XML package p is -- Declare public package members here private -- Declare private package members here end p; package body p is ... -- Define package implementation here end p; Ada package p Go selective export module p (name1, name2, ...) where ... Haskell --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------- @ISA = qw(Exporter); @EXPORT = qw(name1 name2 ...); Perl package p is ... end; package body p is ... end; Ada p = module() export name1, name2, ...; ... end module Maple (export 'name1 'name2) Common Lisp attached to each name (public, private...) Java, Pike namespace export name1 Tcl namespace p val name1 : type1 ... F# append_features Ruby module type PType = sig val name1 : type1 ... end module P : PType = struct ... end OCaml all files in package directory are exported. files in /private sub-directory are not exported, but can be used by the package itself Matlab __all__ = [ ... ] Python Identifier is only exported if the first character of its name is an Unicode upper case letter; and the identifier is declared in the package block or it is a field name or method name. No other identifiers are exported Go - import
everything into current namespaceuse p(71) Perl uses p Pascal using p C# using namespace p; C++ (use-package 'p) Common Lisp open p F#, OCaml import Pike import p Haskell IMPORT p; Modula-2 import p.* Java import "p" YCP from p import * Python with p; use p; Ada namespace import p * Tcl inherit c export {NONE} all end Eiffel include or even extend Ruby do Rebol addpath Matlab . p BourneShell source p BourneShell builtin -f /path/to/lib.so KornShell << p` Mathematica Get["p`"] Mathematica Needs["p`"] Mathematica use P1\P; PHP5 use P1\P as Q; PHP5 selectively import p (name1, name2, ...) Haskell ----------------------------------- ----------- import p.name1; import p.name2 Java (import '(p:name1 p:name2)) Common Lisp use p qw(name1 name2 ...) Perl from p import name1, name2, ... Python FROM p IMPORT name1, name2, ...; Modula-2 namespace import p name1 Tcl using p::name1; using p::name2; ... C++ with p; use type p.type1; ... Ada with(p[name1, name2,]) Maple def name := import:p.name E :- use_module(name1, name2, ...) Prolog package (ie. load the package) import p Python ----------------------------- ----------- use p;(72) Perl require p Perl require "p" Ruby require, "p" Yorick (require 'p)(73) Common Lisp with p; Ada with(p) Maple package require p Tcl automatically done(74) Java, OCaml import "p" Go
Strings
- type name
char[] C char const[] C++ string C#, C++, F#, Go, Maple, OCaml, Pascal, PHP, Pike, SML, Vimscript, YCP string! Rebol String Ada, C#, CoffeeScript, Haskell, Java, JavaScript, merd, Ruby, Smalltalk, Visual Basic STRING Eiffel str Python, YAML Str Perl6, Pliant NSString * Objective-C CHAR, VARCHAR(size) SQL92 Sequence Io - character type name
char C, C#, C++, F#, OCaml, SML char! Rebol Char Haskell, merd, Perl6 Character Ada, Smalltalk CHARACTER Eiffel rune Go - character "z"
'z' Ada, B, C, C#, C++, Classic REXX, E, Eiffel, F#, Go, Haskell, Matlab, OCaml, Pascal, Pike "z" BourneShell, Classic REXX, Maple, merd "z Logo $z Smalltalk #\z Common Lisp, Scheme
| #"z" | Rebol, SML |
| &z; | Oz |
| ?z | Emacs Lisp, Ruby |
| char z, [char] z(75) | Forth |
- strings
with no interpolation of variables'...' Beta, BourneShell, Classic REXX, CoffeeScript, CSS, FishShell, JavaScript, Lua, Matlab, Pascal, Perl, Perl6, PHP, Prolog, Python, Ruby, Smalltalk, SQL92, Vimscript, XPath, YAML "..." Ada, Awk, C, C#, C++, Classic REXX, Common Lisp, CSS, Dylan, E, Eiffel, Emacs Lisp, F#, FL, Go, Haskell, Io, Java, JavaScript, Lua, Maple, Mathematica, Modula-3, MUMPS, OCaml, Oz, Pike, Pliant, Prolog, Python, Rebol, Scheme, SML, XPath, YAML, YCP "... Logo '''...''' Python """...""" Io, Python [[ ... ]] Lua R"[ ... ]" C++-0x <<'MARK' ... MARK BourneShell, Perl, Ruby <<<'MARK' ... MARK(76) PHP5 {...{...}...} Tcl (...) PostScript q(...(...)...), q[...], q{...}, q<...>, q/.../ Perl, Perl6 %q(...(...)...), %q[...], %q{...}, %q<...>, %q/.../ Ruby q(...(...)...) merd @"...""..." C# s"..." Forth @"..." Objective-C with interpolation of variables ...(77) Tcl -------------------------------------------------------------- --------------------------------------------- "... $v ..." BourneShell, FishShell, Perl, Perl6, PHP, Tcl "... {v} ..." merd "... #{v} ..." "... #$v ..." "... #@v ..." "... #@@v ..." CoffeeScript, Ruby <<MARK ... $v ... MARK BourneShell, Perl <<MARK ... #{v} ... MARK Ruby <<<MARK ... $v ... MARK PHP qq(...(... $v ...)...), qq[...], qq{...}, qq<...>, qq/.../ Perl, Perl6 %Q(...(... #{v} ...)...), %Q[...], %Q{...}, %Q<...>, %Q/.../ Ruby qq(...(... {v} ...)...) merd "... #{v} ..." interpolate Io "... %(v)s ..." % vars() Python end-of-line (without writing the real CR or LF character) \n Tcl ---------------- --------------------------------------------------------------------------------------------------------------------------------------------------------- "\n" C, C#, C++, CoffeeScript, FishShell, Go, Haskell, Io, Java, JavaScript, Lua, Maple, Mathematica, OCaml, Perl, Perl6, PHP, Pike, Python, Ruby, YCP, Yorick "*n" B, BCPL "%N" Eiffel "^/" Rebol "~%"(78) Common Lisp "[lf]" Pliant vb_nl Visual Basic (79) Smalltalk - multi-line
all strings allow multi-line strings BourneShell, Common Lisp, E, Emacs Lisp, F#, FishShell, Io, Maple, Mathematica, OCaml, Pascal, Perl, Perl6, PHP, Ruby, Scheme, Smalltalk, YCP "...", {...} Tcl @"..." C# '''...''', """...""" Python [[ ... ]] Lua {...} Rebol "...\n" "...\n" C ... "...\n\ \...\n" Haskell "...", "..." Classic REXX "...%N% %...%N" Eiffel """ ... """ CoffeeScript `...` Go - convert something to a string (see also string interpolation)
show Haskell to_s, to_str, inspect, String() Ruby to_string merd, Pliant tostring Lua, YCP toString CoffeeScript, Java, JavaScript ToString C#, F#, Mathematica String CoffeeScript, JavaScript perl Perl6 Dumper Perl "" . e Perl "" ~ e Perl6 "" + e CoffeeScript, E, Java, JavaScript string Pliant, Vimscript str, `e`, repr Python out Eiffel cvs PostScript T'Image(e)(80) Ada asString Io, Smalltalk printString Smalltalk as(, e) Dylan (string) e PHP, Pike convert(e,string) Maple (coerce e 'string) Common Lisp prin1-to-string Emacs Lisp to string! / to-string / to "" Rebol description Objective-C pr1 Yorick unneeded, all values are strings Tcl string(e) Go - serialize (marshalling)
export-clixml MSH serialize Io, PHP Marshal.to_string OCaml Marshal.dump Ruby Data.Binary.encode Haskell BinaryFormatter.Serialize F# storeBinaryOn Smalltalk Storable::store Perl pickle.dump(81) Python (with-standard-io-syntax (write obj stream)) Common Lisp T'Output(80) Ada - unserialize (un-marshalling)
import-clixml MSH unserialize PHP Marshal.from_string OCaml Marshal.load Ruby Data.Binary.decode Haskell BinaryFormatter.Deserialize F# readBinaryFrom Smalltalk pickle.load Python (with-standard-io-syntax (read obj stream)) Common Lisp Storable::store Perl doString Io T'Input(80) Ada - sprintf-like
sprintf Awk, C, C++, F#, Maple, Matlab, merd, OCaml, Perl, Perl6, PHP, Pike, Ruby printf Haskell % Python, Ruby format Java, Lua, Tcl format(82) Common Lisp, Erlang, Scheme-SRFI28 Format C#, F# putFormat Beta stringWithFormat Objective-C expandMacrosWith(82) Smalltalk Storable::retrieve Perl fmt.Sprintf Go - simple print
on stringsputs C, Dylan, Tcl print Awk, Basic, Java, Maple, merd, PHP, SML write JavaScript, Pascal, Pike, Yorick putStr Haskell print_string F#, OCaml console Pliant writeln JavaScript, Pascal write-string Common Lisp putStrLn Haskell Put_Line Ada display Cobol message Emacs Lisp put_string Eiffel show Smalltalk print_endline(83) OCaml println(83) Java, merd put_chars Erlang echo(84) BourneShell, FishShell, PHP type Forth putText Beta say Classic REXX p or i GNU-sed fmt.Print Go echom Vimscript on simple objects print Perl, Perl6 --------------- ----------- say(83) Perl6 puts(83) Tcl puts -nonewline Tcl on any objects print Io, Logo, Lua, Ruby ---------------------------------------------------------------------------- ------------------------------- print(83) Dylan, Haskell, Python, Rebol Print Mathematica print e, Python println(83) Io prin Rebol Put Ada p(83) Ruby puts(85) Ruby display Scheme write Common Lisp, Io, Prolog, Scheme writeln(83) Io print Common Lisp printOn Smalltalk princ prin1 Common Lisp, Emacs Lisp print_any F# WriteLine C#, F# nothing - just remove ";" at the end of the expression, and it will print it Matlab disp Matlab printf-like printf Awk, C, C++, F#, Haskell, KornShell, Maple, Matlab, merd, OCaml, Perl, PHP, Ruby ----------------- -------------------------------------------------------------------------------- write Pike WriteLine C# putFormat Beta format(82) Common Lisp, Prolog fmt.Printf Go - string equality & inequality
eq ne Perl, Perl6, Tcl strcmp C, Matlab == !=(Vimscript: whether or not == and != are case-sensitive depends on user settings.) CoffeeScript, Go, JavaScript, Pike, Vimscript ==? !=?(86) Vimscript ==# !=#(87) Vimscript == !== PHP == ~= Lua = \= Prolog isEqualToString(88) Objective-C == != Awk, C#, C++, E, Io, merd, Python, Ruby, YCP == <> Python == /= Haskell == \= Oz = != BourneShell, FishShell, Maple, XPath = /= Ada = \= Classic REXX = <> Beta, F#, OCaml, Pliant, SML, Visual Basic = ~= Dylan, Smalltalk == \== or = <> \= Classic REXX === =!= / == !=(20) Mathematica == ~= Matlab equal? Ruby, Scheme equals Java equal, equalp Common Lisp is_equal Eiffel isEqual Objective-C - string size
length Awk, Beta, C++, CoffeeScript, Common Lisp, Eiffel, F#, Haskell, Java, JavaScript, Maple, Matlab, Objective-C, OCaml, Perl, PostScript, Prolog, Ruby LENGTH Classic REXX 'Length Ada length? Rebol size C++, E, Io, Ruby, Smalltalk, SML, YCP Length C#, F#, Modula-3, Oz, Pascal len Go, Pliant, Python, Vimscript, Visual Basic strlen C, PHP, Vimscript string length Tcl string-length Scheme, XPath StringLength Mathematica sizeof Pike count Eiffel, Logo bytes chars Perl6 CHARACTER_LENGTH SQL92 atom_length Prolog wc -c FishShell # Lua
| ${#v} | BourneShell |
| dup(89) | Forth |
- string concatenation
+ C#, C++, CoffeeScript, E, Eiffel, F#, Go, Java, JavaScript, merd, MSH, Pascal, Pike, Pliant, Python, Ruby, YCP . Perl, PHP, Vimscript .. Io, Lua , Smalltalk ~ D, Perl6 & Ada, Modula-3, Visual Basic ^ F#, OCaml, SML _ MUMPS | ++ Haskell aaab BourneShell, FishShell, Tcl concatenate Common Lisp, Dylan string-append Scheme StringJoin Mathematica cat Maple Cat Modula-3 strcat C concat XPath append Beta, Prolog, Rebol stringByAppendingString Objective-C Awk, Classic REXX [string1 string2] Matlab word Logo - duplicate n times
* Ada, E, Pike, Python, Ruby x Perl, Perl6 times merd repeat Pliant repeated Io str_repeat PHP string repeat Tcl strrep Lua repmat Matlab insert/dup Rebol COPIES Classic REXX cat(s$n) Maple concat $ replicate Haskell strings.Repeat Go - upper / lower case character
upcase / downcase Emacs Lisp, Ruby uc / lc Perl, Perl6 upper / lower(90) Lua, Matlab, Pliant, Python toUpper / toLower Haskell to_upper / to_lower Eiffel To_Upper / To_Lower Ada toUpperCase / toLowerCase CoffeeScript, E, Java, JavaScript upper_case / lower_case Pike uppercase / lowercase F#, Logo, OCaml strupper / strlower Lua strtoupper / strtolower PHP ToUpper / ToLower C#, F#, Oz toupper / tolower Awk, C, C++ string toupper / string tolower Tcl asLowercase / asUppercase Io, Smalltalk upCase / lowCase Beta uppercase form / lowercase form Rebol char-upcase / char-downcase Common Lisp, Scheme char_type(C_, to_upper(C)), char_type(C_, to_lower(C)) Prolog \U / \L / \C GNU-sed unicode.ToUpper / unicode.ToLower Go - uppercase / lowercase / capitalized string
upcase / downcase Emacs Lisp, Ruby upper / lower Matlab, SQL92 upper / lower / capitalize Python uppercase/lowercase F#, Logo, OCaml, Rebol upcase_atom/downcase_atom Prolog toUpperCase / toLowerCase CoffeeScript, E, Java, JavaScript ToUpperCase / ToLowerCase Mathematica ToUpper / ToLower C#, F# to_upper / to_lower Ada, Eiffel toupper / tolower Awk, YCP uc / lc Perl, Perl6 UpperCase / LowerCase Pascal StringTools[UpperCase] / StringTools[LowerCase] / StringTools[Capitalize] Maple uppercaseString / lowercaseString / capitalizedString Objective-C UCase / LCase Visual Basic strtoupper / strtolower PHP, Yorick strupper / strlower Lua string toupper / string tolower / string totitle Tcl string-upcase / string-downcase Common Lisp, Scheme asLowercase / asUppercase / asUppercaseFirst Smalltalk asLowercase / asUppercase / makeFirstCharacterUppercase Io upcase_atom / downcase_atom Prolog makeLC / makeUC Beta parse upper var in_var out_var / parse lower var in_var out_var Classic REXX strings.ToUpper / strings.ToLower / strings.Title Go - ascii to character
chr F#, Haskell, OCaml, Pascal, Perl, Perl6, PHP, Python, Ruby, SML chr$ Visual Basic char Matlab format %c $c Tcl toChar E strchar Lua from_integer Eiffel fromCharCode CoffeeScript, JavaScript FromCharacterCode Mathematica character Pliant Character value: c Smalltalk asCharacter Io code-char Common Lisp integer->char Scheme 'Val Ada (char) c C, C#, C++, Java to char! / to-char Rebol X2C, D2C Classic REXX $CHAR(s) MUMPS char_code Prolog ascii Logo StringTools[Char] Maple utf8.DecodeRuneInString(s) Go - character to ascii
ord F#, Haskell, Pascal, Perl, Perl6, PHP, Python, SML asc Visual Basic getNumericValue Java charCodeAt CoffeeScript, JavaScript asciiValue Smalltalk code Eiffel, OCaml char-code Common Lisp char->integer Scheme s[0] Ruby s 0 get PostScript s at(0) Io scan $s %c Tcl strbyte Lua toInteger E 'Pos Ada number Pliant (int) c C, C#, C++, Java to integer! / to-integer Rebol ToCharacterCode Mathematica C2X, C2D Classic REXX $ASCII(s) MUMPS (done automatically when applying mathematical operations on char, such as +) Matlab char Logo char_code Prolog StringTools[Ord] Maple string(c) Go - accessing n-th character
s[n] C, C#, C++, E, Go, Maple, PHP, Pike, Python, Ruby, Vimscript s(n) Ada, Matlab s:n Pliant s.[n] F#, OCaml s !! n Haskell s @ n Eiffel s/:n Rebol string index s n Tcl sub SML char, aref, schar, svref Common Lisp GetChar Modula-3 s at(n) Io at(91) C++, Smalltalk aref Common Lisp char(s, i) B charAt CoffeeScript, Java, JavaScript characterAtIndex Objective-C n -> s.inxGet Beta string-ref Scheme StringTake[s, {n}] Mathematica $EXTRACT(s, n) MUMPS item Logo over n chars + c@ Forth s/.{n}(.).*/\1/ GNU-sed - extract a substring
s[n..m] CoffeeScript, Maple, Pike, Ruby s.[n..m] F# s(n..m) Ada s(n:m) Matlab s(n,m+1) E s[n:m+1] Go, Python, Vimscript s[n,len] Ruby s n len Pliant strndup(s + n, len) C substring Eiffel, Java, Scheme, SML, XPath, YCP Substring C# substr C++, Perl, Perl6, PHP SUBSTR Classic REXX sub F#, Lua, OCaml SUB Modula-3 subseq Common Lisp slice CoffeeScript, Io, JavaScript mid$ JavaScript string range Tcl StringTake[s, {n, m}] Mathematica strpart(s, n, m) Yorick copy/part at s n len Rebol copy/part at s n at s m Rebol s copyFrom: n to: m Smalltalk (n,m)->s.sub Beta [s substringWithRange:NSMakeRange(n, len)] Objective-C SUBSTRING(s FROM n len) SQL92 $EXTRACT(s, n, m) MUMPS sub_string / sub_atom Prolog (take len . drop n) s Haskell over n chars + len Forth s/.{n}(.{len}).*/\1/ GNU-sed - locate a substring
index Ada, Perl, Perl6, Python, Ruby indexOf CoffeeScript, Java, JavaScript IndexOf C#, F# indexOfString Smalltalk startOf E search Common Lisp, Pike, PostScript StringTools[Search] Maple StringPosition Mathematica strstr strchr C find C++, Logo, Lua, Python, Rebol, YCP findSeq Io findSubstring Haskell strfind Matlab, Yorick strpos PHP $FIND MUMPS index_non_blank / find_token Ada substring_index Eiffel rangeOfString Objective-C POS Classic REXX POSITION(needle IN s) SQL92 sub_string / sub_atom Prolog string first Tcl strings.Index Go - locate a substring (starting at the end)
rindex OCaml, Perl, Perl6, Python, Ruby rfind C++, Python find/last Rebol strrchr C index(Going => Backward) Ada lastStartOf E lastIndexOf CoffeeScript, Java, JavaScript last_index_of(92) Eiffel LastIndexOf C#, F# lastIndexOfString Smalltalk string last Tcl (search substring string :from-end t) Common Lisp [string rangeOfString:substring options:NSBackwardsSearch] Objective-C LASTPOS Classic REXX t=strfind(s,p), t(end) Matlab strrpos PHP StringTools[SearchAll](s,p)[-1] Maple strings.LastIndex Go
Booleans
- type name
Bool Haskell, Perl6, Pliant bool C#, C++, C99, F#, Go, OCaml, PHP, Python, SML, YAML Boolean Ada, Lua, Pascal, Smalltalk, Visual Basic boolean CoffeeScript, Common Lisp, Java, JavaScript, Maple, PHP, YCP BOOLEAN Eiffel logic! Rebol logical Matlab - false value
false Ada, BCPL, Beta, BourneShell, C#, C++, C99, CoffeeScript, E, F#, FL, Forth, Go, Io, Java, JavaScript, Logo, Lua, Maple, Matlab, OCaml, Oz, Pascal, PHP, Pliant, PostScript, Rebol, Ruby, Smalltalk, SML, Tcl, YAML, YCP False Eiffel, Haskell, Mathematica, merd, Python, Visual Basic FALSE Modula-3, SQL92 false() XPath #f Dylan, Scheme
| n | YAML |
| nil | Common Lisp, Emacs Lisp, Io, Lua, Ruby |
| no | CoffeeScript, Tcl, YAML |
| No | Prolog |
| none | Rebol |
| None | Python |
| null | CoffeeScript, JavaScript |
| NULL | C, C++, C99, PHP |
| off | CoffeeScript, Tcl, YAML |
| undef | Perl, Perl6 |
| undefined | CoffeeScript, JavaScript |
| fail | Prolog |
| FAIL | Maple |
| array containing at least one false value | Matlab |
| exit status different from 0 | BourneShell |
| 0(93) | Awk, B, C, C++, C99, Classic REXX, CoffeeScript, Forth, JavaScript, Matlab, MUMPS, Perl, Perl6, PHP, Pike, Python, Tcl, Visual Basic, XPath, Yorick |
| 0.0 | Matlab, Perl, PHP |
| NaN | CoffeeScript, JavaScript, XPath |
| "" | Awk, CoffeeScript, JavaScript, Perl, Perl6, PHP, Python, XPath |
| "0" | Awk, Perl, Perl6, PHP |
| '' | CoffeeScript, Matlab, Perl |
| '\0' | C, C++, C99 |
| () | Perl, Perl6, Python |
| [] | Matlab, Python |
| {} | Matlab, Python |
| array() | PHP |
- true value
TRUE Modula-3, SQL92 True Eiffel, Haskell, Mathematica, merd, Python, Visual Basic true Ada, BCPL, Beta, BourneShell, C#, C++, CoffeeScript, E, F#, FL, Forth, Go, Io, Java, JavaScript, Logo, Maple, OCaml, Oz, Pascal, PHP, Pliant, PostScript, Prolog, Rebol, Ruby, Smalltalk, SML, Tcl, YAML, YCP true() XPath t Common Lisp, Emacs Lisp #t Dylan, Scheme
| y | YAML |
| yes | CoffeeScript, Tcl, YAML |
| Yes | Prolog |
| on | CoffeeScript, Tcl, YAML |
| exit status 0 | BourneShell |
| anything not false | Awk, B, C, C++, Common Lisp, Dylan, Emacs Lisp, Matlab, MUMPS, Perl, Perl6, Pike, Python, Rebol, Ruby, Scheme, XPath, Yorick |
| 1 | Classic REXX, MUMPS |
| non zero number | Tcl |
| non-zero-numbers | Visual Basic |
| -1 | Forth |
- logical not
! Awk, B, C, C#, C++, CoffeeScript, E, Go, Java, JavaScript, Mathematica, Perl, Perl6, PHP, Pike, Ruby, Tcl, Vimscript, YCP, Yorick not(94) Ada, Beta, CoffeeScript, Common Lisp, Eiffel, Emacs Lisp, F#, Haskell, Io, Logo, Lua, Maple, merd, OCaml, Pascal, Perl, Perl6, Pliant, PostScript, Prolog, Python, Rebol, Ruby, Scheme, Smalltalk, SML, XPath Not Oz, Visual Basic NOT Modula-3 ~ BCPL, Dylan, Matlab, PL/I ^ PL/I ' MUMPS \ Classic REXX =0 Forth - logical or / and
short circuit
| || / && | Awk, C, C#, C++, CoffeeScript, E, F#, Go, Haskell, Java, JavaScript, Mathematica, Matlab, merd, OCaml, Perl, Perl6, PHP, Pike, Ruby, Tcl, Vimscript, YCP, Yorick |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| | / & | B, BCPL, Dylan |
| or / and | CoffeeScript, Common Lisp, Emacs Lisp, Io, Logo, Lua, Modula-2, Perl, Perl6, PHP, Pliant, Python, Ruby, Scheme, Smalltalk |
| OR / AND | Modula-3 |
| or / &(95) | Modula-2 |
| any / all | Rebol |
| orelse / andalso | SML |
| orelse / andthen | Oz |
| or else / and then | Ada, Eiffel |
| ; / , | Prolog |
| & / ! | MUMPS |
non short circuit (always evaluates both arguments)| / & C#, Classic REXX, Java, Matlab, Smalltalk or / and Ada, Beta, Eiffel, Maple, Pascal, PostScript, Rebol, SML, XPath Or / And(96) Oz, Visual Basic \/ / /\(15) BCPL ?| / Perl6
Bags and Lists
- type name
seq YAML a list F#, OCaml, SML [a] Haskell a[] C# list Maple, Python List Io, Mathematica, Pliant Array or List Perl6 ARRAY or LINKED_LIST Eiffel Array or OrderedCollection Smalltalk ARRAY Perl array PHP cell Matlab vector C++ Containers.Vectors.Vector or Ada.Containers.Doubly_Linked_Lists.List Ada []a Go - list concatenation
+ E, Eiffel, merd, PHP, Pike, Python, Ruby, Vimscript , Maple, Matlab, Perl, Smalltalk @ F#, OCaml, SML ~ D & Ada ++ Haskell | array_merge PHP merge YCP concat CoffeeScript, JavaScript, Tcl concatenate Dylan nconc Common Lisp, Emacs Lisp append Beta, Common Lisp, Emacs Lisp, Go, Prolog, Rebol, Scheme Append Oz appendSeq Io arrayByAddingObjectsFromArray Objective-C sentence Logo Join Mathematica - list flattening
one level depthconcat F#, Haskell, Mercury, SML flatten F#, Io, merd, OCaml, Prolog, YCP Flatten Oz eval concat Tcl ListTools[FlattenOnce] Maple {*}$l Tcl8.5 "$l" FishShell recursive flatten Pike, Ruby -------------------- ----------- ListTools[Flatten] Maple Flatten Mathematica - list constructor
[ a, b, c ](97) CoffeeScript, E, Haskell, JavaScript, Maple, Matlab, merd, Perl, Perl6, PHP5, PostScript, Prolog, Python, Ruby, SML, Vimscript, YAML, YCP ( a, b, c ) Perl, Perl6 { a, b, c }(98) C, C++, Lua, Mathematica #(a, b, c) Dylan
| #(a b c)(99) | Smalltalk |
| { a. b. c } | Squeak |
| [ a ; b ; c ] | F#, OCaml |
| [ a b c ] | Logo, Oz, Rebol |
| ({ a, b, c }) | Pike |
| '(a b c) | Common Lisp, Emacs Lisp, Scheme |
| << a, b, c >> | Eiffel |
| list(a, b, c) | Io |
| list | Common Lisp, Dylan, Emacs Lisp, Scheme, Tcl |
| array(a, b, c) | PHP |
| new t[] { a, b, c } | C# |
| new[] { a, b, c } | C#3 |
| new List { a, b, c} | C#3 |
| Array(a, b, c)(100) | JavaScript |
| [NSArray arrayWithObjects:a, b, c, nil] | Objective-C |
| set l a b c | FishShell |
| - a - b - c | YAML |
| []t{a, b, c} | Go |
- list/array indexing
a[i] B, BourneShell, C, C#, C++, CoffeeScript, Dylan, E, FishShell, Go, Java, JavaScript, KornShell, Lua, Maple, merd, Modula-3, MSH, Pascal, Perl, Perl6, PHP, Pike, Python, Ruby, Vimscript a*[i] or a!i or a*(i) depending on the version BCPL a[[i]] Mathematica a[i]:default YCP a(i) Ada, Matlab a:i Pliant a/:i Rebol a.(i) F#, OCaml a.[i] F# a !! i Haskell, Mercury a @ i Eiffel a i get(101) PostScript a at(i) Io at(102) C++, Smalltalk lindex Tcl nth Common Lisp, Emacs Lisp, OCaml Nth Oz aref Common Lisp, Emacs Lisp nth0 / nth1 Prolog list-ref / vector-ref Scheme element Dylan slice Ruby node[i] XPath objectAtIndex Objective-C item Logo a i cells + @ (for write access: o a i cells + ! Forth - adding an element at the beginning (list cons)
return the new list (no side-effect): Haskell, merd :: F#, OCaml, SML | Oz [ e | l ] Erlang, Prolog [e l[]] Maple [e l] Matlab cons Common Lisp, Emacs Lisp, Scheme pair Dylan fput Logo Prepend Ada, Mathematica side-effect unshift CoffeeScript, JavaScript, Perl, Perl6, Ruby -------------- ------------------------------------------- prepend YCP push_front C++ addFirst Smalltalk insert Rebol put_first Eiffel push Common Lisp, Io array_unshift PHP PrependTo Mathematica - adding an element at index
return the new list (no side-effect)linsert l i e Tcl Insert Ada, Mathematica side-effect [a insertObject:e atIndex:i] Objective-C ------------------------------------------------ ------------ a.insert(i, e) Python, Ruby a insertAt(e, i) Io a add: e beforeIndex: i / a add: e afterIndex: i Smalltalk splice(@a, i,0,i, 0, i,0,e) Perl - adding an element at the end
return the new list (no side-effect)[l e] Matlab push merd arrayByAddingObject Objective-C lput Logo linsert l end e Tcl Append Ada, Mathematica side-effect push CoffeeScript, JavaScript, Perl, Perl6, Ruby ----------- ------------------------------------------- push_back C++ append Go, Io, Pliant, Python, Rebol AppendTo Mathematica lappend Tcl += Pliant add Java, Smalltalk, YCP put_last Eiffel array_push PHP addObject Objective-C - first element
head Haskell Head F# hd F#, OCaml car Common Lisp, Emacs Lisp, Scheme first Eiffel, Io, Logo, Pliant, Rebol, Smalltalk First(103) Mathematica First_Element Ada iterator head Beta ----- ---- begin C++ First Ada - all but the first element
tail Haskell Tail F# tl F#, OCaml cdr Common Lisp, Emacs Lisp, Scheme Rest Mathematica butfirst Logo allButFirst Smalltalk l[1:] Go, Python a(2:end) Matlab L = [_|ButFirst] Prolog lrange l 1 end Tcl - last element
last E, Eiffel, Haskell, Io, Logo, Pliant, Prolog, Rebol, Scheme, Smalltalk Last Mathematica, Oz lastObject Objective-C a[-1] Perl, Pike, Python, Ruby a(end) Matlab node[last()] XPath (car (last l)) Common Lisp, Emacs Lisp lindex l end Tcl Last_Element Ada l[len(l)-1:] Go iterator - all but the last element
- get the first element and remove it
shift CoffeeScript, JavaScript, Perl, Perl6, Ruby shift! merd pop Common Lisp, Logo removeFirst Io, Smalltalk array_shift PHP - get the last element and remove it
pop CoffeeScript, E, Io, JavaScript, Perl, Perl6, Python, Ruby pop! merd array_pop PHP removeLast Io, Smalltalk dequeue Logo - for each element do something
each merd, Pliant, Ruby for v in l ... CoffeeScript, E, Maple, Ruby for v in l: ... Python for v in l; do ...; done BourneShell for v in l do ... F# for v in l; ...; end FishShell for (v in l) ... Awk, Dylan for (var v in l) { ... } JavaScript For Each v in l ... Next Visual Basic for v in range loop .. end loop Ada for Perl foreach Logo, Lua, Perl, PHP, Pike, Rebol, Tcl foreach (t v in l) ... C# foreach (v in l) ... C#3 foreach ($v in l) ... MSH foreach(t v, l, { ... }) YCP l foreach(v, ...) Io for_each C++ for-each Scheme forall PostScript, Prolog ForAll Oz iter F#, OCaml do Smalltalk do_all Eiffel app SML mapc Emacs Lisp mapM_ Haskell Scan Mathematica (dolist (v l) ...) (loop for v in l do ...) mapc Common Lisp list.iterate (# do current ... #) Beta l.Iterate(...) F# Iterate Ada for i, v := range l {...} Go - transform a list (or bag) in another one
map Dylan, F#, Haskell, Io, Maple, Mercury, merd, OCaml, Perl, Pike, Python, Ruby, Scheme, SML Map F#, Mathematica, Oz mapcar Common Lisp, Emacs Lisp maplist Prolog, YCP sublist Prolog map / map.se Logo for-each XSLT foreach or selected MSH collect Ruby, Smalltalk transform C++ array_map PHP /@ Mathematica [ f x | x <- l ](104) Haskell [ f(x) for x in l ](104) Python magical: sin(x) computes sin on each element Matlab - transform two lists in parallel
map2 F#, OCaml zipWith Haskell Zip Maple, Oz map Dylan, Logo, Python, Scheme map.se Logo mapcar Common Lisp maplist2 Prolog l1 with: l2 collect: ... Smalltalk transform C++ ListPair.map SML magical: a binary function or operator is appliied on each element Matlab - find an element
find C++, Common Lisp, F#, Haskell, merd, OCaml, Rebol, Ruby, Scheme-SRFI1, SML, YCP Find Ada find_if C++ find-if Common Lisp first(22) Perl detect Ruby, Smalltalk search Pike ListTools[Search] Maple lsearch -exact Tcl index Python indexOf Io indexOfObject, indexOfObjectIdenticalTo Objective-C find(a == 3) Matlab Position Mathematica - keep elements
matchingfind_all F#, OCaml, Ruby filter F#, Haskell, Mercury, merd, OCaml, Pike, Python, Scheme-SRFI1, SML, YCP filter! Scheme-SRFI1 Filter Oz grep Perl, Perl6 where MSH select Io, Maple, Ruby, Smalltalk Select / Case Mathematica selectInPlace Io remove-if-not delete-if-not Common Lisp choose Dylan array_filter PHP5 [ x | x <- l, p x ](104) Haskell [ x for x in l if p(x) ](104) Python a(a == 3) Matlab non matching remove-if delete-if Common Lisp ------------------- ----------- reject Ruby - partition a list: elements matching, elements non matching
partition F#, Haskell, merd, OCaml, Ruby, Scheme-SRFI1, SML partition! Scheme-SRFI1 Partition Oz - split a list
in 2 based on a predicate
into sublists delimited by elements matching a predicatesplit-sequence(105) Common Lisp ListTools[Split] Maple into a list of lists of same value group Haskell ----- ----------- Split Mathematica into sublists based on a predicate groupBy Haskell ------- ----------- Split Mathematica - is an element in the list
member? Dylan, merd, Ruby include? Ruby mem F#, OCaml member Common Lisp, Prolog, Scheme Member Oz MemberQ Mathematica memq memv Scheme memberp / member? Logo contains E, Io, YCP containsObject Objective-C in CoffeeScript, JavaScript, Python, SQL92, Tcl8.5 in_array PHP includes Smalltalk elem Haskell, Mercury has Eiffel has_value Pike ismember Matlab /elt/ GNU-sed - is the predicate true for an element
any(31) Haskell, Matlab, Mercury, Python, Scheme-SRFI1 any? Dylan, Ruby anySatisfy Smalltalk exists F#, OCaml, SML exists? merd some Common Lisp Some Oz ormap Maple detect Io - is the predicate true for every element
all(31) Haskell, Mercury, Python, SML All Oz all? merd, Ruby allSatisfy Smalltalk every Common Lisp, Scheme-SRFI1 every? Dylan for_all F#, OCaml andmap Maple - smallest / biggest element
min / max Common Lisp, Eiffel, Io, Java, Maple, Matlab, Perl6, PHP5, Pike, Prolog, Python, Ruby, Scheme, Smalltalk Min / Max Mathematica minimum / maximum Haskell, Mercury, merd minimum-of / maximum-of Rebol min minstr / max maxstr(22) Perl min_element / max_element C++ - join a list of strings in a string using a glue string
join(s, l) Perl, Perl6, PHP String.Join(s, l) C# s.join(l) Python l.join(s) CoffeeScript, JavaScript, Perl6, Ruby l asStringWith: s Smalltalk join l s Tcl implode(s, l) PHP ListTools[Join] Maple rjoin E join Io concat F#, OCaml strcat Matlab concat_atom Prolog l * s Pike, Ruby (mapconcat 'identity l s) Emacs Lisp componentsJoinedByString Objective-C intercalate Haskell StringJoin @@ Riffle[l, s] Mathematica strings.Join Go - list size
size C++, Dylan, E, Io, Java, Matlab, merd, Pliant, Ruby, Scilab, Smalltalk, YCP sizeof Pike length C#, CoffeeScript, Common Lisp, Emacs Lisp, F#, Haskell, Java, JavaScript, Matlab, Mercury, OCaml, PostScript, Prolog, Ruby, Scheme, SML Length Ada, F#, Mathematica, Oz length? Rebol len Python, Vimscript llength Tcl $LENGTH MUMPS elems Perl6 getn Lua count Eiffel, FishShell, Objective-C, PHP, SQL92, XPath numel Matlab scalar @l Perl nops Maple # Lua
| len(l) | Go |
- iterate with index
each_with_index merd, Ruby enumerate(l) Python foreach($l as i=>i => i=>v) PHP a foreach(i, e, ...) Io for i => v in l E for (v in l, i from 0) ... end Dylan forAllInd Oz foreachi Lua foreach(l; typ0 i; typ1 v) { ... } Pike withIndexDo Squeak iteri F#, OCaml IterateIndexed F# MapIndexed Mathematica (loop for v in l as i upfrom 0 do ...) Common Lisp for v,i in l ... CoffeeScript for i, v := range l {...} Go - remove duplicates
uniq merd, Perl6, Pike, Ruby uniq! Ruby uniq2 Pike unique(106) C++, Io, Matlab, Rebol nub Haskell array_unique PHP ListTools[MakeUnique] Maple delete-duplicates Common Lisp, Scheme-SRFI1 delete-duplicates! Scheme-SRFI1 remove-duplicates Common Lisp, Dylan lsort -unique Tcl toset YCP distinct SQL92 set Python Union Mathematica - sort
sort(107) C#, C++, CoffeeScript, Common Lisp, E, Eiffel, F#, Haskell, Io, Java, JavaScript, Lua, Maple, Matlab, merd, OCaml, Perl, Perl6, PHP, Pike, Prolog, Python, Rebol, Ruby, Scheme, XSLT, YCP sort! Ruby sorted Python Sort Mathematica, Oz sort_by merd, Ruby sortBy Haskell, Io, Smalltalk order by SQL92 lsort Tcl asort Awk sort-object MSH sortedArrayUsingSelector, sortUsingSelector Objective-C predsort / keysort / mergesort Prolog - reverse
reverse C++, CoffeeScript, Common Lisp, Dylan, Emacs Lisp, Haskell, Io, Java, JavaScript, Logo, Mercury, merd, Perl, Perl6, Pike, Prolog, Python, Rebol, Ruby, Scheme Reverse C#, Mathematica, Oz reversed Python, Smalltalk reverse_copy C++ rev F#, OCaml, SML Reverse_Elements Ada lreverse Tcl8.5 array_reverse PHP ListTools[Reverse] Maple fliplr flipud... Matlab l[::-1] Python - list of couples from 2 lists
combine F#, OCaml zip F#, Haskell, Maple, merd, Perl6, Python, Ruby, Scheme-SRFI1, SML pairlis(108) Common Lisp transpose Ruby Transpose Mathematica [a b] Matlab - 2 lists from a list of couples
split F#, OCaml unzip F#, Haskell, merd, SML unzip2 Scheme-SRFI1 transpose Ruby Transpose Mathematica zip(*l) Python a(1,:), a(2,:) Matlab - lookup an element in a association list
lookup Haskell assoc Common Lisp, Emacs Lisp, F#, OCaml, Ruby, Scheme assq Emacs Lisp, Scheme assv Scheme get_assoc Prolog select Rebol a.(e) Matlab a[e] Maple gprop Logo /. Mathematica - list out of a bag
to_a Ruby toArray Java asArray Smalltalk to_list merd list Python map-as(, bag) Dylan [a.(:)] Matlab array get Tcl - f(... f(f(init, e1), e2) ..., en)
foldl Haskell, Maple, Mercury, merd, SML FoldL Oz fold_left OCaml fold F#, Scheme-SRFI1 Fold Mathematica reduce(109) Common Lisp, Dylan, Io, Perl, Perl6, Pike, Python inject Ruby inject into Smalltalk - f(e1, f(e2, ... f(en, init) ...))
foldr Haskell, Maple, Mercury, merd, SML FoldR Oz fold-right Scheme-SRFI1 fold_right OCaml foldBack F# rreduce Pike (reduce f '(e1 e2 ... en) :from-right t :initial-value init) Common Lisp reverseReduce Io
Various Data Types
- tuple type
typ1 * ... * typn F#, OCaml, SML (typ1, ..., typn) Haskell typ1, ..., typn merd tuple Python tuple! Rebol Tuple[Typ1, Typ2, Typ3] E tuple< typ1, ..., typn > C++-0x - tuple constructor
a, b, c F#, Lua, merd, OCaml, Python, Ruby ( a, b, c ) Ada, C++-0x, Haskell, Perl, Prolog, SML { a. b. c } Smalltalk { a, b, c } Matlab [ a, b, c ] E a . b . c Rebol (cons a b) Common Lisp - computable tuple (these are a kind of immutable lists playing a special role in parameter passing)
empty tuple() merd, Perl, Perl6, Python [] Ruby {} Matlab, Smalltalk #() Smalltalk
| Nothing | Prolog |
1-uple
a or [a] | Ruby |
---|---|
a, | Perl6, Python |
tuple([a]) | Python |
(a) | Perl |
((a)) | merd |
{a} | Smalltalk |
using a tuple for a function call | |
t | merd, Perl |
------------------------------ | ------------ |
*t | Python, Ruby |
t{:} | Matlab |
f @@ t | Mathematica |
L =.. [ F | Args ], call(L) | Prolog |
- reference (pointer)
creation& B, C, C#, C++, Go \ Perl AddressOf Visual Basic addr(110) Pascal @(110) Pascal lv BCPL ref C#, F#, OCaml, SML newSTRef Haskell NewCell Oz variable Forth 'access Ada :> :>> Pliant '' Maple dereference *(111) B, C, C#, C++, Go --------------------------------------- ----------------- $ @ % &(111) Perl ->[...] ->{...} ->(...)(112) Perl ->(113) C, C++ ^(112) Modula-3, Pascal F#, OCaml, SML rv BCPL readSTRef Haskell Access Oz .[all] Ada @ Forth eval Maple (reg) Assembler assigning (when dereferencing doesn't give a lvalue) writeSTRef Haskell ---------- -------------- Assign Oz := F#, OCaml, SML ! Forth - optional value
null value0(114) C++, Forth 0 nullptr(114) C++-0x NULL C, Maple, SQL92 nil Common Lisp, Emacs Lisp, Io, Lua, Objective-C, Ruby, Smalltalk null C#, CoffeeScript, Java, JavaScript Null(115) Ada, Mathematica undef Perl None F#, OCaml, Python NONE SML Nothing Haskell Void Eiffel #f () Emacs Lisp
| (empty) / ~ / null | YAML |
value
v | Ada, C#, CoffeeScript, Common Lisp, Eiffel, Emacs Lisp, Java, JavaScript, Lua, Perl, Perl, Python, Ruby, Scheme, Smalltalk |
---|---|
*v(114) | C, C++ |
Just v | Haskell |
Some v | F#, OCaml |
SOME v | SML |
type name | |
option | F#, OCaml, SML |
------ | -------------- |
Maybe | Haskell |
null coalescing | |
COALESCE | SQL92 |
--------------- | ---------------------- |
?: | PHP |
| | |
//(116) | Perl |
?? | C# |
if(a, b) | Visual Basic |
or | Python, Scheme |
- record
type declarationstruct { typ1 n1; typ2 n2; ... } C, C++ type typ = { n1 : typ1; n2 : typ2 } OCaml, SML data Typ = N0 { n1, n2 :: typ1, n3 :: typ3, ... } Haskell type Typ is record N1 : Typ1; N2 : Typ2 := default_val; ... end record; Ada type typ struct{ n1 typ1; n2 typ2; } Go selector . Ada, Beta, C, C#, C++, CoffeeScript, E, Eiffel, F#, Go, Java, JavaScript, Lua, Matlab, Modula-2, Modula-3, OCaml, Oz, Pascal, Python, Ruby -------------------- ------------------------------------------------------------------------------------------------------------------------------------------ :: XPath % Fortran90 '(117) Ada ^ Mercury r { field } merd r:field Pliant field r Haskell -> C, C++ r[field] Maple r["field"] JavaScript #field r SML
| normal function call | Common Lisp, Dylan, Haskell, Io, Smalltalk |
- union type declaration
union { typ1 n1; typ2 n2; ... } C, C++ data Typ = N1 typ1 | N2 typ2 ... Haskell type typ = N1 of typ1 | N2 of typ2 ... OCaml datatype typ = N1 of typ1 | N2 of typ2 ... SML type Typ (Choice : Discrete_Type) is record case Choice is when Choice_1 => N1 : Typ1; ... when Choice_2 | Choice_3 => ... when others => ... end case; end record; Ada - enumerated type declaration
enum typ { n1; n2; ... }(118) C, C#, C++, Java Enum typ n1 n2 End Enum Visual Basic (n1, n2, ...) Pascal type typ is(119) Ada data Typ = N1 | N2 ... Haskell type typ = N1 | N2 ... OCaml datatype typ = N1 | N2 ... SML - dictionary
type namemap Go, YAML Map F#, Io std::map C++ dict Python Dictionary Pliant, Smalltalk dictionary Vimscript Hash Perl6, Ruby HASH Perl HASH_TABLE Eiffel HashTable Java Hashtbl F# Hashtbl.t OCaml struct Matlab table Maple array PHP Data.Map, Data.HashTable Haskell Containers.Ordered_Maps.Map Ada constructor [ a => b, c => d ] E ------------------------------------------------------------- ------------------------------------------------- array( a => b, c => d ) PHP { a => b, c => d } Perl, Perl6, Ruby { a, b, c, d } Perl, Ruby { a: b, c: d } CoffeeScript, JavaScript, Python, Vimscript, YAML { a: b; c: d } CSS $[ a: b, c: d ] YCP { a->b. c->d } Squeak { a = b, c = d } Lua @{ a = b; c = d } MSH ([ a:b, c:d ]) Pike ([a]=b [c]=d) KornShell << a b c d >> PostScript struct(a, b, c, d) Matlab Hash[ a, b, c, d ] Ruby Map.of_list [a, b; c, d] F# Hashtbl.of_list [a, b; c, d] F# table([a=b, c=d]) Maple define table foo a => b; c => d end Dylan dict create a b c d Tcl8.5 new t { {a, b}, {c, d} } C# fromList Haskell [NSDictionary dictionaryWithObjectsAndKeys:b, a, d, c, nil] Objective-C a: b c: d YAML map[typ0]typ1{ a: b, c: d } Go access: read/write h[k] Awk, C#, C++, CoffeeScript, Dylan, E, Go, JavaScript, Lua, Maple, MSH, PHP, Python, Ruby, Vimscript ---------------- --------------------------------------------------------------------------------------------------- $h{k} Perl %h{k} or %h Perl6 h(k) Tcl h.[k] F# h.k CoffeeScript, JavaScript, Lua, Matlab h:k Pliant h["k"] or h->k Pike (gethash k h) Common Lisp access: read h k get PostScript ------------------------------------------- ------------- find F#, OCaml fetch Ruby get Java dict get Tcl8.5 at Io, Smalltalk h@k or h.at(k) Eiffel h[k]:default YCP ${h[k]} KornShell h.get(k, returned_value_when_k_unfound) Python objectForKey Objective-C lookup Haskell Element Ada access: write h k o put PostScript -------------------------- -------------- put Eiffel, Java add, replace F#, OCaml store Ruby dict set Tcl8.5 h[k] KornShell, YCP atPut Io h at: k put: o Smalltalk [h setObject:o forKey:k] Objective-C insert Haskell Replace_Element Ada has the key ? exists $h{k} Perl --------------------------------------- -------------------------------- exists Perl6, Pliant dict exists Tcl8.5 has Eiffel haskey YCP hasKey Io has_key Python, Vimscript has_key?, include?, key?, member? Ruby Contains Ada, C#, F# containsKey Java includesKey Smalltalk k in h CoffeeScript, JavaScript, Python k not in h Python in Awk mem F#, OCaml member Haskell isfield Matlab find(120) C++ h[k] Pike (gethash k h) Common Lisp maps E known PostScript isset(h[k]), array_key_exists(k, h) PHP v, exists := h[k] Go remove by key delete $h{k} Perl ------------------ ---------------------------------------------- del h[k] Python unset(h[k]) PHP remove Eiffel, F#, Java, OCaml, YCP Remove C#, F# dict remove Tcl8.5 removeAt Io removeKey E, Smalltalk remhash Common Lisp delete CoffeeScript, Haskell, JavaScript, Perl6, Ruby Delete Ada erase C++ m_delete Pike removeObjectForKey Objective-C undef PostScript rmfield Matlab delete(h, k) Go list of keys keys Haskell, Io, Maple, MSH, Perl, Perl6, Python, Ruby, Smalltalk --------------------------------- ------------------------------------------------------------- dict keys Tcl8.5 keySet Java allKeys Objective-C AllKeys C# indices Pike current_keys Eiffel getKeys E array_keys PHP fieldnames Matlab findall(Key, item(Key, _), Keys) Prolog ${!h[@]} KornShell list of values values Io, Java, Perl, Perl6, Pike, Python, Ruby, Smalltalk ------------- ---------------------------------------------------- dict values Tcl8.5 getValues E content Eiffel array_values PHP struct2cell Matlab entries Maple elems Haskell ${h[@]} KornShell merge merge(121) Ruby ------------------------- ------------ array_merge(121) PHP union(122) Haskell update(121) Python, Ruby putAll(121) Java insert(122) C++ (%h1, %h2)(121) Perl - range
inclusive .. inclusivea .. b Ada, E, merd, MSH, Pascal, Perl, Ruby a:b Matlab [ a .. b ] CoffeeScript, F#, Haskell to Io, Smalltalk seq a b / jot - a b(123) BourneShell, FishShell {a..b} KornShell range PHP range(from: a, to: b, by: step) Dylan Range Mathematica Range with Io List.number A B Step Oz numlist / between Prolog iseq Logo k, v := range h Go inclusive .. exclusive a ... b CoffeeScript, Ruby ------- ------------------ a ..! b E range Python
Mathematics
- type name
integersshort, int, long C, C# int OCaml, PHP, SML, YAML Int Perl6 Int, uInt, Int8, Int16... Pliant int, long(124) Python integer Maple, PHP INTEGER, INT, SMALLINT SQL92 INTEGER, INTEGER_8, NATURAL_8... Eiffel int8, uint8, int16, uint16, ...64 Go, Matlab int8_t, uint8_t, int16_t, uint16_t, ...64 C99 int, int8, uint8, int16, uint16, int32, uint32, int64, uint64, bigint, bignum F# Int, Integer, Int8, Int16, Int32, Int64 Haskell Integer, FixNum, BigNum Ruby Integer, SmallInteger, LargeInteger Smalltalk Integer Mathematica type T is range Low...High; Ada number Vimscript floating point float, double, long double C -------------------------------------------------------- --------------------------------------- float, double C# float Maple, OCaml, PHP, SML, Vimscript, YAML Float Ruby float, float32 F# Float, Float32, Float64 Pliant NUMERIC, DECIMAL, DOUBLE PRECISION SQL92 Rat Perl6 DOUBLE, REAL Eiffel single, double Matlab Float, Double, Ratio Haskell Float, Double, Fraction, FixedPoint Smalltalk float, decimal.Decimal Python Real, Rational Mathematica Number Io type T is digits N range Low..High; Ada type T is delta S digits N range Low..High;(125) Ada float32, float64 Go - numbers syntax
integers1000 Awk, B, BourneShell, C, C#, C++, CoffeeScript, E, Eiffel, F#, Forth, Go, Haskell, Io, Java, JavaScript, Logo, Maple, Mathematica, merd, OCaml, Oz, Pascal, Perl, Perl6, PHP, Pike, Pliant, Prolog, Python, Rebol, Ruby, Scheme, Smalltalk, SQL92, Tcl, Yorick 1000, 1000. Common Lisp, Emacs Lisp 1000, 1000., 1000.0 Awk, Matlab 1000, '1000'D Classic REXX 1000, 1E3 Ada integers in base 2, octal and hexadecimal 0b1, 07, 0xf(126) CoffeeScript, Oz, Perl, PHP5, Pike, Ruby ------------------------- ---------------------------------------- 0b1, 0o7, 0xf F#, OCaml, Perl6 07, 0xf Awk, C, C++, JavaScript, Python, Tcl 0xf C#, E, Go, Io, Yorick 07 B 0o7, 0xf Haskell 1b Eiffel 2#1#, 8#7#, 16#f# Ada 2#{1}, #{F} Rebol #b1, #o7, #xf Common Lisp, Emacs Lisp, Scheme
| 2^^1, 8^^7, 16^^f | Mathematica |
| 2r1, 8r7, 16rf | Smalltalk |
| #2r1, #8r7, #16rf | Common Lisp, Emacs Lisp |
| 1b, Fh | Pliant |
| '1'B, 'F'X | Classic REXX |
| B'1', X'F' | SQL92 |
| $f | Forth |
integer thousand-separator
1_000, 10_00, 100_0 | Ada, E, Eiffel, OCaml, Perl, Perl6, Ruby |
---|---|
1'000, 10'00, 100'0 | Rebol |
1_000 | merd |
floating point | |
1000., 1E3 | C, C++, Classic REXX, CoffeeScript, E, F#, Go, Java, JavaScript, Logo, Maple, OCaml, Python, Scheme, SQL92, Tcl |
------------------------------ | --------------------------------------------------------------------------------------------------------------- |
1000., 1E3, 1,0 | Rebol |
1000., 1.E3 | Eiffel, Oz |
1000.0, 1E3 | C#, Common Lisp, Emacs Lisp, PHP, Pike, Prolog, Ruby, Smalltalk |
1000.0, 1.0E3 | Ada, Haskell |
1000, 1000.0, 1E3(127) | Awk, merd, Perl, Perl6 |
1000., 1*^3, 1000` | Mathematica |
1000e, 1e3 | Forth |
- addition / subtraction / multiplication / division
+ / - / * / / BourneShell, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, D, Eiffel, Emacs Lisp, F#, Forth, Go, Haskell, Io, Java, JavaScript, Logo, Maple, Matlab, merd, MUMPS, Perl, Perl6, PHP, Pliant, Prolog, Python, Ruby, Scheme, Smalltalk, SQL92, Tcl, Vimscript, Yorick + / - / * or nothing / / Mathematica + +. / - -. / * *. / / /.(128) OCaml sum / difference / product / quotient Logo add / sub / mul / idiv div PostScript f+ / f- / f* / f/ Forth - exponentiation (power)
** Ada, Classic REXX, E, F#, Fortran, Io, merd, OCaml, Perl, Perl6, PL/I, Prolog, Python, Rebol, Ruby, Tcl8.5 ^ Awk, Dylan, Eiffel, Lua, Mathematica, Matlab, Pliant, Yorick *(129) APL **, ^ Maple ^^ D **, ^ and ^^(130) Haskell f** Forth pow C, C++, CoffeeScript, Java, JavaScript, PHP, Pike, Python, SML, Tcl Pow C#, Oz power Delphi-Kylix, Logo, Rebol exp PostScript expt Common Lisp, Emacs Lisp, Scheme raisedTo Smalltalk math.Pow Go - negation
- Ada, Awk, B, BCPL, BourneShell, C, C#, C++, Classic REXX, CoffeeScript, Common Lisp, D, E, Eiffel, Emacs Lisp, F#, Go, Haskell, Io, Java, JavaScript, Logo, Maple, Mathematica, Matlab, merd, MUMPS, Perl, Perl6, PHP, Pike, Pliant, Prolog, Python, Rebol, Ruby, Scheme, Smalltalk, Tcl, Vimscript, Yorick - -. OCaml ~ Oz, SML neg PostScript negate Forth, Rebol fnegate Forth minus Logo - random
random numberrand C, Maple, Matlab, Perl, Perl6, PHP, Ruby, Tcl random Common Lisp, Logo, Prolog, Python, Yorick $RANDOM MUMPS randomR Haskell Random(131) Ada Random.int OCaml Random, RandomReal, RandomInteger Mathematica Random value Io Random new nextInteger Smalltalk r: RANDOM create r.make r.start r.item Eiffel Random ran = new Random(); ran.Next(...); C# let r = System.Random() r.Next() F# mt_rand PHP rand.Read(132) Go seed the pseudo random generator srand C, Perl, Perl6, PHP, Ruby, Tcl ------------------------------------------ ------------------------------ set_seed Eiffel random.seed Python Random setSeed Io Random.init, Random.self_init OCaml rand('state',...) Matlab rerandom Logo RandomTools[MersenneTwister][SetState] Maple Random new setSeed Smalltalk SeedRandom Mathematica mkStdGen Haskell make-random-state Common Lisp Reset Ada rand.Seed(133) Go - operator priorities and associativities
addition vs multiplicationmathematical BourneShell, C, C#, C++, Classic REXX, Eiffel, F#, Go, Haskell, Io, Java, Maple, Mathematica, Matlab, merd, Perl, Perl6, PHP, Python, Ruby, Tcl, Yorick same priorities MUMPS, Smalltalk exponentiation vs negation (is -3^2 equal to 9 or -9) mathematical Classic REXX, Eiffel, Haskell, Io, Maple, Mathematica, Matlab, Perl, Perl6, Python, Ruby -------------- ---------------------------------------------------------------------------------------- negation first F#, OCaml - square root / e-exponential / absolute value
sqrt / exp / abs Ada, C, C++, CoffeeScript, Common Lisp, E, Eiffel, Emacs Lisp, F#, Haskell, Io, Java, JavaScript, Lua, Maple, OCaml, Pascal, Perl, Perl6, PHP, Prolog, Python, Ruby, Scheme, Smalltalk, SML, Tcl, Yorick sqrt realsqrt / exp / abs Matlab sqrt / exp / Awk, Logo Sqrt / Exp / Abs C#, Mathematica, Oz sqrt / / abs PostScript Sqrt / / ABS Modula-3 / exp / abs Pliant sqrt / / Pike square-root / exp / abs or absolute Rebol Sqrt / Exp / ABS Classic REXX sqrt,isqrt / exp / abs Tcl8.5 fsqrt / fexp / abs,fabs Forth math.Sqrt Go - trigonometry
basicsin / cos / tan Ada, C, C++, CoffeeScript, Common Lisp, E, Emacs Lisp, F#, Haskell, Io, Java, JavaScript, Lua, Maple, Matlab, OCaml, Pascal, Perl, Perl6, PHP, Pike, Pliant, Prolog, Python, Ruby, Scheme, Smalltalk, SML, Tcl, Yorick Sin / Cos / Tan C#, Classic REXX, Mathematica, Oz sin / cos / Awk, PostScript sine / cosine / tangent Eiffel, Rebol radsin / radcos / radtan Logo fsin / fcos / ftan Forth math.Sin / math.Cos / math.Tan Go inverse asin / acos / atan(134) Ada, C, C++, CoffeeScript, Common Lisp, F#, Haskell, Io, JavaScript, Matlab, OCaml, Perl, Perl6, Pike, Pliant, Prolog, Python, Ruby, Scheme, Tcl, Yorick -------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------- Asin / Acos / Atan C#, Oz ASin / ACos / ATan Classic REXX arcsin / arccos / arctan Maple arcSin / arcCos / arcTan Smalltalk ArcSin / ArcCos / ArcTan Mathematica arcsine / arccosine / arctangent Rebol arc_sine / arc_cosine / arc_tangent Eiffel / / atan PostScript / / radarctan Logo fasin / facos / fatan Forth math.Asin / math.Acos / math.Atan Go - logarithm
base eln Delphi-Kylix, Logo, Maple, Pascal, PostScript, Smalltalk, SML log Awk, C, C++, CoffeeScript, Common Lisp, E, Eiffel, Emacs Lisp, F#, Io, Java, JavaScript, Lua, Maple, Matlab, OCaml, Perl, Perl6, PHP, Pike, Pliant, Prolog, Python, Ruby, Scheme, Tcl, Yorick Log Ada, C#, Classic REXX, Mathematica, Oz log 10 Haskell log-e Rebol fln Forth math.Log Go base 10 log10 C, C++, Delphi-Kylix, Eiffel, F#, Io, Logo, Lua, Matlab, OCaml, Perl, Perl6, PHP, Pliant, Prolog, Python, Ruby, Tcl, Yorick --------------------------- --------------------------------------------------------------------------------------------------------------------------- Log10 C#, Classic REXX log PostScript, SML log: 10 Smalltalk log-10 Rebol log[10] Maple Log[10, val] Mathematica logBase 10 Haskell Log(X => val, Base => 10.0) Ada (log x 10) Common Lisp flog Forth math.Log10 Go base 2 log2 Matlab -------------------------- ----------- log-10 / log-2 Rebol Log(X => val, Base => 2.0) Ada log(val, 2) Python Log[2, val] Mathematica frexp C math.Log2 Go - euclidean division (both quotient and modulo)
divmod Python, Ruby divMod Haskell div ldiv lldiv C IntInf.quotrem SML floor Common Lisp, Dylan /mod Forth Div(135) Go - modulo
modulo of -3 / 2 is 1% Classic REXX, Perl, Perl6, Pike, Python, Ruby, Tcl %% E \\ Smalltalk mod Ada, Common Lisp, Emacs Lisp, Haskell, Matlab, Prolog, SML Mod Mathematica MOD Modula-3 modulo Dylan, Logo, Ruby rem Prolog modulo of -3 / 2 is -1 % Awk, B, C, C#, C++, CoffeeScript, E, F#, Go, Io, Java, JavaScript, PHP, Pliant, Yorick --------- -------------------------------------------------------------------------------------- # MUMPS
| mod | F#, Forth, Lua, OCaml, Oz, Pascal, PostScript, Prolog, XPath |
| remainder | Logo, Ruby, Scheme |
| rem | Ada, BCPL, Haskell, Matlab, Smalltalk |
| // | Classic REXX, Rebol |
| \\ | Eiffel |
- truncate / round / floor / ceil
trunc / round / floor / ceil C, C++, Maple, Matlab truncate / round / floor / ceiling Common Lisp, Haskell, Perl6, PostScript, Prolog, Scheme int / round / floor / ceil CoffeeScript, JavaScript, Pike, Python int / round / / Logo to_i, Integer() / round / floor / ceil Ruby TRUNC / FORMAT / Floor / Ceil Classic REXX Float'Truncation / Float'Rounding / Float'Floor / Float'Ceiling(136) Ada / round / floor / ceil E, Io, Java, Lua, PHP, SML, Tcl / Round / Floor / Ceiling C# / Round / Floor / Ceil Oz / round / floor / ceiling Dylan, Emacs Lisp, PostScript, XPath / ROUND / FLOOR / CEILING Modula-3 / rounded / floor / ceiling Eiffel, Smalltalk int / / floor / ceil F#, Perl int_of_float / / floor / ceil F#, OCaml / / floor / ceil Lua, Yorick IntegerPart / Round / Floor / Ceiling Mathematica / Rounding / Floor / Ceiling Ada to-integer / / / Rebol / fround / / Forth math.Trunc / / math.Floor / math.Ceil Go - bitwise operators
and / or / xor& / | / ^ C, C#, C++, CoffeeScript, E, Eiffel, Go, Java, JavaScript, Perl, PHP, Pike, Python, Ruby, Tcl & / | / ~ Yorick & / | YCP +& / +| / +^ Perl6 .&. / .|. / xor(137) Haskell &&& / | and / or / xor Ada, Forth, PostScript, Rebol land / lor / lxor F#, OCaml logand / logior / logxor(138) Common Lisp bitand / bitor / bitxor Logo, Matlab BITAND / BITOR / BITXOR Classic REXX BitAnd / BitOr / BitXor Mathematica bitAnd / bitOr / bitXor Smalltalk bitwiseAnd / bitwiseOr / bitwiseXor Io /\ / \/ / xor Prolog bitwise inversion ~ C, C#, C++, CoffeeScript, Java, JavaScript, Perl, PHP, Pike, Python, Ruby, SML, Tcl, YCP ------------------- ---------------------------------------------------------------------------------------- ~~~ F# not Ada, Eiffel, PostScript lnot F#, OCaml lognot(139) Common Lisp bitnot Eiffel, Logo BitNot Mathematica complement Haskell, Rebol bitcmp Matlab bitInvert Smalltalk bitwiseComplement Io invert Forth \ Prolog left shift / right shift / unsigned right shift << / >> / >>> CoffeeScript, Java, JavaScript ------------------------------------------------------------------------------------ --------------------------------------------------------------- << / >> C, C#, C++, Go, Perl, PHP, Pike, Prolog, Python, Ruby, Tcl, YCP <<< / >>> F# |<< / >> lsl / lsr or asr F#, OCaml bitshift Matlab, PostScript bitShift Smalltalk ashift lshift Logo lshift / rshift Forth shiftL / / shiftR Haskell shiftLeft / shiftRight Io Shift_Left / Shift_Right / Shift_Right_Arithmetic / Rotate_Left / Rotate_Right Ada (ash x positive-integer) / (ash x negative-integer) / Common Lisp
Threads
- thread definition
class class_name(threading.Thread) {[override run method] } Python task task_name is [entry entry_name[(parameter ...)]...] end task_name Ada task type task_type_name is [entry entry_name[(parameter ...)]...] end task_type_name Ada class class_name extends Thread {[override run method] } Java thread ... Pliant parallel [threads nb_threads] [mini mini_threshold] [maxi maxi_threshold] [active] ... task parallel_instructions [post sequential_instructions] ... Pliant [NSThread detachNewThreadSelector:mainFunction toTarget:target withObject:obj] Objective-C - thread creation
object t=Thread.Thread(f) Pike set t [thread create {code}] Tcl Thread createThread(...) Io - thread object creation
MyTask : task_type_name; Ada class_name MyThread = new class_name() Java p := [ ... ] newProcess. Smalltalk p := [ ... ] fork.(140) Smalltalk - starting / stopping threads
start() / stop()(141) Java resume / suspend / terminate Smalltalk Tasks are started when created / call Stop entry or "abort task-object-name" Ada thread send $t {script} Tcl - passing data directly between threads
call an entry with parameters Ada call any public method Java common variables are copied at thread creation, in abscence of a "share" statement Pliant use messages, parameters or shared variables(142) Smalltalk - terminating thread communication due to a time-out
select task_entry_call; or delay timeout_limit; end select; Ada - Thread Synchronization
Defining a Synchronized Shared Resourcethread::mutex Tcl protected Object_Name is [entry entry_name(Parameter : [in out] is type [...]); procedure procedure_name(Parameter : [in out] is type [...]); function function_name return type; private shared data declaration end Object_Name; Ada synchronize (this){ ... } Java SharedQueue, Semaphore critical: [...], Future, LazyValue Smalltalk Synchronized Writing to a shared resource Object_Name.Entry_Name(Parms)Object_Name.Procedure_Name(Parms) Ada ------------------------------------------------------------------ ---- Object_Name.SetMethod(Parms) Java Synchronized Reading of a Shared Resource Object_Name.Function_Name Ada --------------------------- ---- Object_Name.GetMethod() Java Monitor Syntax Objectg_Name.Entry_Name(Parms) Ada -------------------------------- --- - Joining Another Thread
Suspending a thread until another thread completesCall task entry serviced just before task termination Ada OtherThread.join() Java, Python Suspending a Thread Until Another Thread Establishes An Internal State Call a task entry on the other thread Ada ------------------------------------- --- - Thread Prioritization
Selecting a Prioritization Modelpragma Locking_Policy(Ceiling_Locking); Ada Establishing a base thread priority pragma Priority(expression); Ada ---------------------------- --- Changing Thead Priority Set_Priority(Priority_Value); Ada ------------------------------- --------- setPriority(newPriority); Java p priority: n Smalltalk - Thread-safe sharing of data without synchronization
Ensuring access is atomicpragma Atomic(Object_Name); Ada Ensuring access is always via a local copy of the shared data pragma Volatile(Object_Name); Ada ------------------------------ ---
Remarks
- (1) introduced in Scheme in R6RS
- (2) when unused
- (3) for C, it is not a standard convention, but it is the more widespread
- (4) any string literal would work
- (5) see also =head1, =head2, =over, etc
- (6) need "file: %script-header.r" in file header
- (7) for user defined functions only
- (8) displayed <- with a special character
- (9) variable on the right
- (10) F#: with indentation
- (11) the variable behaves like a pointer
- (12) cf horizontal layout
- (13) introduce scope
- (14) Smalltalk: introduce scope
- (15) ascii representation, original uses a special charset
- (16) in Modula-2, <> and # are synonyms
- (17) === and !== differ from == and != when the objects' type differ
- (18) for objects
- (19) normal / structural / unification / arithmetic
- (20) structural / mathematical
- (21) deep comparison
- (22) in List::Util
- (23) just 'eval' evaluates JavaScript
- (24) Univ operator
- (25) starting with PHP 5.3
- (26) procedure call
- (27) in Pliant, special sugar for only one parameter
- (28) only for one parameter
- (29) only for two parameters
- (30) f is a block
- (31) Python >= 2.5
- (32) it does not scale to 3rd argument
- (33) lambda (x . y) ...
- (34) only final parameter may be variadic and accepts zero or more arguments
- (35) when callee has special "&" prototype
- (36) this is a block, not precisely a function, but it's alike
- (37) manual declaration of local variables wanted in the closure
- (38) see also: #1 + #2 &
- (39) also works for procedures: proc {$ A B} ... end
- (40) x, y, z are the parameters
- (41) method is optional
- (42) in Lua, "return xxx" can only appear before a block end. in Matlab, only in inline('...')
- (43) "return" is used when there is no value to return
- (44) in Matlab, only for anonymous function
- (45) firefox
- (46) C#4, only for "dynamic" objects
- (47) the result goes to "e"
- (48) "break"s are mandatory, even for "default"!
- (49) Perl >= 5.8.0
- (50) 1 is optional in this example, since min is 1 by default
- (51) in Ruby, see also catch/throw
- (52) often provided in the abbreviated form call/cc
- (53) matches an expression of type t
- (54) type is infered
- (55) expression "e" is cast to the type of "v"
- (56) for parameters
- (57) quite bad: only the reference is non-mutable whereas the object is still mutable
- (58) eventual send
- (59) properties are something alike attributes, but really are methods
- (60) one level depth
- (61) general deep copy function
- (62) object cloning is the default, uses the copy constructor in C++
- (63) or simply o_ := o for non-polymorphic objects
- (64) c'Class is the class rooted in c
- (65) see also isMemberOf
- (66) assignment attempt
- (67) see also callable(obj.meth) for unbound methods
- (68) in Python, usually called self
- (69) ":" is for external symbols only, recommended
- (70) directory name is package name
- (71) if names are exported using @EXPORT
- (72) if names are not exported or are exported using @EXPORT_OK
- (73) deprecated in ANSI Common Lisp, but used in ASDF
- (74) using a correspondance from the package name to the file name
- (75) inside a function
- (76) since PHP 5.3
- (77) no spaces
- (78) when using format
- (79) need expandMacros
- (80) where T is the type of the value
- (81) see also cPickle
- (82) but not using the C-like %-syntax
- (83) adding an end-of-line
- (84) in BourneShell, adding an end-of-line
- (85) adding an end-of-line unless already newline-terminated
- (86) Always case insensitive
- (87) Always case sensitive
- (88) faster than isEqual
- (89) the string is represented on the stack as (addr len)
- (90) in Lua >= 5.0
- (91) in C++, is range-checked whereas a[i] is not
- (92) ESI dialect
- (93) beware of 0.0 which is true in Pike!
- (94) Smalltalk: postfix operator
- (95) in Modula-2, "&" and "and" are synonyms
- (96) in Oz, simple functions, not operators
- (97) new in PHP 5.4
- (98) restricted to initialisation of a local variable in C and C++
- (99) a b c must be constants
- (100) beware, if you give only one integer argument, it is the size!
- (101) for write access: a i o put
- (102) in C++, it is range-checked whereas a[i] is not. in Smalltalk, for write access: a :at i :put o
- (103) see also Head
- (104) list comprehension
- (105) not in standard
- (106) in C++, it is done in place
- (107) in Scheme, not standard, but nearly standard
- (108) the result is not guaranteed to be the same as the order in the input
- (109) in Perl, in List::Util
- (110) Borland extension in Pascal
- (111) prefix
- (112) postfix
- (113) infix
- (114) optional value is only for pointers
- (115) only for "access" types in Ada
- (116) introduced in Perl 5.10
- (117) attribute selector
- (118) Java: introduced in 1.5
- (119) n1, n2, ...
- (120) returns an iterator
- (121) right-bias
- (122) left-bias
- (123) jot on BSD
- (124) long is a big integer
- (125) fixed point
- (126) 0b1 new in PHP 5.4
- (127) integers are decimals
- (128) with mathematical priorities
- (129) APL uses a real multiplication sign for multiplication from a special character set
- (130) for each various types
- (131) from instances of Ada.Numerics.Float_Random or Ada.Numerics.Discrete_Random
- (132) "math/rand" is pseudo random whereas "crypto/rand" is cryptographically random
- (133) only applies to "math/rand"
- (134) Ruby >= 1.7
- (135) method on big.Int
- (136) replace Float with whatever type you are using
- (137) in module Data.Bits
- (138) see also bit-and / bit-or / bit-xor
- (139) see also bit-not
- (140) equivalent to newProcess + resume
- (141) "stop" is now deprecated
- (142) a thread is created from a block, which is a closure on the variables as seen by the block
Similar Pages
- Belorussian translation of this page
- Comparison of programming languages syntax
- Comments and Literals in programming languages
- The Surface of Programming Languages
- Delphi, VisualBasic, C++, Java
- SML, OCaml
- Java, C++, Smalltalk
- Java, C#
- Java, C#
- Ruby, Java, Perl
- Python, Perl
- Python, Lisp
- PL/I, C
- Perl, PHP
- EmacsLisp, Perl
- Smalltalk, Lisp
- Tasks in many languages
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 (BourneShell, Common Lisp, ...)
- Ian Henderson (Objective C)
- Anthony Borla (Classic REXX, Prolog, Logo)
- Paul McJones (Modula-3 fixes)
- Uwe Kolb (Smalltalk fixes)
- Ciaran McNulty (PHP)
- David B. Nagle (Yorick)
- Michael Schaufelberger (Eiffel)
- Samuel Charron (Erlang)
- Kyle Ross (OCaml)
- Damien Krotkine (Ruby)
- Guillaume Cottenceau (Java)
- David.Whitten (MUMPS)
- Phil Howard (various)
- Andrzej Zawadzki (Ruby)
- Stuart Brady (VisualBasic)
- Joris Gillis (Maple)
- Garrett Wollman (Ruby, BourneShell, C...)
- Claus Gittinger (Smalltalk)
- Bobby 'nneonneo' Xiao (Python)
- Michael Schlenker (Tcl)
- Alex Vondrak (Python)
- Daniel Laberge (Pascal)
- Daniel Wagner (Haskell)
- Bob Bane (Common Lisp)
- Alan Hogan (Java)
- Steve Davison (C)
- Konstantin Yegupov (PHP, Python...)
- Noé Rubinstein (Io, CoffeeScript)
- Florentin Millour (Yorick)
- Axel Liljencrantz (FishShell)
- Sanghyeon Seo (Lua)
- Szabolcs Horvát (Mathematica)
- Laurent Le Brun (F#, GNU-sed)
- Julien Hall (Smalltalk)
- Ian Osgood (Forth)
- Dmitry A. Kazakov (Ada)
- Peter Hermann (Ada)
- Ian Jackson (Tcl, Perl, C, Assembler...)
- Steve Breese
- Nils M Holm (Scheme, ...)
- Stas Malyshev (PHP5)
- Adam Woodbeck (Go)
This work is licensed under a Creative Commons Attribution-ShareAlike 2.0 Generic License.
Generated from <syntax-across-languages.html.pl>