### Example global configuration search path Source: https://docs.julialang.org/en/v1/manual/environment-variables Example global configuration search path for a Linux installation with SYSCONFDIR=../etc. ```text /etc/julia/startup.jl ``` -------------------------------- ### Example source-file search path Source: https://docs.julialang.org/en/v1/manual/environment-variables Example source-file search path for a Linux installation with JULIA_BINDIR=/bin and DATAROOTDIR=../share. ```text /share/julia/base ``` -------------------------------- ### Load and use the Example package Source: https://docs.julialang.org/en/v1/stdlib/Pkg Loads the installed Example package into the Julia session and calls the `hello` function, which returns the string "Hello, friend". ```julia julia> import Example julia> Example.hello("friend") "Hello, friend" ``` -------------------------------- ### Inline setup with setup option Source: https://docs.julialang.org/en/v1/devdocs/contributing/jldoctests Use the `setup =` option to include small setup expressions inline in a jldoctest block. The example shows using `:(using InteractiveUtils)` to make InteractiveUtils available. ```julia ```jldoctest; setup = :(using InteractiveUtils) ... ``` ``` -------------------------------- ### pwd() example - Get and change working directory Source: https://docs.julialang.org/en/v1/base/file Example showing pwd() and cd() usage. The output shows the current directory before and after changing. ```julia julia> pwd() "/home/JuliaUser" julia> cd("/home/JuliaUser/Projects/julia") julia> pwd() "/home/JuliaUser/Projects/julia" ``` -------------------------------- ### Add packages to tutorial environment and check status Source: https://docs.julialang.org/en/v1/stdlib/Pkg Adds Example and JSON to the tutorial environment, then shows the status output listing the installed packages with their versions. ```julia (tutorial) pkg> add Example JSON ... (tutorial) pkg> status Status `~/tutorial/Project.toml` [7876af07] Example v0.5.3 [682c06a0] JSON v0.21.3 ``` -------------------------------- ### schedule and yield example Source: https://docs.julialang.org/en/v1/base/parallel Example usage of `schedule` and `yield` to run a task. Shows that after scheduling and yielding, the task is started and done. ```julia julia> a5() = sum(i for i in 1:1000); julia> b = Task(a5); julia> istaskstarted(b) false julia> schedule(b); julia> yield(); julia> istaskstarted(b) true julia> istaskdone(b) true ``` -------------------------------- ### Add a package with `add` Source: https://docs.julialang.org/en/v1/stdlib/Pkg Adds the Example package using the `add` command in the Pkg REPL. The output shows the package being installed and the Project.toml and Manifest.toml files being updated. ```julia (@v1.10) pkg> add Example Resolving package versions... Installed Example ─ v0.5.3 Updating `~/.julia/environments/v1.10/Project.toml` [7876af07] + Example v0.5.3 Updating `~/.julia/environments/v1.10/Manifest.toml` [7876af07] + Example v0.5.3 ``` -------------------------------- ### Status and upgrade with `up` Source: https://docs.julialang.org/en/v1/stdlib/Pkg Shows the status output when an older version of Example is installed, indicating a newer version is available with the ⌃ marker, and then the `up` command upgrades the package from v0.5.1 to v0.5.3. ```julia (@v1.10) pkg> st Status `~/.julia/environments/v1.10/Project.toml` ⌃ [7876af07] Example v0.5.1 Info Packages marked with ⌃ have new versions available and may be upgradable. (@v1.10) pkg> up Updating `~/.julia/environments/v1.10/Project.toml` [7876af07] ↑ Example v0.5.1 ⇒ v0.5.3 ``` -------------------------------- ### DocTestSetup meta block Source: https://docs.julialang.org/en/v1/devdocs/contributing/jldoctests Use the `DocTestSetup` meta block for longer setup code or when multiple blocks require the same environment. The example imports Random and seeds it. ```markdown ```@meta DocTestSetup = :(import Random; Random.seed!(1234)) ``` ``` -------------------------------- ### get! with do-block example Source: https://docs.julialang.org/en/v1/base/collections Example of get! with a do-block that computes and stores a default value. Shows the function definition and the resulting dictionary. ```julia julia> squares = Dict{Int, Int}(); julia> function get_square!(d, i) get!(d, i) do i^2 end end get_square! (generic function with 1 method) julia> get_square!(squares, 2) 4 julia> squares Dict{Int64, Int64} with 1 entry: 2 => 4 ``` -------------------------------- ### Generate and set up the Example package Source: https://docs.julialang.org/en/v1/stdlib/Test Commands to generate a new package named Example, change into its directory, create a test folder, and activate the package environment. ```julia pkg> generate Example shell> cd Example shell> mkdir test pkg> activate . ``` -------------------------------- ### get with default example Source: https://docs.julialang.org/en/v1/base/collections Example of get with a default value. Returns the stored value for an existing key and the default for a missing key. ```julia julia> d = Dict("a"=>1, "b"=>2); julia> get(d, "a", 3) 1 julia> get(d, "c", 3) 3 ``` -------------------------------- ### get! with default example Source: https://docs.julialang.org/en/v1/base/collections Example of get! with a default value. Returns the existing value for an existing key and stores the default for a missing key. ```julia julia> d = Dict("a"=>1, "b"=>2, "c"=>3); julia> get!(d, "a", 5) 1 julia> get!(d, "d", 4) 4 julia> d Dict{String, Int64} with 4 entries: "c" => 3 "b" => 2 "a" => 1 "d" => 4 ``` -------------------------------- ### Get short name of a branch example Source: https://docs.julialang.org/en/v1/stdlib/LibGit2 Example showing how to get the short name of a branch reference. It creates a GitRepo, gets the head reference, and shows that LibGit2.shortname returns "master" while LibGit2.name returns "refs/heads/master". ```julia julia> repo = GitRepo(path_to_repo); julia> branch_ref = LibGit2.head(repo); julia> LibGit2.name(branch_ref) "refs/heads/master" julia> LibGit2.shortname(branch_ref) "master" ``` -------------------------------- ### Example output of versioninfo() Source: https://docs.julialang.org/en/v1/devdocs/backtraces Shows the expected output of `versioninfo()` on a Linux system, including version, commit, build info, platform, CPU, LLVM, GC, threads, and environment variables. ```text Julia Version 1.13.0 Commit d1c37793dd2 (2026-09-09 19:00 UTC) Build Info: Official https://julialang.org release Platform Info: OS: Linux (x86_64-linux-gnu) CPU: 128 × AMD EPYC 7502 32-Core Processor WORD_SIZE: 64 LLVM: libLLVM-20.1.8 (ORCJIT, znver2) GC: Built with stock GC Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores) Environment: JULIA_DEPOT_PATH = /cache/julia-buildkite-plugin/depots/019ebd63-635e-4155-b60a-9d2815900786: JULIA_CPU_THREADS = 12 JULIA_NUM_THREADS = 1 ``` -------------------------------- ### LibGit2.url example Source: https://docs.julialang.org/en/v1/stdlib/LibGit2 Example usage of LibGit2.url showing how to get the fetch URL of a remote. ```julia julia> repo_url = "https://github.com/JuliaLang/Example.jl"; julia> repo = LibGit2.init(mktempdir()); julia> remote = LibGit2.GitRemote(repo, "origin", repo_url); julia> LibGit2.url(remote) "https://github.com/JuliaLang/Example.jl" ``` -------------------------------- ### LibGit2.fetch_refspecs example Source: https://docs.julialang.org/en/v1/stdlib/LibGit2 Example usage of LibGit2.fetch_refspecs showing how to get the fetch refspecs for a remote. ```julia julia> remote = LibGit2.get(LibGit2.GitRemote, repo, "upstream"); julia> LibGit2.add_fetch!(repo, remote, "upstream"); julia> LibGit2.fetch_refspecs(remote) String["+refs/heads/*:refs/remotes/upstream/*"] ``` -------------------------------- ### Create a simple TCP server with listen and accept Source: https://docs.julialang.org/en/v1/manual/networking-and-streams Starts a TCP server on port 2000 using `listen` and accepts connections in a loop, printing "Hello World\n" for each connection. The server runs in a spawned task wrapped with `errormonitor`. ```julia julia> using Sockets julia> errormonitor(Threads.@spawn begin server = listen(2000) while true sock = accept(server) println("Hello World\n") end end) Task (runnable) @0x00007fd31dc11ae0 ``` -------------------------------- ### readdir examples - List directory contents with various options Source: https://docs.julialang.org/en/v1/base/file Examples showing readdir() with default, join=true, and with a directory argument. Outputs are truncated with ⋮. ```julia julia> cd("/home/JuliaUser/dev/julia") julia> readdir() 30-element Vector{String}: ".appveyor.yml" ".git" ".gitattributes" ⋮ "ui" "usr" "usr-staging" julia> readdir(join=true) 30-element Vector{String}: "/home/JuliaUser/dev/julia/.appveyor.yml" "/home/JuliaUser/dev/julia/.git" "/home/JuliaUser/dev/julia/.gitattributes" ⋮ "/home/JuliaUser/dev/julia/ui" "/home/JuliaUser/dev/julia/usr" "/home/JuliaUser/dev/julia/usr-staging" julia> readdir("base") 145-element Vector{String}: ".gitignore" "Base.jl" "Enums.jl" ⋮ "version_git.sh" "views.jl" "weakkeydict.jl" julia> readdir("base", join=true) 145-element Vector{String}: "base/.gitignore" "base/Base.jl" "base/Enums.jl" ⋮ "base/version_git.sh" "base/views.jl" "base/weakkeydict.jl" julia> readdir(abspath("base"), join=true) 145-element Vector{String}: "/home/JuliaUser/dev/julia/base/.gitignore" "/home/JuliaUser/dev/julia/base/Base.jl" "/home/JuliaUser/dev/julia/base/Enums.jl" ⋮ "/home/JuliaUser/dev/julia/base/version_git.sh" "/home/JuliaUser/dev/julia/base/views.jl" "/home/JuliaUser/dev/julia/base/weakkeydict.jl" ``` -------------------------------- ### Connect to the server and observe output Source: https://docs.julialang.org/en/v1/manual/networking-and-streams Connects to the server created on port 2000 using `connect(2000)`. The server prints "Hello World" upon accepting the connection. ```julia julia> connect(2000) TCPSocket(open, 0 bytes waiting) julia> Hello World ``` -------------------------------- ### Google Jules Initial Setup Source: https://docs.julialang.org/en/v1/devdocs/contributing/aiagents Configuration commands for the initial setup of Google Jules. ```bash curl -fsSL https://install.julialang.org | sh -s -- -y --default-channel nightly . /home/swebot/.profile ``` -------------------------------- ### displaysize with stdout example Source: https://docs.julialang.org/en/v1/base/io-network Example of displaysize called with stdout to get the TTY size, returning (34, 147) in this case. ```julia julia> displaysize(stdout) (34, 147) ``` -------------------------------- ### Activate a new environment with `activate` Source: https://docs.julialang.org/en/v1/stdlib/Pkg Activates a new environment named `tutorial` using the `activate` command. The environment is created relative to the current working directory, and the REPL prompt changes to reflect the new active environment. ```julia (@v1.10) pkg> activate tutorial [ Info: activating new environment at `~/tutorial/Project.toml`. ``` -------------------------------- ### Artifacts.artifact_path Source: https://docs.julialang.org/en/v1/stdlib/Artifacts Function to get the installation path of an artifact. ```APIDOC ## `Artifacts.artifact_path` — Function ### Description Given an artifact (identified by SHA1 git tree hash), return its installation path. If the artifact does not exist, returns the location it would be installed to. ### Signature ``` artifact_path(hash::SHA1; honor_overrides::Bool=true) ``` ### Parameters - `hash::SHA1` - Required - The SHA1 git tree hash of the artifact. - `honor_overrides::Bool` - Optional - Whether to honor overrides. Defaults to `true`. ### Returns - The installation path of the artifact, or the location it would be installed to if it does not exist. ``` -------------------------------- ### Use REPL help mode Source: https://docs.julialang.org/en/v1/manual/getting-started Switch to help mode by pressing `?` at an empty `julia>` prompt. Typing a keyword like `begin` fetches its documentation and examples. ```julia help?> begin search: begin disable_sigint reenable_sigint begin begin...end denotes a block of code. ``` -------------------------------- ### Create and run a Julia startup file Source: https://docs.julialang.org/en/v1/manual/command-line-interface Creates a startup file that prints a greeting whenever Julia is launched. The output shows the greeting printed after running `julia`. The `~/.julia/config` folder and `startup.jl` file may need to be created manually if they do not exist. ```bash $ echo 'println("Greetings! 你好! 안녕하세요?")' > ~/.julia/config/startup.jl $ julia Greetings! 你好! 안녕하세요? ... ``` -------------------------------- ### Check task started with istaskstarted Source: https://docs.julialang.org/en/v1/base/parallel Example for `istaskstarted`: creates a task from a function that sums 1 to 1000 and checks that it has not started executing. ```julia julia> a3() = sum(i for i in 1:1000); julia> b = Task(a3); julia> istaskstarted(b) false ``` -------------------------------- ### thisind examples Source: https://docs.julialang.org/en/v1/base/strings Examples of thisind: returns start index for in-bounds indices, rewinds for non-start indices, and throws BoundsError for out-of-bounds. ```julia julia> thisind("α", 0) 0 julia> thisind("α", 1) 1 julia> thisind("α", 2) 1 julia> thisind("α", 3) 3 julia> thisind("α", 4) ERROR: BoundsError: attempt to access 2-codeunit String at index [4] [...] julia> thisind("α", -1) ERROR: BoundsError: attempt to access 2-codeunit String at index [-1] [...] ``` -------------------------------- ### mkdir example Source: https://docs.julialang.org/en/v1/base/file Example of mkdir creating a directory and then changing into it. The function returns the path string, and the directory is created with default permissions. ```julia julia> mkdir("testingdir") "testingdir" julia> cd("testingdir") julia> pwd() "/home/JuliaUser/testingdir" ``` -------------------------------- ### Install toolchain binaries Source: https://docs.julialang.org/en/v1/devdocs/sanitizers Run these commands to install the toolchain binaries (clang, clang++, llvm-symbolizer) into $TOOLCHAIN_WORKTREE/usr/tools. ```bash cd $TOOLCHAIN_WORKTREE make -C deps install-llvm install-clang install-llvm-tools ``` -------------------------------- ### strides usage example Source: https://docs.julialang.org/en/v1/base/arrays Example showing how to use strides to get the tuple of memory strides for a 3x4x5 array filled with ones. ```julia julia> A = fill(1, (3,4,5)); julia> strides(A) (1, 3, 12) ``` -------------------------------- ### splitext examples Source: https://docs.julialang.org/en/v1/base/file Examples of splitext showing how it handles a simple extension, a double extension, and a path with a dot in the directory name. ```julia julia> splitext("/home/myuser/example.jl") ("/home/myuser/example", ".jl") julia> splitext("/home/myuser/example.tar.gz") ("/home/myuser/example.tar", ".gz") julia> splitext("/home/my.user/example") ("/home/my.user/example", "") ``` -------------------------------- ### fullname examples Source: https://docs.julialang.org/en/v1/base/base Examples of using fullname to get the fully-qualified name of a module. For Base.Iterators it returns (:Base, :Iterators), and for Main it returns (:Main,). ```julia julia> fullname(Base.Iterators) (:Base, :Iterators) julia> fullname(Main) (:Main,) ``` -------------------------------- ### Get detailed help for `develop` with `?develop` Source: https://docs.julialang.org/en/v1/stdlib/Pkg Shows detailed help for the `develop` command. ```julia (@v1.10) pkg> ?develop ``` -------------------------------- ### Base64DecodePipe example Source: https://docs.julialang.org/en/v1/stdlib/Base64 Example of using Base64DecodePipe to decode base64 data from an IOBuffer. The stream is read after seeking to the start, and the decoded bytes are converted to a string. ```julia julia> io = IOBuffer(); julia> iob64_decode = Base64DecodePipe(io); julia> write(io, "SGVsbG8h") 8 julia> seekstart(io); julia> String(read(iob64_decode)) "Hello!" ``` -------------------------------- ### cd example - Change directory and show pwd Source: https://docs.julialang.org/en/v1/base/file Example showing cd() with and without arguments, and the resulting pwd() output. ```julia julia> cd("/home/JuliaUser/Projects/julia") julia> pwd() "/home/JuliaUser/Projects/julia" julia> cd() julia> pwd() "/home/JuliaUser" ``` -------------------------------- ### Example: Get GitBlob from tree entry Source: https://docs.julialang.org/en/v1/stdlib/LibGit2 Example usage of constructing a GitTree from a repository and a revision, accessing its first entry, and converting that entry to a GitBlob. ```julia tree = LibGit2.GitTree(repo, "HEAD^{tree}") tree_entry = tree[1] blob = LibGit2.GitBlob(tree_entry) ``` -------------------------------- ### Ask Pkg for help with `?` Source: https://docs.julialang.org/en/v1/stdlib/Pkg Displays a list of available Pkg commands with short descriptions. ```julia (@v1.10) pkg> ? ``` -------------------------------- ### stride usage example Source: https://docs.julialang.org/en/v1/base/arrays Example showing how to use stride to get the memory stride for dimensions 2 and 3 of a 3x4x5 array filled with ones. ```julia julia> A = fill(1, (3,4,5)); julia> stride(A,2) 3 julia> stride(A,3) 12 ``` -------------------------------- ### Specify start index in match Source: https://docs.julialang.org/en/v1/manual/strings Shows how to specify a starting index for the search. The examples find the first digit at offsets 1, 6, and 11 respectively. ```julia julia> m = match(r"[0-9]","aaaa1aaaa2aaaa3",1) RegexMatch("1") julia> m = match(r"[0-9]","aaaa1aaaa2aaaa3",6) RegexMatch("2") julia> m = match(r"[0-9]","aaaa1aaaa2aaaa3",11) RegexMatch("3") ``` -------------------------------- ### Build documentation with make docs Source: https://docs.julialang.org/en/v1/devdocs/contributing/documentation Run from Julia's root directory to rebuild the system image, install dependencies, and generate HTML documentation in doc/_build/html/. Recommended before opening a pull request. ```bash make docs ``` -------------------------------- ### tril(M, k) function with examples Source: https://docs.julialang.org/en/v1/stdlib/LinearAlgebra Returns the lower triangle of M starting from the kth superdiagonal. The example shows the output for k=3 and k=-3 on a 4x4 matrix of ones. ```julia tril(M, k::Integer = 0) ``` ```julia julia> a = fill(1.0, (4,4)) 4×4 Matrix{Float64}: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 julia> tril(a,3) 4×4 Matrix{Float64}: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 julia> tril(a,-3) 4×4 Matrix{Float64}: 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 ``` -------------------------------- ### triu(M, k) function with examples Source: https://docs.julialang.org/en/v1/stdlib/LinearAlgebra Returns the upper triangle of M starting from the kth superdiagonal. The example shows the output for k=3 and k=-3 on a 4x4 matrix of ones. ```julia triu(M, k::Integer = 0) ``` ```julia julia> a = fill(1.0, (4,4)) 4×4 Matrix{Float64}: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 julia> triu(a,3) 4×4 Matrix{Float64}: 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 julia> triu(a,-3) 4×4 Matrix{Float64}: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ``` -------------------------------- ### Profile.Allocs.start function syntax Source: https://docs.julialang.org/en/v1/stdlib/Profile Function to begin recording allocations with a given sample rate. A sample rate of 1.0 records everything; 0.0 records nothing. ```julia Profile.Allocs.start(sample_rate::Real) ``` -------------------------------- ### get usage example Source: https://docs.julialang.org/en/v1/base/scopedvalues Example of using `ScopedValues.get` to retrieve the current value. Shows that a value with a default returns `Some(value)` and an unset value returns `nothing`. ```julia julia> using Base.ScopedValues julia> a = ScopedValue(42); b = ScopedValue{Int}(); julia> ScopedValues.get(a) Some(42) julia> isnothing(ScopedValues.get(b)) true ``` -------------------------------- ### Pkg REPL prompt for tutorial environment Source: https://docs.julialang.org/en/v1/stdlib/Pkg The Pkg REPL prompt after activating the `tutorial` environment, showing the new active environment name. ```julia (tutorial) pkg> ``` -------------------------------- ### getalladdrinfo(host::AbstractString) with example Source: https://docs.julialang.org/en/v1/stdlib/Sockets Gets all IP addresses of the host, using the OS's getaddrinfo implementation which may do a DNS lookup. The example shows the result for google.com. ```julia getalladdrinfo(host::AbstractString) -> Vector{IPAddr} ``` ```julia julia> getalladdrinfo("google.com") 2-element Vector{IPAddr}: ip"172.217.6.174" ip"2607:f8b0:4000:804::200e" ``` -------------------------------- ### pkgdir examples Source: https://docs.julialang.org/en/v1/base/base Shows pkgdir(Foo) returning the package root and pkgdir(Foo, "src", "file.jl") returning a path within the package root. ```julia julia> pkgdir(Foo) "/path/to/Foo.jl" julia> pkgdir(Foo, "src", "file.jl") "/path/to/Foo.jl/src/file.jl" ``` -------------------------------- ### code_typed examples with tuples Source: https://docs.julialang.org/en/v1/base/base Shows how to call code_typed with a tuple of argument types to get the corresponding CodeInfo. The examples cover addition, subtraction, type conversion, and a Returns object. ```julia julia> code_typed(+, (Float64, Float64)) 1-element Vector{Any}: CodeInfo( 1 ─ %1 = Base.add_float(x, y)::Float64 └── return %1 ) => Float64 julia> code_typed((typeof(-), Float64, Float64)) 1-element Vector{Any}: CodeInfo( 1 ─ %1 = Base.sub_float(x, y)::Float64 └── return %1 ) => Float64 julia> code_typed((Type{Int}, UInt8)) 1-element Vector{Any}: CodeInfo( 1 ─ %1 = Core.zext_int(Core.Int64, x)::Int64 └── return %1 ) => Int64 julia> code_typed((Returns{Int64},)) 1-element Vector{Any}: CodeInfo( 1 ─ %1 = builtin Base.getfield(obj, value)::Int64 └── return %1 ) => Int64 ``` -------------------------------- ### eachcol usage example Source: https://docs.julialang.org/en/v1/base/arrays Example of eachcol on a 2x2 matrix, showing the resulting ColumnSlices object and indexing to get a column view. The output shows the type and contents of the slices. ```julia julia> a = [1 2; 3 4] 2×2 Matrix{Int64}: 1 2 3 4 julia> s = eachcol(a) 2-element ColumnSlices{Matrix{Int64}, Tuple{Base.OneOf{Int64}}, SubArray{Int64, 1, Matrix{Int64}, Tuple{Base.Slice{Base.OneOf{Int64}}, Int64}, true}}: [1, 3] [2, 4] julia> s[1] 2-element view(::Matrix{Int64}, :, 1) with eltype Int64: 1 3 ``` -------------------------------- ### open example with mode strings Source: https://docs.julialang.org/en/v1/base/io-network Example usage of open with mode strings 'w', 'r', and 'a'. Demonstrates writing, reading, and appending, and shows an error when writing to a read-only stream. ```julia julia> io = open("myfile.txt", "w"); julia> write(io, "Hello world!"); julia> close(io); julia> io = open("myfile.txt", "r"); julia> read(io, String) "Hello world!" julia> write(io, "This file is read only") ERROR: ArgumentError: write failed, IOStream is not writeable [...] julia> close(io) julia> io = open("myfile.txt", "a"); julia> write(io, "This stream is not read only") 28 julia> close(io) julia> rm("myfile.txt") ``` -------------------------------- ### eachrow usage example Source: https://docs.julialang.org/en/v1/base/arrays Example of eachrow on a 2x2 matrix, showing the resulting RowSlices object and indexing to get a row view. The output shows the type and contents of the slices. ```julia julia> a = [1 2; 3 4] 2×2 Matrix{Int64}: 1 2 3 4 julia> s = eachrow(a) 2-element RowSlices{Matrix{Int64}, Tuple{Base.OneTo{Int64}}, SubArray{Int64, 1, Matrix{Int64}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}}: [1, 2] [3, 4] julia> s[1] 2-element view(::Matrix{Int64}, 1, :) with eltype Int64: 1 2 ``` -------------------------------- ### Threads.@spawn example with tasks Source: https://docs.julialang.org/en/v1/base/multi-threading Demonstrates spawning multiple tasks with Threads.@spawn and fetching their results. The example prints the thread ID from each task, showing that tasks may run on different threads. The output shows the thread IDs from a sample run. ```julia julia> t() = println("Hello from ", Threads.threadid()); julia> tasks = fetch.([Threads.@spawn t() for i in 1:4]); Hello from 1 Hello from 1 Hello from 3 Hello from 4 ``` -------------------------------- ### IOContext custom property example Source: https://docs.julialang.org/en/v1/base/io-network Example demonstrating how to read custom properties from an `IOContext` using `get`. The function `f` prints different text based on the `:short` property. ```julia julia> function f(io::IO) if get(io, :short, false) print(io, "short") else print(io, "loooooong") end end f (generic function with 1 method) julia> f(stdout) loooooong julia> f(IOContext(stdout, :short => true)) short ``` -------------------------------- ### Run Julia installer with arguments Source: https://docs.julialang.org/en/v1/manual/installation Runs the Julia installer with command line arguments. Replace with options such as --yes, --default-channel, --add-to-path, --background-selfupdate, --startup-selfupdate, or --path. ```shell curl -fsSL https://install.julialang.org | sh -s -- ``` -------------------------------- ### Generate a minimal working example (MWE) with Pkg Source: https://docs.julialang.org/en/v1/devdocs/precompile_hang Use the Pkg REPL command 'generate MWE' to create a new package skeleton. The output shows the generated project files: MWE/Project.toml and MWE/src/MWE.jl. ```julia (@v1.10) pkg> generate MWE Generating project MWE: MWE\Project.toml MWE\src\MWE.jl ``` -------------------------------- ### remotecall_wait WorkerPool example Source: https://docs.julialang.org/en/v1/stdlib/Distributed Example usage of remotecall_wait with a WorkerPool. Starts Julia with 3 processes, creates a WorkerPool, and calls remotecall_wait to compute the maximum of a random array, then fetches the result. ```julia $ julia -p 3 julia> wp = WorkerPool([2, 3]); julia> A = rand(3000); julia> f = remotecall_wait(maximum, wp, A) Future(3, 1, 9, nothing) julia> fetch(f) 0.9995177101692958 ``` -------------------------------- ### UnitRange type definition and examples Source: https://docs.julialang.org/en/v1/base/collections Defines UnitRange with start and stop of type T, spaced by 1. The syntax a:b with both integers creates a UnitRange. The example shows collect and typeof results. ```julia UnitRange{T<:Real} ``` ```julia julia> collect(UnitRange(2.3, 5.2)) 3-element Vector{Float64}: 2.3 3.3 4.3 julia> typeof(1:10) UnitRange{Int64} ``` -------------------------------- ### Using the hello world package Source: https://docs.julialang.org/en/v1/manual/command-line-interface Shows that using the package with 'using Hello' executes the @main function, while 'import Hello' does not because execution depends on the binding. ```bash $ julia -e 'using Hello' Hello from the package! $ julia -e 'import Hello' # N.B.: Execution depends on the binding not whether the package is loaded $ ``` -------------------------------- ### Reactivate the Example environment Source: https://docs.julialang.org/en/v1/stdlib/Test Commands to return to the root of the Example package and reactivate its environment before running tests. ```julia shell> cd .. pkg> activate . ``` -------------------------------- ### remotecall_fetch WorkerPool example Source: https://docs.julialang.org/en/v1/stdlib/Distributed Example usage of remotecall_fetch with a WorkerPool. Starts Julia with 3 processes, creates a WorkerPool, and calls remotecall_fetch to compute the maximum of a random array, returning the result directly. ```julia $ julia -p 3 julia> wp = WorkerPool([2, 3]); julia> A = rand(3000); julia> remotecall_fetch(maximum, wp, A) 0.9995177101692958 ``` -------------------------------- ### Example: show vs print for strings Source: https://docs.julialang.org/en/v1/base/io-network Example REPL session showing the difference between show and print for a string. show includes quotes, print does not. ```julia julia> show("Hello World!") "Hello World!" julia> print("Hello World!") Hello World! ``` -------------------------------- ### StepRange type definition and examples Source: https://docs.julialang.org/en/v1/base/collections Defines StepRange with constant step, start, and stop. The syntax a:b:c with b != 0 and all integers creates a StepRange. The example shows collect and typeof results. ```julia StepRange{T, S} <: OrdinalRange{T, S} ``` ```julia julia> collect(StepRange(1, Int8(2), 10)) 5-element Vector{Int64}: 1 3 5 7 9 julia> typeof(StepRange(1, Int8(2), 10)) StepRange{Int64, Int8} julia> typeof(1:3:6) StepRange{Int64, Int64} ``` -------------------------------- ### range() examples with various keyword arguments Source: https://docs.julialang.org/en/v1/base/math Shows the output of `range` with different combinations of `start`, `stop`, `step`, and `length`. Demonstrates that when `length` is not specified and `stop - start` is not an integer multiple of `step`, the range ends before `stop`. ```julia julia> range(1, length=100) 1:100 julia> range(1, stop=100) 1:100 julia> range(1, step=5, length=100) 1:5:496 julia> range(1, step=5, stop=100) 1:5:96 julia> range(1, 10, length=101) 1.0:0.09:10.0 julia> range(1, 100, step=5) 1:5:96 julia> range(stop=10, length=5) 6:10 julia> range(stop=10, step=1, length=5) 6:1:10 julia> range(start=1, step=1, stop=10) 1:1:10 julia> range(; length = 10) Base.OneTo(10) julia> range(; stop = 6) Base.OneTo(6) julia> range(; stop = 6.5) 1.0:1.0:6.0 ```