1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-01-19 12:24:17 +00:00

72 lines
6.5 KiB
Julia
Raw Normal View History

2021-07-13 09:07:29 +02:00
x = 3
2020-10-05 16:23:01 +05:30
2021-07-13 09:07:29 +02:00
y = 2x
2020-10-05 16:23:01 +05:30
typeof(y)
2021-07-13 09:07:29 +02:00
f(x) = 2 + x
2020-10-05 16:23:01 +05:30
f
f(10)
2021-07-13 09:07:29 +02:00
function g(x, y)
 z = x + y
 return z^2
2020-10-05 16:23:01 +05:30
end
g(1, 2)
2021-07-13 09:07:29 +02:00
let s = 0
 for i in 1:10
 s += i # Equivalent to s = s + i
2020-10-05 16:23:01 +05:30
 end
2021-07-13 09:07:29 +02:00
 s
2020-10-05 16:23:01 +05:30
end
typeof(1:10)
function mysum(n)
2021-07-13 09:07:29 +02:00
 s = 0
 for i in 1:n
 s += i
2020-10-05 16:23:01 +05:30
 end
2021-07-13 09:07:29 +02:00
 return s
2020-10-05 16:23:01 +05:30
end
mysum(100)
2021-07-13 09:07:29 +02:00
a = 3
2020-10-05 16:23:01 +05:30
2021-07-13 09:07:29 +02:00
a < 5
2020-10-05 16:23:01 +05:30
2021-07-13 09:07:29 +02:00
if a < 5
2020-10-05 16:23:01 +05:30
 "small"
else
 "big"
end
2021-07-13 09:07:29 +02:00
v = [1, 2, 3]
2020-10-05 16:23:01 +05:30
typeof(v)
v[2]
v[2] = 10
2021-07-13 09:07:29 +02:00
v2 = [i^2 for i in 1:10]
2020-10-05 16:23:01 +05:30
2021-07-13 09:07:29 +02:00
M = [1 2
2020-10-05 16:23:01 +05:30
 3 4]
typeof(M)
zeros(5, 5)
2021-07-13 09:07:29 +02:00
zeros(Int, 4, 5)
2020-10-05 16:23:01 +05:30
2021-07-13 09:07:29 +02:00
[i + j for i in 1:5, j in 1:6]