June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,22 +1,8 @@
numbers = [1, 3, 5, 7]
square1 = [square(n) for n in numbers] # list comprehension
squares2a = map(square, numbers) # functional form
squares2b = map(x -> x*x, numbers) # functional form with `lambda`
#There is also extended block form for the map function
squares2c = map(numbers) do x
sum = 0
for i = 1:x
sum += x^2 #trivial, but you get the point
end
return sum
end
squares3 = [n * n for n in numbers] # no need for a function,
squares4 = numbers .* numbers # element-wise operation
squares4a = numbers .^ 2 # most arithmetic operations can be done element-wise
@show [n ^ 2 for n in numbers] # list comprehension
square(x) = x ^ 2; @show map(square, numbers) # functional form
@show map(x -> x ^ 2, numbers) # functional form with anonymous function
@show [n * n for n in numbers] # no need for a function,
@show numbers .* numbers # element-wise operation
@show numbers .^ 2 # includes .+, .-, ./, comparison, and bitwise operations as well