((3+4) * (5+6)) =>
(7 * (5+6)) =>
(7 * 11) =>
77
if ( B > 0 ) { |
A = 2; |
} |
else { |
A= 1; |
} |
|
|
|
|
while ( A > 0 ) { |
... |
} |
# the imperative way to build a list of the squares of the integers |
# 1 .. 10 |
squares = [] |
for x in range(10): |
squares.append(x**2) |
print(squares) |
|
# the functional way using list comprehension. The expression x**2 is |
# mapped over the list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
squares = [x**2 for x in range(10)] |
print(squares) |
|
|
# the imperative way to build a list of the squares of the integers |
# 1 .. 10 |
my @range = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); |
|
my @squares = (); |
foreach my $x ( @range ) { |
push @squares, $x * $x; |
} |
print("@squares\n"); |
|
# the functional way using list comprehension. The expression x**2 is |
# mapped over the list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
@squares = map { $_ * $_ } @range; |
print("@squares\n"); |
2. Programming Styles Notes on Functional Programming / Version 2.10 2014-02-24 |