Code · 1 file

Sample Julia File

Julia is a fast dynamic language for numerical and scientific computing. The Julia sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.

Julia · 479 B

Sample Julia file

An idiomatic Julia example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.jl — first linesJulia
# Sample Julia script — samplefiles.com
using Printf

struct Customer
    id::Int
    name::String
    balance::Float64
end

isvip(c::Customer) = c.balance >= 10_000
total_balance(cs::Vector{Customer}) = sum(c -> c.balance, cs)

customers = [Customer(1, "Ada", 12_500), Customer(2, "Grace", 830.5), Customer(3, "Linus", 10_000)]
for c in customers
    @printf("%-6s %10.2f %s\n", c.name, c.balance, isvip(c) ? "VIP" : "")
end
@printf("Total: %.2f\n", total_balance(customers))

File details

Size
479 B (479 bytes)
MIME type
text/x-julia
SHA-256
d6cfb36a507d5bad5c07509b93517c02fd0638757fbd9c4b5705d0288236f550
MD5
98acf16eef682a6e4c3a5a61344b22fd

Download from the command line

curl -L -o sample.jl https://files.samplefiles.com/code/jl/sample.jl

Or check the download in your browser with the checksum calculator.