Julia
satya - 6/15/2020, 9:12:29 PM
Julia programming language
Julia programming language
satya - 6/16/2020, 8:32:15 AM
Getting started with Julia
Getting started with Julia
satya - 6/16/2020, 8:41:42 AM
Julia getting started online document: julia.org
satya - 6/16/2020, 9:59:45 AM
VScode
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.
satya - 6/16/2020, 10:44:38 AM
Comments come under punctuation in the language manual
satya - 6/16/2020, 12:07:37 PM
juno julia intellisense functions in a module
juno julia intellisense functions in a module
satya - 6/16/2020, 12:18:27 PM
stdout, stdin, print and io functions
satya - 6/16/2020, 12:24:07 PM
They are
Core
Base
Main
satya - 6/16/2020, 12:25:14 PM
Intellisense in juno
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
satya - 6/16/2020, 9:38:52 PM
juno julia snippets
juno julia snippets
satya - 6/17/2020, 8:47:10 AM
hashtables in julia
hashtables in julia
satya - 6/17/2020, 9:27:20 AM
You can define a result set like this
cmdArray = [
"vscode" "createVSCodeCommand";
"psutils" "C:\\satya\\data\\code\\power-shell-scripts"
]
satya - 6/17/2020, 9:28:07 AM
You can then do
#print the array
print(cmdArray)
#using type names
print(typeof(cmdArray))
satya - 6/17/2020, 12:14:06 PM
How do I find installed modules in Julia
How do I find installed modules in Julia
satya - 6/17/2020, 3:17:16 PM
Julia paths on windows
Julia paths on windows
satya - 6/17/2020, 3:23:40 PM
Julia environment variables are documented here
satya - 6/17/2020, 3:25:27 PM
How does Julia resolve function names?
How does Julia resolve function names?
satya - 6/18/2020, 8:25:11 AM
Confusion with Packages
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
satya - 6/18/2020, 10:20:51 AM
More information on packages: code loading from docs
satya - 6/18/2020, 10:21:26 AM
My question on packages in julia forum
satya - 6/18/2020, 10:48:13 AM
System variables are documented here
satya - 6/18/2020, 10:50:03 AM
Examples of system variables
DEPOT_PATH
LOAD_PATH
BINDIR
CPU_THREADS
WORD_SIZE
ARCH
MACHINE
satya - 6/18/2020, 10:50:44 AM
So you can do this
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"
satya - 6/18/2020, 11:51:21 AM
Depot_path is formulated this way
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.
satya - 6/19/2020, 9:53:50 AM
What is startup.jl in julia
What is startup.jl in julia
satya - 6/19/2020, 9:54:19 AM
Startup.jl can be discovered
normpath(joinpath(Sys.BINDIR,"..","etc","julia","startup.jl"))
satya - 6/19/2020, 1:41:12 PM
DataStructures package in julia
DataStructures package in julia
satya - 6/19/2020, 2:11:14 PM
How to run a jl file from julia REPL?
How to run a jl file from julia REPL?
satya - 6/20/2020, 2:18:12 PM
Iterators are explained here in the API
satya - 6/20/2020, 2:18:29 PM
For instance you can do this
function printkeys(keysIter)
for (index, key) in enumerate(keysIter)
println("$index : $key")
end
end
satya - 6/21/2020, 8:55:46 AM
How are null values represented in Julia
How are null values represented in Julia
satya - 6/21/2020, 1:36:30 PM
Tasks and coroutines are explained here
satya - 6/21/2020, 1:36:55 PM
How can I access the fields of a type in Julia
How can I access the fields of a type in Julia
satya - 6/21/2020, 1:48:37 PM
Exploring fields of an object
#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
satya - 6/21/2020, 2:02:01 PM
A discussion on access fields of an object
satya - 6/21/2020, 2:31:10 PM
how to print stacktrace in julia
how to print stacktrace in julia
satya - 6/21/2020, 10:47:38 PM
Printing an exception stack trace
#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
satya - 6/21/2020, 10:48:31 PM
will print something like
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
satya - 6/21/2020, 10:49:23 PM
Ideas to understand further
showerror()
stacktrace()
catch_backtrace()
satya - 6/21/2020, 10:53:38 PM
Testing for an empty string
#**********************************
#* 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
satya - 6/21/2020, 11:02:48 PM
Use "tab" for auto completion in juno
Use "tab" for auto completion in juno
satya - 6/21/2020, 11:08:03 PM
Here is how to prompt for input from stdin
#**********************************
#* 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
satya - 6/23/2020, 10:56:59 AM
A better prompt function
function prompt(question::String, defaultAnswer)::Any
p(question)
line = readline(stdin)
if (isEmptyString(line))
return defaultAnswer
end
return line
end
satya - 6/24/2020, 9:04:55 AM
Enumeration
function printkeys(keysIter)
for (index, key) in enumerate(keysIter)
println("$index : $key")
end
end
satya - 6/24/2020, 9:12:31 AM
How to print a dictionary with ordinals
function printDict(dict)
for (index, key) in enumerate(keys(dict))
keyvalue = dict[key]
s = "$index), $key: $keyvalue"
p(s)
end
end
satya - 6/24/2020, 9:12:46 AM
will print something like
1), vscode: createVSCodeCommand
2), psutils: C:\satya\data\code\power-shell-scripts
satya - 6/24/2020, 10:28:44 AM
Converting strings to numbers is not automatic
s = "1234"
#wrong
x:Int16 = s
satya - 6/24/2020, 10:29:06 AM
The base function convert() also doesn't do this
The base function convert() also doesn't do this
satya - 6/24/2020, 10:29:41 AM
Instead it is called parse. It is documented here
satya - 6/24/2020, 10:39:02 AM
Iteration utilities are documented here
satya - 6/24/2020, 10:49:54 AM
Accessing a sorted dictionary by index and not key: Discussion
Accessing a sorted dictionary by index and not key: Discussion
satya - 6/24/2020, 1:02:17 PM
Generators and iteration in julia: deep dive
satya - 6/24/2020, 1:02:46 PM
generators in julia lang
generators in julia lang
satya - 6/24/2020, 1:05:46 PM
State, Generators, Iterators, Channels: Julia lang
State, Generators, Iterators, Channels: Julia lang
Search for: State, Generators, Iterators, Channels: Julia lang
satya - 6/24/2020, 1:06:56 PM
How to write a stateful function in Julia
How to write a stateful function in Julia
satya - 6/24/2020, 3:28:11 PM
inheritance symbol
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
satya - 6/24/2020, 3:28:51 PM
It is
<:
satya - 6/24/2020, 4:25:38 PM
Here is how to use generators via types in Julia
#=
*******************************************************
* 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
satya - 6/24/2020, 10:57:46 PM
Constructors are explained here: inner, outer
satya - 6/24/2020, 11:01:42 PM
Operators as functions are described here
satya - 6/24/2020, 11:04:09 PM
Operator functions in julia
Operator functions in julia
satya - 6/24/2020, 11:04:41 PM
Writing types in julia: Best practice
Writing types in julia: Best practice
satya - 6/24/2020, 11:04:54 PM
Inner and outer constructors in Julia
Inner and outer constructors in Julia
satya - 6/24/2020, 11:05:39 PM
Conversions and constructors in julia
satya - 6/27/2020, 11:33:45 AM
How to write to files in Julia lang
How to write to files in Julia lang
satya - 6/27/2020, 1:08:02 PM
Concatenating strings in julia: sample code
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
satya - 6/27/2020, 10:27:46 PM
You can avoid escaping strings using raw
tdir = raw"C:\satya\data\utils\jl"
tdir1 = raw"C:\satya\data\utils\jl\1"
satya - 6/27/2020, 10:28:07 PM
This is documented here as part of strings docs
satya - 6/27/2020, 10:28:43 PM
Here is some file IO using open and do
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
satya - 7/3/2020, 9:32:18 AM
List comprehensions in julia
List comprehensions in julia
satya - 7/3/2020, 9:34:05 AM
Comparing map and list comprehension syntax
satya - 7/3/2020, 9:52:00 AM
Syntax of a list comprehension
[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
satya - 7/3/2020, 10:09:01 AM
Using foreach
function printArray(a::AbstractArray, message::String)
hp(message)
foreach(p,a)
end
satya - 7/3/2020, 10:10:25 AM
with comments
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
satya - 7/3/2020, 10:20:04 AM
Regular expressions are covered here
satya - 7/3/2020, 10:28:36 AM
Regex() constructor in julia
Regex() constructor in julia
satya - 7/3/2020, 10:30:27 AM
regex flags to regex constructor in julia
regex flags to regex constructor in julia
satya - 7/3/2020, 11:33:35 AM
regex flags case insensitive
regex flags case insensitive
satya - 7/3/2020, 11:46:39 AM
How to enter help mode in Julia REPL
How to enter help mode in Julia REPL
satya - 7/3/2020, 11:49:07 AM
Julia REPL modes are documented here
satya - 7/3/2020, 11:55:25 AM
Various modes of REPL
#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
satya - 7/3/2020, 11:57:26 AM
Julia REPL shell mode doesn't work in windows
Julia REPL shell mode doesn't work in windows
satya - 7/3/2020, 12:09:02 PM
A question on navigating type documentation
satya - 7/3/2020, 12:09:16 PM
How does one navigate type documentation in Julia
How does one navigate type documentation in Julia
Search for: How does one navigate type documentation in Julia
satya - 7/3/2020, 12:15:40 PM
String contains code
function testOccursIn()
s = "how about this"
yesOrNo = occursin("about",s)
#prints true
p(yesOrNo)
end
satya - 7/3/2020, 12:33:44 PM
How do I define a function whose argument is iterable?
How do I define a function whose argument is iterable?
Search for: How do I define a function whose argument is iterable?
satya - 7/3/2020, 12:33:58 PM
How do I define a function whose argument is iterable?
satya - 7/3/2020, 12:42:56 PM
Discussion: How do I define a function whose argument is iterable?
Discussion: How do I define a function whose argument is iterable?
satya - 7/5/2020, 9:35:45 PM
Tokenize strings in julia
Tokenize strings in julia
satya - 7/5/2020, 9:51:08 PM
Use split function in julia to split strings or tokenize them
Use split function in julia to split strings or tokenize them
satya - 7/5/2020, 9:51:45 PM
Printing keys and values of environment variables. Takes into account path has many segments
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
satya - 7/5/2020, 9:55:08 PM
It prints out the environment variables like this
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
satya - 7/6/2020, 3:33:38 PM
A more advanced select statement in julia
#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]))
]
satya - 7/6/2020, 3:34:51 PM
Here is a utility that explores environment for Julia using a prompted search string
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
*************************************
satya - 7/6/2020, 8:08:13 PM
Regular Expressions section in the docs
satya - 7/6/2020, 8:10:02 PM
How can I see the docs on a data type like Regex
1. Type ? at REPL
2. Type Regex (your type) and enter
3. This will show the docs from that type in that source code
satya - 7/6/2020, 8:12:04 PM
Occursin documentation as part of strings
satya - 7/7/2020, 9:17:09 AM
Julia environment on command line after Julia computing install
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
satya - 7/7/2020, 9:19:26 AM
These look different when run from the Juno editor directly using the julia computing install
ATOM_HOME
JULIA_DEPOT_PATH
JULIA_EDITOR
JULIA_NUM_THREADS
JULIA_PKG_SERVER
JULIPRO_HOME
JUNORC_PATH
NODE_PATH
PATH
satya - 7/7/2020, 9:22:16 AM
Here is what each one points to in the Juno Julia REPL
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