Julia Reference Card Page 2

ADVERTISEMENT

1.6 Arrays
function f(params) ... end
function definition
readsandwrite(command)
(its in, its out, process)
(homogeneous & type may be specified)/
f(x, y=0) = return x+y
optional parameter
detach(command)
run & outlive Julia process
Array(T, dims)
Uninitalized dense dim
f(a,b,c...) =
varargs c = [] or ()
setenv(command,env)
set vars for running
array of Type T
f(a,b; dir="nth") =
named args
ENV
EnvHash->EnvHash
Sys environment vars
Initialize different arrays (sometimes with T else just dims):
f(a,b; d=5,e...) =
varargs as of k,v tuples
getpid()
get Julias pid
zeros ones
trues
falses
rand randdf
randn
... |> (x,f)
apply fn to preceding args
clipboard(x)
print x to clipboard
eye
eye(n)
linspace(start, stop, n)
f(1,1), f(2), f(y=3, x=4)
function calls
s = clipboard()
or s from clipboard
Vector = 1 dim column array or cell is like a list in Python
(x) -> x+a
anonymous function
@time()
@elapsed()->secs
time and expression
Functions on arrays:
strftime([f,]time())
time as string
nnz (num non zero values) stride(A,n)
strides(A)
function make_adder_2(a)
closure, alternatively,
cd(f[,dir])
run f in temporary dir
ndims, transpose & ctranspose .' & '
add(b) = return a+b
function mkadr(a)
cell(dims ...)
uninitialized
return add
b -> a+b
Filesystem Operations
heterogeneous array
end
end
gethostname(), getipaddr(), pwd(), cd('dir'),
Array(Int32,0)
[]
{}
Empty array or cell
let v=1,w=" "... ; end
scope block with vars
mkdir(p,mode), mkpath(p,mode), rmdir(p),
reshape(A, dims)
new shape, same data
@time()
gc_disable()
report time elapsed
ignorestatus(cmd),
similar
reinterpret
@profile
Profile.print
profile, print & clear
redirect in run commands: |> std output, |>> append
[a,x] [a x]
{c,x} {c x}
add element
stdout, |.> stderr
to process, file or DevNull
a = [f(x,y,...) for x=rx,
array comprehensions
global v
bind to global variable
6 Input/Output
y=ry, ...]
: ... ; quote ... end
create an expression
1.7 DataFrames
(using DataFrames)
open(filename, mode)
open file (a & w create,
eval(expr)
evaluate expression
DataArray
NA
NAtype
Array with missing values
mode = r r+ w w+ a a+
+ is both r&w, w truncates)
DataFrame(A=1:4,B=[...])
Tabular hetero dataset
open(f(),args)
f(result of open args)
using name
fn()
load module namespace
removeNA
replaceNA(dv,val)
remove or replace NAs
close(stream)
flush and close
import name
name.fn()
import gives named access
failNA
write(stream, x)
write binary x to stream
require(filepath)
Load file once
df[2,"A"]
df[[rows,]1:2]
get & slice
writedlm writecsv
array, dlm with csv delimeter
reload(filepath)
and reload it
df[1:2,["A","B"]]
read(stream, type[,dims]) read value from stream
include(filepath)
set dir & load source
df[df["A"] % 2 .== 0, :]
readbytes readdlm readcsv nb bytes, array, csv
evalfile(file)
execute file
colnames!(df[,newnames])
read or insert col names
readall readline[s]
all as string, line or lines
cd("data") do
safely write file in a
head, tail, describe
position(s)
get position of a stream
open("outfile", "w") do f
directory and close after.
join(df..., jointype)
join two dataframes
seek(s, pos)
seek stream to position
write(f,data)
groupby(df,catvar)
split df by categorical var
seekstart(s),
seekend(s)
to start to end
end
by(df,catvar, df->f(df[]))
split and apply fn or
skip(s, offset)
seek relative
end
by(df,catvar,:(n=...; m=...))
expression to subset
isopen
eof
isreadonly
open? end of file? read only?
4 Exception Handling & Debugging
stack(df,categorical var)
reshape data
ltoh(x)
htol(x)
little endian conversions
readtable(fname,header=false,
defaults are true, comma
try ...
Try-block
[de]serialize(stream,val)
separator='\t')
also, writetable(f, fname)
catch [y]
catch exception as var
download(url[,localfile]) unix download
2 Basic Syntax
print data
+ others
error("...")
exception handling
if expr statements
Conditional
end
7 Areas Not Covered
elseif expr statements
; if on same line
finally ...
in any case
else statements end
terminate with end
@assert expression
debug assertion
z = cond ? x : y
ternary version
Julia has a dynamic type system but with a rich language of
throw(e)
explicit expection
z = ifelse(cond, x, y)
as ? but all args evaluated
types including parametric. Type declaration is optional so
using Debug
loads the debugger
z = cond && x
short circuit
the casual user can usually ignore it.
@debug
@bp
before module, set breakpt
Multiple dispatch permits methods to be called based on the
l
p var1, ...
list lines, print vars
while expr statements end
while loop
types of all unnamed arguments.
s
c
step into, continue to @bp
while true .. if cond break do .. while equivalent
Object orientated design can be achieved by combining type
5 System Interaction
for target in iter
for loop
definition and multiple dispatch to associate methods with
statements ; end
run(`cmd`) or ;cmd
system call
new classes of objects
for i=itr, j=itr ... end
over multiple variables
spawn(`cmd`)
run asynchronously
Tasks or Coroutines permit computations to be flexibly
for key in keys(d)...
over dictionary
success(`cmd`)
bool for exit condition
suspended and resumed, effectively enhanced generators.
break, continue
end loop / jump to next
process_running(process)
determine if running
Parallel and distributed computing and metaprogramming
s=start(I);while !done(I,s)
iterator from sequence
process_exited(process)
determine if has exited
are supported.
(i,s) = next(I,s)
kill(process, signum)
print("hello world")
print or println (new line)
readsfrom(command)
(its stdout, process)
help(name)
get help on object
[expr for x in seq lc ]
list comprehension
writesto(command)
runs asynch & returns
apropos("search string")
search docs for string
nothing
empty statement
(its stdin, process)

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2