Julia

Julia programming language

Search for: Julia programming language

Homepage Julia.org

language ref PDF

Getting started with Julia

Search for: Getting started with Julia

Julia getting started online document: julia.org

If the extension does not find your Julia installation automatically, or if you want to use a different Julia installation than the default one, you can set the julia.executablePath to point to the Julia executable that the extension should use. In that case the extension will always use that version of Julia. To edit your configuration settings, execute the Preferences: Open User Settings command (you can also access it via the menu File->Preferences->Settings), and then make sure your user settings include the julia.executablePath setting. The format of the string should follow your platform specific conventions, and be aware that the backlash \ is the escape character in JSON, so you need to use \\ as the path separator character on Windows.

Flie system API

comments in julia

Search for: comments in julia

Comments come under punctuation in the language manual

julia sample code

Search for: julia sample code

Learning resources are here

juno julia intellisense functions in a module

Search for: juno julia intellisense functions in a module

stdout, stdin, print and io functions

Modules are documented here

Standard modules docs


Core
Base
Main

1. Base. doesn't seem to do much

2. You have to know at least one or two letters to kick off the intellisense

3. Ex: Base.pr.... will show functions starting with pr in that module

juno julia snippets

Search for: juno julia snippets

Arrays from a learning site

hashtables in julia

Search for: hashtables in julia

Collections are documented here


cmdArray = [
    "vscode" "createVSCodeCommand";
    "psutils" "C:\\satya\\data\\code\\power-shell-scripts"
]

#print the array
print(cmdArray)

#using type names
print(typeof(cmdArray))

How do I find installed modules in Julia

Search for: How do I find installed modules in Julia

This is discussed in julia forum

Pkg is documented here

Julia paths on windows

Search for: Julia paths on windows

Julia environment variables are documented here

How does Julia resolve function names?

Search for: How does Julia resolve function names?

1. what is project.toml

2. Registry at: C:\Users\satya\.juliapro\JuliaPro_v1.4.2-1\registries\JuliaPro

3. Can registries be local?

4. what is project.toml?

5. project.toml is at C:\Users\satya\.juliapro\JuliaPro_v1.4.2-1\environments\v1.4\Project.toml

6. what is manifest.toml?

7. it is at C:\Users\satya\.juliapro\JuliaPro_v1.4.2-1\environments\v1.4\Manifest.toml

More information on packages: code loading from docs

My question on packages in julia forum

JULIA_DEPOT_PATH

Search for: JULIA_DEPOT_PATH

System variables are documented here


DEPOT_PATH
LOAD_PATH
BINDIR
CPU_THREADS
WORD_SIZE
ARCH
MACHINE

julia> DEPOT_PATH
3-element Array{String,1}:
 "C:\\Users\\satya\\.juliapro\\JuliaPro_v1.4.2-1"
 "C:\\satya\\i\\julia142\\Julia-1.4.2\\local\\share\\julia"
 "C:\\satya\\i\\julia142\\Julia-1.4.2\\share\\julia"

1. ~/.julia where ~ is the user home as appropriate on the system;

2. an architecture-specific shared system directory, e.g. /usr/local/share/julia;

3. an architecture-independent shared system directory, e.g. /usr/share/julia.

What is startup.jl in julia

Search for: What is startup.jl in julia


normpath(joinpath(Sys.BINDIR,"..","etc","julia","startup.jl"))

DataStructures package in julia

Search for: DataStructures package in julia

DataStructures in github

How to run a jl file from julia REPL?

Search for: How to run a jl file from julia REPL?

Julia Cheat sheet

Iterators are explained here in the API


function printkeys(keysIter)
    for (index, key) in enumerate(keysIter)
        println("$index : $key")
    end
end

How are null values represented in Julia

Search for: How are null values represented in Julia

Understanding nulls from faq

try and catch explained here

Tasks and coroutines are explained here

How can I access the fields of a type in Julia

Search for: How can I access the fields of a type in Julia

Same question in SOF


#x is a variable
type = typeof(x)

#print type  info
println(type)

#fields in that type
list = fieldnames(type)
println(list)

#or
println(fieldnames(typeof(x)))

#get a field once you know name
val = x.fieldname
fiel

Stacktrace module of julia

A discussion on access fields of an object

how to print stacktrace in julia

Search for: how to print stacktrace in julia


#Encapsulate that in a function

function printExceptionStackTrace(x)
    showerror(stdout, x, catch_backtrace())
end


#Use it while an exception is in play

function testStackTrace()
        try
            println(blah)
        catch x
            printStackTrace(x)
        end
end

UndefVarError: blah not defined
Stacktrace:
 [1] testStackTrace() at C:\satya\data\utils\jl\chdirs2.jl:96
 [2] testmain at C:\satya\data\utils\jl\chdirs2.jl:103 [inlined]
 [3] test() at C:\satya\data\utils\jl\chdirs2.jl:108
 [4] top-level scope at C:\satya\data\utils\jl\chdirs2.jl:113
 [5] include_string(::Module, ::String, ::String) at .\loading.jl:1080

showerror()
stacktrace()
catch_backtrace()

#**********************************
#* write a function to see if string is empty
#**********************************

function isEmptyString(s::String)::Bool
    #type ensures that an unassignd value
    #is never passed in
    if (s == nothing)
        return true
    end
    if (isempty(s) == true)

        return true
    end
    if (isempty(strip(s)) == true)
        return true
    end
    return false
end

#**********************************
#* test the function
#**********************************
function testValidStrings()
    b = isEmptyString("")
    p(b) #true
    b = isEmptyString(" \t")
    p(b) #true
    b = isEmptyString(" dd ")
    p(b) #false
end

Use "tab" for auto completion in juno


#**********************************
#* write a function 
#**********************************
function prompt(question::String, defaultAnswer)::String
    p(question)
    line = readline(stdin)
    if (isEmptyString(line))
        return defaultAnswer
    end
    return line
end


#**********************************
#* test the function
#**********************************
function testInput()
    ans = prompt("what is your name",nothing)
    if (ans == nothing)
        p("No answer")
        return
    end
    p("You typed:$ans")
end

Union of types is described here


function prompt(question::String, defaultAnswer)::Any
    p(question)
    line = readline(stdin)
    if (isEmptyString(line))
        return defaultAnswer
    end
    return line
end

function printkeys(keysIter)
    for (index, key) in enumerate(keysIter)
        println("$index : $key")
    end
end

function printDict(dict)
    for (index, key) in enumerate(keys(dict))
        keyvalue = dict[key]
        s = "$index), $key: $keyvalue"
        p(s)
    end
end

1), vscode: createVSCodeCommand
2), psutils: C:\satya\data\code\power-shell-scripts

Convertions between types


s = "1234"

#wrong
x:Int16 = s

The base function convert() also doesn't do this

Instead it is called parse. It is documented here

Iteration utilities are documented here

Accessing a sorted dictionary by index and not key: Discussion

Generators and iteration in julia: deep dive

generators in julia lang

Search for: generators in julia lang

Generator discussion in Julia

State, Generators, Iterators, Channels: Julia lang

Search for: State, Generators, Iterators, Channels: Julia lang

How to write a stateful function in Julia

Search for: How to write a stateful function in Julia


abstract type Number end
abstract type Real     <: Number end
abstract type AbstractFloat <: Real end
abstract type Integer  <: Real end
abstract type Signed   <: Integer end
abstract type Unsigned <: Integer end

<:

#=
*******************************************************
* IndexedOrderDict: Quick wrapper around OrderedDict
* Collects keys in an cmdArray
* holds the keys for future calls
* In that sense it acts as a stateful function 
* like a generator in python
*******************************************************
=#
struct IndexedOrderDict
    dict::OrderedDict
    keysArray::AbstractArray
    function IndexedOrderDict(dict::OrderedDict)
        keysArray = collect(keys(dict))
        new(keysArray,dict)
    end
end

#Override getindex for this type so that 
#you can do dict[7] -> translates to getindex on that type
function Base.getindex(d::IndexedOrderDict, index::Int)
    keyname = d.keysArray[index]
    keyvalue = d.dict[keyname]
    return keyvalue
end

#Ordered Dictionary or hashtable
#keeps the keys in order
cmds = OrderedDict([
    ("vscode","createVSCodeCommand"),
    ("psutils","C:\\satya\\data\\code\\power-shell-scripts")
])

function testIndexingByIndexNotKey()
    dict = IndexedOrderDict(cmds)
    dir = dict[2]
    p(dir)
end

Constructors are explained here: inner, outer

Types are documented here

Operators as functions are described here

Operator functions in julia

Search for: Operator functions in julia

Writing types in julia: Best practice

Search for: Writing types in julia: Best practice

Inner and outer constructors in Julia

Search for: Inner and outer constructors in Julia

Conversions and constructors in julia

Strageness of "do" in julia

How to write to files in Julia lang

Search for: How to write to files in Julia lang

Working with Strings


function testStringConcat()
    first = "first"
    second = "second"

    #First way
    s1 = string(first,second)
    p(s1)

    #second way
    s1 = string(first, ",", second)
    p(s1)

    #third way
    s1 = first * "," * second
    p(s1)

    #fourth way
    s1 = "$first,$second"
    p(s1)
end

Arrays are documented here

Arrays in ThinkJulia

Map function is documented here


tdir = raw"C:\satya\data\utils\jl"
tdir1 = raw"C:\satya\data\utils\jl\1"

This is documented here as part of strings docs


function getTransferfilename()
    return  "C:\\satya\\data\\utils\\jl\\transfer-commands.txt"
end

function saveTargetDirToFile(tdir)
    tfile = getTransferfilename()
    Base.open(tfile,"w") do io
        write(io,tdir)
    end
end

function readTargetDirFile()
    tfile = getTransferfilename()
    txt = Base.open(tfile,"r") do io
        return read(io,String)
    end
    return txt
end

function testFileio()
    tdir = raw"C:\satya\data\utils\jl"
    tdir1 = raw"C:\satya\data\utils\jl\1"

    saveTargetDirToFile(tdir1)
    txt = readTargetDirFile()
    p(txt)
end

What is JuliaDB

Search for: What is JuliaDB

A quick intro to Julia DB: PDF

List comprehensions in julia

Search for: List comprehensions in julia

Comparing map and list comprehension syntax


[x for x in list if x % 2 == 0]

or

[f2(x) for x in list if f(x) == true]

same as

select x // before for
from table //for part
where f(x) == true //if part

function printArray(a::AbstractArray, message::String)
    hp(message)
    foreach(p,a)
end

function printArray(a::AbstractArray, message::String)

    #header print: Print message like a header
    hp(message)

    #p is a function with 1 argument
    #Each element of the array is passed in to the function "p"
    foreach(p,a)
end

Regular expressions are covered here

Regex() constructor in julia

Search for: Regex() constructor in julia

regex flags to regex constructor in julia

Search for: regex flags to regex constructor in julia

regex flags case insensitive

Search for: regex flags case insensitive

Regex flags are documented here

How to enter help mode in Julia REPL

Search for: How to enter help mode in Julia REPL

Julia REPL modes are documented here


#to exit
c-d or exit()


#help mode
?. for entering help mode
Backspace to leave

#enter shell mode
; to enter
Backspace to leave

c-d exit
c-c interrupt
c-L clear

Julia REPL shell mode doesn't work in windows

Search for: Julia REPL shell mode doesn't work in windows

A question on navigating type documentation

How does one navigate type documentation in Julia

Search for: How does one navigate type documentation in Julia


function testOccursIn()
    s = "how about this"
    yesOrNo = occursin("about",s)

    #prints true
    p(yesOrNo)
end

How do I define a function whose argument is iterable?

Search for: How do I define a function whose argument is iterable?

How do I define a function whose argument is iterable?

Discussion: How do I define a function whose argument is iterable?

Tokenize strings in julia

Search for: Tokenize strings in julia

Use split function in julia to split strings or tokenize them


function printKeys(keyCollection, dict)
    for key in keyCollection
        keyvalue = dict[key]
        printKeyAndValue(key,keyvalue)
    end
end

function printKeyAndValue(key,value)
    if !occursin(";",value)
        p("$key: $value")
        return
    end
    p(key)
    valueArray = split(value,";")
    foreach(x -> p("\t $x"),valueArray)
    p("")
end

HOMEPATH: \Users\satya
JULIA_DEPOT_PATH
         C:\Users\satya\.juliapro\JuliaPro_v1.4.2-1
         C:\satya\i\julia142\Julia-1.4.2\local\share\julia
         C:\satya\i\julia142\Julia-1.4.2\share\julia

JUNORC_PATH: C:\satya\i\julia142\.atom

#Perform case insensitive search
#for keys or values that match a case insensitve string 
re = Regex(reply,"i")

#key names where key or its value has a matching string
keynames = [key for key in keys(ENV)
        if (occursin(re,key) || occursin(re,ENV[key]))
]


Program Start
*************************************
Search ENV string:
julia
Searchign env for: julia

Env keys matching: julia
*************************************
=C:
ATOM_HOME
JULIA_DEPOT_PATH
JULIA_EDITOR
JULIA_NUM_THREADS
JULIA_PKG_SERVER
JULIPRO_HOME
JUNORC_PATH
NODE_PATH
PATH

Matching Env  Key Values
*************************************
=C:: C:\satya\data\code\LearnJuliaRepo
ATOM_HOME: C:\satya\i\julia142\.atom
JULIA_DEPOT_PATH
         C:\Users\satya\.juliapro\JuliaPro_v1.4.2-1
         C:\satya\i\julia142\Julia-1.4.2\local\share\julia
         C:\satya\i\julia142\Julia-1.4.2\share\julia

JULIA_EDITOR: "C:\satya\i\julia142\app-1.47.0\atom.exe"  -a
JULIA_NUM_THREADS: 4
JULIA_PKG_SERVER: pkg.juliacomputing.com
JULIPRO_HOME: "C:\Users\satya\.juliapro\JuliaPro_v1.4.2-1"
JUNORC_PATH: C:\satya\i\julia142\.atom
NODE_PATH: C:\satya\i\julia142\app-1.47.0\resources\app.asar\exports
PATH
         C:\Windows\system32
         C:\Windows
         C:\Windows\System32\Wbem
         C:\Windows\System32\WindowsPowerShell\v1.0         
         C:\Windows\System32\OpenSSH         
         C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL
         C:\Program Files\Intel\Intel(R) Management Engine Components\DAL
         C:\Program Files\Intel\WiFi\bin         
         C:\Program Files\Common Files\Intel\WirelessCommon         
         C:\satya\i\git\Git\cmd
         c:\satya\i\jdk8\jre\bin         
         c:\satya\i\python374         
         c:\satya\i\hadoop312-common-bin\bin
         C:\satya\i\python374\Scripts         
         C:\satya\i\spark\bin
         C:\satya\data\code\pyspark\install
         C:\satya\i\nodejs         
         c:\satya\i\gradle563\bin
         C:\satya\i\nvm
         C:\satya\i\nodejs
         C:\satya\data\code\power-shell-scripts\individual\satya\git-util
         C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn         
         C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn         
         C:\Program Files\Microsoft SQL Server\150\Tools\Binn         
         C:\Program Files\Microsoft SQL Server\150\DTS\Binn         
         C:\Program Files\dotnet         
         C:\Program Files\Microsoft SQL Server\130\Tools\Binn         
         C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn         
         C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn         
         C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn         
         C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn         
         C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn         
         C:\satya\i\julia142\Julia-1.4.2\bin
         C:\satya\data\utils\jl
         C:\satya\i\python374\Scripts         
         C:\satya\i\python374         
         C:\Users\satya\AppData\Local\Microsoft\WindowsApps
         C:\satya\i\vscode\bin
         C:\Users\satya\AppData\Local\GitHubDesktop\bin
         C:\Users\satya\AppData\Roaming\npm
         C:\satya\i\nvm
         C:\satya\i\nodejs


Program End
*************************************

Regular Expressions section in the docs

1. Type ? at REPL

2. Type Regex (your type) and enter

3. This will show the docs from that type in that source code

Occursin documentation as part of strings

Base.occursin in function doc

Comprehensions are documented here

for loops and comprehensions



User profile dir: upd: C:\Users\satya
Install dir: id:  C:\satya\i\julia142\Julia-1.4.2

JULIA_DEPOT_PATH
     (upd)\.juliapro\JuliaPro_v1.4.2-1
     (id)\local\share\julia
     (id)\share\julia

JULIA_PKG_SERVER: 
    pkg.juliacomputing.com

JUNORC_PATH: 
    C:\satya\i\julia142\.atom

PATH:
    (id)\bin

ATOM_HOME
JULIA_DEPOT_PATH
JULIA_EDITOR
JULIA_NUM_THREADS
JULIA_PKG_SERVER
JULIPRO_HOME
JUNORC_PATH
NODE_PATH
PATH

ATOM_HOME: C:\satya\i\julia142\.atom
JULIA_DEPOT_PATH
   C:\Users\satya\.juliapro\JuliaPro_v1.4.2-1
   C:\satya\i\julia142\Julia-1.4.2\local\share\julia
   C:\satya\i\julia142\Julia-1.4.2\share\julia

JULIA_EDITOR: 
   "C:\satya\i\julia142\app-1.47.0\atom.exe"  -a

JULIA_NUM_THREADS: 
   4

JULIA_PKG_SERVER: 
   pkg.juliacomputing.com

JULIPRO_HOME: 
   "C:\Users\satya\.juliapro\JuliaPro_v1.4.2-1"

JUNORC_PATH: 
   C:\satya\i\julia142\.atom

NODE_PATH: 
   C:\satya\i\julia142\app-1.47.0\resources\app.asar\exports

PATH:
   C:\satya\i\julia142\Julia-1.4.2\bin

Math operators in julia