Sunteți pe pagina 1din 23

* either the entry exist in the language, and please tell.

* either the entry doesn't exist in the language, and please tell so. The entry will be marked as such
and won't appear as missing anymore.

* Category: Object Oriented, Dynamically typed, Has anonymous functions

* Various

{ ... }(1) block (grouping statements, especially when statements are not expressions)
nothing needed breaking lines (useful when end-of-line and/or indentation has a special meaning)
# commenting (until end of line)
< > <= >= comparison
lt gt le ge comparison
min minstr / max maxstr(2) comparison (min / max (binary or more))
a <=> b comparison (returns 3 values (i.e. inferior, equal or superior))
cmp comparison (returns 3 values (i.e. inferior, equal or superior))

=pod
...
=cut

(3) documentation comment


== != equality / inequality (shallow)
incremental garbage collection => not needed force garbage collection
( ... ) grouping expressions
__LINE__ __FILE__ information about the current line and file
eval runtime evaluation
case-sensitive tokens (case-sensitivity (keywords, variable identifiers...))
[_a-zA-Z0-9]+ tokens (variable identifier regexp)
CamelCase for modules, ALL_CAPS for constants, unclear for functions / variables tokens (what is
the standard way for scrunching together multiple words)
do use a block as a return value (when statements are not expressions)
= variable assignment or declaration (assignment)
my / our / local / use vars variable assignment or declaration (declaration)

* Functions

sub { my ($a, $b) = @_; ... } anonymous function


{ my ($a, $b) = @_; ... }(4) anonymous function
f(a,b,...) function call
&$f(a,b,...) or $f->(a,b,...) function call
f a, b, ... function call
f function call (with no parameter)
f() function call (with no parameter)
&$f or $f->() function call (with no parameter)
AUTOLOAD function called when a function is not defined (in dynamic languages)
sub f { ... } function definition
sub f { ... @_ } function definition (variable number of arguments)
return(5) function return value (breaks the control flow)
no syntax needed(6) function return value (function body is the result)
caller runtime inspecting the caller information

* Control Flow

next / last breaking control flow (continue / break)


goto breaking control flow (goto (unconditional jump))
redo/ breaking control flow (redo / retry)
return(5) breaking control flow (returning a value)
eval {a}; if ($@) ... exception (catching)
die exception (throwing)
if (c) {...} if_then
... if c if_then
c and ... if_then
if (c) {b1} elsif (c2) {b2} else {b3} if_then_else
c ? b1 : b2 if_then_else
unless ifnot_then (unless)
do {...} until c loop (do something until condition)
for loop (for "a la C" (while + initialisation))
for (my $i = 10; $i >= 1; $i--) { ... } loop (for each value in a numeric range, 1 decrement)
foreach my $i (1 .. 10) { ... } loop (for each value in a numeric range, 1 increment (see also the
entries about ranges))
for (my $i = 1; $i <= 10; $i += 2) { ... } loop (for each value in a numeric range, free increment)
while (c) ... loop (while condition do something)

my %case = (
v1 => sub { ... },
v2 => sub { ... },
);
if ($case{val}) { $case{val}->() } else { ... }

multiple selection (switch)

use Switch;
switch ($val) {
case v1 { ... }
case v2 { ... }
else ...
})

(7) multiple selection (switch)


, sequence
; sequence

* Object Oriented & Reflexivity

$o->SUPER::method(...) accessing parent method


first parameter(8) current instance
ref get the type/class corresponding to an object/instance/value
canhas the method
@ISA = qw(parent1 parent2) inheritance
DESTROY manually call an object's destructor
object->method(para) method invocation
object->method method invocation (with no parameter)
Storable::dclone object cloning
new class_name(...) object creation
isa testing class membership

* Package, Module

package p; declare
@ISA = qw(Exporter); @EXPORT = qw(name1 name2 ...); declare (selective export)
use p(9) import (everything into current namespace)
use p;(10) import (package (ie. load the package))
require p import (package (ie. load the package))
use p qw(name1 name2 ...) import (selectively)
:: package scope
' package scope

* Strings

chr ascii to character


ord character to ascii
Dumper convert something to a string (see also string interpolation)
"" . e convert something to a string (see also string interpolation)
x duplicate n times
substr extract a substring
index locate a substring
rindex locate a substring (starting at the end)
all strings allow multi-line strings multi-line
Storable::store serialize (marshalling)
print simple print (on simple objects)
printf simple print (printf-like)
sprintf sprintf-like
Storable::retrieve sprintf-like
. string concatenation
eq ne string equality & inequality
length string size
"\n" strings (end-of-line (without writing the real CR or LF character))
"... $v ..." strings (with interpolation of variables)
<<MARK ... $v ... MARK strings (with interpolation of variables)
qq(...(... $v ...)...), qq[...], qq{...}, qq<...>, qq/.../strings (with interpolation of variables)
'...' strings (with no interpolation of variables)
<<'MARK' ... MARK strings (with no interpolation of variables)
q(...(...)...), q[...], q{...}, q<...>, q/.../ strings (with no interpolation of variables)
Storable::store unserialize (un-marshalling)
uc / lc upper / lower case character
uc / lc uppercase / lowercase / capitalized string

* Booleans

undef false value


0(11) false value

"" false value


"0" false value
() false value
! logical not
not(12) logical not
|| / && logical or / and (short circuit)
or / and logical or / and (short circuit)
anything not false true value

* Bags and Lists

splice(@a, $i, 0, $e) adding an element at index (side-effect)


unshift adding an element at the beginning (list cons) (side-effect)
push adding an element at the end (side-effect)
reduce(13)f(... f(f(init, e1), e2) ..., en)
first(2) find an element
for for each element do something
foreach for each element do something
shift get the first element and remove it
pop get the last element and remove it
join(s, l) join a list of strings in a string using a glue string
grep keep elements (matching)
a[-1] last element
, list concatenation
[ a, b, c ] list constructor
( a, b, c ) list constructor
scalar @l list size
a[i]list/array indexing
reverse reverse
min minstr / max maxstr(2) smallest / biggest element
sort(14) sort
map transform a list (or bag) in another one

* Various Data Types

(a) computable tuple (these are a kind of immutable lists playing a special role in parameter
passing) (1-uple)
() computable tuple (these are a kind of immutable lists playing a special role in parameter
passing) (empty tuple)
t computable tuple (these are a kind of immutable lists playing a special role in parameter
passing) (using a tuple for a function call)
$h{k} dictionary (access: read/write)
{ a => b, c => d } dictionary (constructor)
{ a, b, c, d } dictionary (constructor)
exists $h{k} dictionary (has the key ?)
keys dictionary (list of keys)
values dictionary (list of values)
(%h1, %h2)(15) dictionary (merge)
delete $h{k} dictionary (remove by key)
undef optional value (null value)
v optional value (value)
v optional value (value)
a .. b range (inclusive .. inclusive)
\ reference (pointer) (creation)
$ @ % &(16) reference (pointer) (dereference)
->[...] ->{...} ->(...)(17) reference (pointer) (dereference)
( a, b, c ) tuple constructor

* Mathematics

+ / - / * / / addition / subtraction / multiplication / division


& / | / ^ bitwise operators (and / or / xor)
<< / >> bitwise operators (left shift / right shift / unsigned right shift)
~ bitwise operators (negation)
** exponentiation (power)
log10 logarithm (base 10)
log logarithm (base e)
% modulo (modulo of -3 / 2 is 1)
- negation
1000, 1000.0, 1E3(18) numbers syntax (decimals)
1_000, 10_00, 100_0 numbers syntax (integer thousand-seperator)

0b1, 07, 0xf numbers syntax (integers in base 2, octal and hexadecimal)
1000 numbers syntax (integers)
mathematical operator priorities and associativities (addition vs multiplication)
mathematical operator priorities and associativities (exponentiation vs negation (is -3^2 equal
to 9 or -9))
rand random (random number)
srand random (seed the pseudo random generator)
sqrt / exp / abs square root / e-exponential / absolute value
sin / cos / tan trigonometry (basic)
asin / acos / atan(19) trigonometry (inverse)
int / / floor / ceil truncate / round / floor / ceil

Remarks

* (1) introduce scope


* (2) in List::Util
* (3) see also =head1, =head2, =over, etc
* (4) when callee has special "&" prototype
* (5) in Lua, "return xxx" can only appear before a block end. in Matlab, only in inline('...')
* (6) in Matlab, only for anonymous function
* (7) Perl >= 5.8.0
* (8) in Python, usually called self
* (9) if names are exported using @EXPORT
* (10) if names are not exported or are exported using @EXPORT_OK
* (11) beware of 0.0 which is true in Pike!
* (12) Smalltalk: postfix operator
* (13) in Perl, in List::Util
* (14) in Scheme, not standard, but nearly standard
* (15) right-bias
* (16) prefix
* (17) postfix
* (18) integers are decimals
* (19) Ruby >= 1.7

Pixel
This document is licensed under GFDL (GNU Free Documentation License).
Generated from syntax-across-languages.html.pl
$Id: syntax-across-languages.html.pl 408 2008-08-29 08:32:23Z pixel $
robert
adhi
kusuma
putra
robert
adhi
kusuma
putra
robert
adhi
kusuma
putra
robert
adhi
kusuma
putra

S-ar putea să vă placă și