playing around with Julia
- Continue to build out Julia automation in GitHub Actions....
-
at least got Julia to build in GitHub Actions
-
try to get linting and/or CI/CD working for this repo. Use this GitHub Actions example.
Experiment trying to get linting via a Makefile
working
-
tldr; was able to get lint working in a
Makefile
inside of cli-tools directory. -
limitations: requires manual package install. no clue how to reproduce Julia package installs!
Basing the example from this guide of argparse
- Launch julia
- type in
]
(package manager mode) add ArgParse
- control-c to quit
Working example in cli-tools: ./calc.jl --num1 5 --num2 10
- Setup lint (not sure how to do it!) https://www.julia-vscode.org/docs/stable/userguide/linter/ https://github.com/aviatesk/JET.jl
help?> cos
search: cos cosh cosd cosc cospi acos acosh acosd sincos sincosd sincospi const close closewrite isconst copysign chopsuffix MathConstants coalesce
cos(x)
To see documentation use include, then do ?add
julia> include("./docJulia.jl")
TO DO: Figure out how to actually run Julia doctest.
include("./Hello.jl")
using .Hello
foo()
So for our example:
include("./testImport.jl")
Now try a directory:
include("./juliaModuleTest/hello.jl")
- to build libraries you build a directory
- to use them use just use the include command
include("./juliaModuleTest/hello.jl")
- Build an add tool called
cliJuliaAddNumbers.jl
- Try out argparse for Julia: https://carlobaldassi.github.io/ArgParse.jl/stable/
https://docs.julialang.org/en/v1/manual/types/
Cover exceptions and any final looping.
Control Flow: https://docs.julialang.org/en/v1/manual/control-flow/
compound expressions: z = (x = 1; y = 2; x + y)
z = begin
x = 1
y = 2
z = x + y
end
similar to python
z = x = 1; y = 2; x + y
Tenary Operator is fun to play with: https://docs.julialang.org/en/v1/manual/control-flow/#man-conditional-evaluation
Short Circuit: https://docs.julialang.org/en/v1/manual/control-flow/#man-conditional-evaluation
While Loop: https://docs.julialang.org/en/v1/manual/control-flow/#man-loops
i = 1;
while i <= 5
println(i)
global i+=1
end
(sqrt ∘ +)(3, 6)
1:10 |> sum |> sqrt
Let's break this down for newbies:
#Range 1:10
#sum function that sums an iterable/range sum
#sqrt function sqrt function that finds square root
julia> 1000 |> sqrt 31.622776601683793
julia> 1:1000 |> sum 500500
Each of the elements is then send to a separate function.
["a", "list", "of", "strings"] .|> [length, length, length, length]
https://docs.julialang.org/en/v1/manual/functions/#man-vectorized
julia> A = [1.0, 2.0, 3.0] sqrt.(A)
- Material for today on Julia Functions
- Download and add to path
- Try out julia from interactive prompt
julia
- Try out a "one-liner"
julia -e 'println(PROGRAM_FILE); for x in ARGS; println(x); end' foo bar
- Create a
hello.jl
- Create a binary from Julia code
- Strings and Numbers