Julia

Julia is another language I learned for fun, it's quite good but it starts it arrays at 1 instead of 0 so I could never really like it,


Here are some functions I grabed from my .julia/config/startup.jl

here is some Julia code it hooks in a c library and runs getenv


"""

getenv gets the value of an environment variable

Author Francis Grizzly Smit <grizzlysmit@smit.id.au>

"""

function getenv(var::AbstractString)

"""

calls the systems getenv in libc-2.29

"""

val = ccall((:getenv, "libc-2.29"), Cstring, (Cstring,), var)

if val == C_NULL

error("getenv: undefined variable: ", var)

end

return unsafe_string(val)

end

and here is some code that calls ls and runs ls -Flahi


"""

list the contents of directory path if path is "" or not supplied

list the current dir.

An option options may be supplied this can contain either a single

-- option or multiple bunched up one - options

i.e.

lg(;options="--color") or lg(;options="-dt")

the options -Flahi will always be supplied

Author Francis Grizzly Smit <grizzlysmit@smit.id.au>

"""

function lg(path::AbstractString = ""; options::AbstractString = "")

if path == "" && options == ""

run(`ls -Flahi`)

elseif path != "" && options == ""

run(`ls -Flahi $path`)

elseif path == "" && options != ""

run(`ls -Flahi $options`)

else

run(`ls -Flahi $options $path`)

end

end

and this is a command that runs ping and then responds to the exceptions

I treat the InterruptException differently because in Unix/Linux you stop ping via a ctrl-C as it otherwise goes on for ever.

"""

ping domain if domian is not supplied pings julialang.org

Author Francis Grizzly Smit <grizzlysmit@smit.id.au>

"""

function ping(domain::AbstractString = "julialang.org")

try

run(`ping $domain`)

catch e

if isa(e, InterruptException)

println("Done.")

elseif isa(e, ErrorException)

println("ErrorException")

println("e.msg: $(e.msg)")

flush(stdout)

#rethrow(e)

else

println("yeeerhaaa")

println("e: $e")

flush(stdout)

rethrow(e)

end

end

end