Julia – Arrays ”; Previous Next An Array is an ordered set of elements which are often specified with squared brackets having comma-separated items. We can create arrays that are − Full or empty Hold values of different types Restricted to values of a specific type In Julia, arrays are actually mutable type collections which are used for lists, vectors, tables, and matrices. That is why the values of arrays in Julia can be modified with the use of certain pre-defined keywords. With the help of push! command you can add new element in array. Similarly, with the help of splice! function you can add elements in an array at a specified index. Creating Simple 1D Arrays Following is the example showing how we can create a simple 1D array − julia> arr = [1,2,3] 3-element Array{Int64,1}: 1 2 3 The above example shows that we have created a 1D array with 3 elements each of which is a 64-bit integer. This 1D array is bound to the variable arr. Uninitialized array We can also specify the type and the dimension of an array by using the below syntax − Array{type}(dims) Following is an example of uninitialized array − julia> array = Array{Int64}(undef, 3) 3-element Array{Int64,1}: 0 0 0 julia> array = Array{Int64}(undef, 3, 3, 3) 3×3×3 Array{Int64,3}: [:, :, 1] = 8 372354944 328904752 3 331059280 162819664 32 339708912 1 [:, :, 2] = 331213072 3 331355760 1 328841776 331355984 -1 328841680 2 [:, :, 3] = 1 0 339709232 164231472 328841872 347296224 328841968 339709152 16842753 Here we placed the type in curly braces and the dimensions in parentheses. We use undef which means that particular array has not been initialized to any known value and thats why we got random numbers in the output. Arrays of anything Julia gives us the freedom to create arrays with elements of different types. Let us see the example below in which we are going to create array of an odd mixture — numbers, strings, functions, constants − julia> [1, “TutorialsPoint.com”, 5.5, tan, pi] 5-element Array{Any,1}: 1 “TutorialsPoint.com” 5.5 tan (generic function with 12 methods) π = 3.1415926535897… Empty Arrays Just like creating an array of specific type, we can also create empty arrays in Julia. The example is given below − julia> A = Int64[] Int64[] julia> A = String[] String[] Creating 2D arrays & matrices Leave out the comma between elements and you will be getting 2D arrays in Julia. Below is the example given for single row, multi-column array − julia> [1 2 3 4 5 6 7 8 9 10] 1×10 Array{Int64,2}: 1 2 3 4 5 6 7 8 9 10 Here, 1×10 is the first row of this array. To add another row, just add a semicolon(;). Let us check the below example − julia> [1 2 3 4 5 ; 6 7 8 9 10] 2×5 Array{Int64,2}: 1 2 3 4 5 6 7 8 9 10 Here, it becomes 2×5 array. Creating arrays using range objects We can create arrays using range objects in the following ways − Collect() function First useful function to create an array using range objects is collect(). With the help of colon(:) and collect() function, we can create an array using range objects as follows − julia> collect(1:5) 5-element Array{Int64,1}: 1 2 3 4 5 We can also create arrays with floating point range objects − julia> collect(1.5:5.5) 5-element Array{Float64,1}: 1.5 2.5 3.5 4.5 5.5 Let us see a three-piece version of a range object with the help of which you can specify a step size other than 1. The syntax for the same is given below − start:step:stop. Below is an example to build an array with elements that go from 0 to 50 in steps of 5 − julia> collect(0:5:50) 11-element Array{Int64,1}: 0 5 10 15 20 25 30 35 40 45 50 ellipsis(…) or splat operator Instead of using collect() function, we can also use splat operator or ellipsis(…) after the last element. Following is an example − julia> [0:10…] 11-element Array{Int64,1}: 0 1 2 3 4 5 6 7 8 9 10 range() function Range() is another useful function to create an array with range objects. It goes from start value to end value by taking a specific step value. For example, let us see an example to go from 1 to 150 in exactly 15 steps − julia> range(1, length=15, stop=150) 1.0:10.642857142857142:150.0 Or you can use range to take 10 steps from 1, stopping at or before 150: julia> range(1, stop=150, step=10) 1:10:141 We can use range() with collect() to build an array as follows − julia> collect(range(1, length=15, stop=150)) 15-element Array{Float64,1}: 1.0 11.642857142857142 22.285714285714285 32.92857142857143 43.57142857142857 54.214285714285715 64.85714285714286 75.5 86.14285714285714 96.78571428571429 107.42857142857143 118.07142857142857 128.71428571428572 139.35714285714286 150.0 Creating arrays using comprehensions and generators Another useful way to create an array is to use comprehensions. In this way, we can create array where each element can produce using a small computation. For example, we can create an array of 10 elements as follows − julia> [n^2 for n in 1:10] 10-element Array{Int64,1}: 1 4 9 16 25 36 49 64 81 100 We can easily create a 2-D array also as follows − julia> [n*m for n in 1:10, m in 1:10] 10×10 Array{Int64,2}: 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36
Category: julia
Julia – Functions
Julia – Functions ”; Previous Next Function, the building blocks of Julia, is a collected group of instructions that maps a tuple of argument values to a return value. It acts as the subroutines, procedures, blocks, and other similar structures concepts found in other programming languages. Defining Functions There are following three ways in which we can define functions − When there is a single expression in a function, you can define it by writing the name of the function and any arguments in parentheses on the left side and write an expression on the right side of an equal sign. Example julia> f(a) = a * a f (generic function with 1 method) julia> f(5) 25 julia> func(x, y) = sqrt(x^2 + y^2) func (generic function with 1 method) julia> func(5, 4) 6.4031242374328485 If there are multiple expressions in a function, you can define it as shown below − function functionname(args) expression expression expression … expression end Example julia> function bills(money) if money < 0 return false else return true end end bills (generic function with 1 method) julia> bills(50) true julia> bills(-50) false If a function returns more than one value, we need to use tuples. Example julia> function mul(x,y) x+y, x*y end mul (generic function with 1 method) julia> mul(5, 10) (15, 50) Optional Arguments It is often possible to define functions with optional arguments i.e. default sensible values for functions arguments so that the function can use that value if specific values are not provided. For example − julia> function pos(ax, by, cz=0) println(“$ax, $by, $cz”) end pos (generic function with 2 methods) julia> pos(10, 30) 10, 30, 0 julia> pos(10, 30, 50) 10, 30, 50 You can check in the above output that when we call this function without supplying third value, the variable cz defaults to 0. Keyword Arguments Some functions which we define need a large number of arguments but calling such functions can be difficult because we may forget the order in which we have to supply the arguments. For example, check the below function − function foo(a, b, c, d, e, f) … end Now, we may forget the order of arguments and the following may happen − foo(“25”, -5.6987, “hello”, 56, good, ‘ABC’) or foo(“hello”, 56, “25”, -5.6987, ‘ABC’, good) Julia provides us a way to avoid this problem. We can use keywords to label arguments. We need to use a semicolon after the function’s unlabelled arguments and follow it with one or more keyword-value pair as follows − julia> function foo(a, b ; c = 10, d = “hi”) println(“a is $a”) println(“b is $b”) return “c => $c, d => $d” end foo (generic function with 1 method) julia> foo(100,20) a is 100 b is 20 ”c => 10, d => hi” julia> foo(“Hello”, “Tutorialspoint”, c=pi, d=22//7) a is Hello b is Tutorialspoint ”c => π, d => 22//7″ It is not necessary to define the keyword argument at the end or in the matching place, it can be written anywhere in the argument list. Following is an example − julia> foo(c=pi, d =22/7, “Hello”, “Tutorialspoint”) a is Hello b is Tutorialspoint ”c => π, d => 3.142857142857143″ Anonymous Functions It is waste of time thinking a cool name for your function. Use Anonymous functions i.e. functions with no name instead. In Julia, such functions can be used in number of places such as map() and in list comprehensions. The syntax of anonymous functions uses the symbol ->. You can check the below example − A -> A^3 + 3A – 3 The above function is an anonymous function that takes an argument A and returns A^3 + 3A – 3. It can be used with map() function whose first argument is a function and we can define an one-off function that exists just for one particular map() operation. The example is given below − julia> map(A -> A^3 + 3A – 3, [10,3,-2]) 3-element Array{Int64,1}: 1027 33 -17 Once the map() function finishes, the function and argument both will disappear − julia> A ERROR: UndefVarError: A not defined Recursive Functions In Julia, the functions can be nested. It is demonstrated in the example given below − julia> function add(x) Y = x * 2 function add1(Y) Y += 1 end add1(Y) end add (generic function with 1 method) julia> d = 10 10 julia> add(d) 21 In the same way, a function in Julia can be recursive also. It means the function can call itself. Before getting into details, we first need to test a condition in code which can be done with the help of ternary operator “?”. It takes the form expr ? a : b. It is called ternary because it takes three arguments. Here the expr is a condition, if it is true then a will be evaluated otherwise b. Let us use this in the following recursive definition − julia> sum(x) = x > 1 ? sum(x-1) + x : x sum (generic function with 1 method) The above statement calculates the sum of all the integers up to and including a certain number. But in this recursion ends because there is a base case, i.e., when x is 1, this value is returned. The most famous example of recursion is to calculate the nth Fibonacci number which is defined as the sum of two previous Fibonacci numbers. Let us understand it with the below given example − julia> fib(x) = x < 2 ? x : fib(x-1) + fib(x-2) fib (generic function with 1 method) Therefore while using recursion, we need to be careful to define a base case to stop calculation. Map Map may be defined as a function that takes the following form − map(func, coll) Here, func is a function applied successively to each element of collection coll. Map generally contains the anonymous function and returns a new collection. The example is given below − julia> map(A ->
Julia – Basic Syntax
Julia Programming – Basic Syntax ”; Previous Next The simplest first Julia program (and of many other programming languages too) is to print hello world. The script is as follows − If you have added Julia to your path, the same script can be saved in a file say hello.jl and can be run by typing Julia hello.jl at command prompt. Alternatively the same can also be run from Julia REPL by typing include(“hello.jl”). This command will evaluate all valid expressions and return the last output. Variables What can be the simplest definition of a computer program? The simplest one may be that a computer program is a series of instructions to be executed on a variety of data. Here the data can be the name of a person, place, the house number of a person, or even a list of things you have made. In computer programming, when we need to label such information, we give it a name (say A) and call it a variable. In this sense, we can say that a variable is a box containing data. Let us see how we can assign data to a variable. It is quite simple, just type it. For example, student_name = “Ram” roll_no = 15 marks_math = 9.5 Here, the first variable i.e. student_name contains a string, the second variable i.e. roll_no contains a number, and the third variable i.e. marks_math contains a floating-point number. We see, unlike other programming languages such as C++, Python, etc.,in Julia we do not have to specify the type of variables because it can infer the type of object on the right side of the equal sign. Stylistic Conventions and Allowed Variable Names Following are some conventions used for variables names − The names of the variables in Julia are case sensitive. So, the variables student_name and Student_name would not be same. The names of the variables in Julia should always start with a letter and after that we can use anything like digits, letters, underscores, etc. In Julia, generally lower-case letter is used with multiple words separated by an underscore. We should use clear, short, and to the point names for variables. Some of the valid Julia variable names are student_name, roll_no, speed, current_time. Comments Writing comments in Julia is quite same as Python. Based on the usage, comments are of two types − Single Line Comments In Julia, the single line comments start with the symbol of # (hashtag) and it lasts till the end of that line. Suppose if your comment exceeds one line then you should put a # symbol on the next line also and can continue the comment. Given below is the code snippet showing single line comment − Example julia> #This is an example to demonstrate the single lined comments. julia> #Print the given name Multi-line Comments In Julia, the multi-line comment is a piece of text, like single line comment, but it is enclosed in a delimiter #= on the start of the comment and enclosed in a delimiter =# on the end of the comment. Given below is the code snippet showing multi-line comment − Example julia> #= This is an example to demonstrate the multi-line comments that tells us about tutorialspoint.com. At this website you can browse the best resource for Online Education.=# julia> print(www.tutorialspoint.com) Print Page Previous Next Advertisements ”;
Basic Mathematical Functions
Julia – Basic Mathematical Functions ”; Previous Next Let us try to understand basic mathematical functions with the help of example in this chapter. Numerical Conversions In Julia, the user gets three different forms of numerical conversion. All the three differ in their handling of inexact conversions. They are as follows − T(x) or convert(T, x) − This notation converts x to a value of T. The result depends upon following two cases − T is a floating-point type − In this case the result will be the nearest representable value. This value could be positive or negative infinity. T is an integer type − The result will raise an InexactError if and only if x is not representable by T. x%T − This notation will convert an integer x to a value of integer type T corresponding to x modulo 2^n. Here n represents the number of bits in T. In simple words, this notation truncates the binary representation to fit. Rounding functions − This notation takes a type T as an optional argument for calculation. Eg − Round(Int, a) is shorthand for Int(round(a)). Example The example given below represent the various forms described above − julia> Int8(110) 110 julia> Int8(128) ERROR: InexactError: trunc(Int8, 128) Stacktrace: [1] throw_inexacterror(::Symbol, ::Type{Int8}, ::Int64) at .boot.jl:558 [2] checked_trunc_sint at .boot.jl:580 [inlined] [3] toInt8 at .boot.jl:595 [inlined] [4] Int8(::Int64) at .boot.jl:705 [5] top-level scope at REPL[4]:1 julia> Int8(110.0) 110 julia> Int8(3.14) ERROR: InexactError: Int8(3.14) Stacktrace: [1] Int8(::Float64) at .float.jl:689 [2] top-level scope at REPL[6]:1 julia> Int8(128.0) ERROR: InexactError: Int8(128.0) Stacktrace: [1] Int8(::Float64) at .float.jl:689 [2] top-level scope at REPL[7]:1 julia> 110%Int8 110 julia> 128%Int8 -128 julia> round(Int8, 110.35) 110 julia> round(Int8, 127.52) ERROR: InexactError: trunc(Int8, 128.0) Stacktrace: [1] trunc at .float.jl:682 [inlined] [2] round(::Type{Int8}, ::Float64) at .float.jl:367 [3] top-level scope at REPL[14]:1 Rounding functions Following table shows rounding functions that are supported on Julia’s primitive numeric types − Function Description Return type round(x) This function will round x to the nearest integer. typeof(x) round(T, x) This function will round x to the nearest integer. T floor(x) This function will round x towards -Inf returns the nearest integral value of the same type as x. This value will be less than or equal to x. typeof(x) floor(T, x) This function will round x towards -Inf and converts the result to type T. It will throw an InexactError if the value is not representable. T floor(T, x) This function will round x towards -Inf and converts the result to type T. It will throw an InexactError if the value is not representable. T ceil(x) This function will round x towards +Inf and returns the nearest integral value of the same type as x. This value will be greater than or equal to x. typeof(x) ceil(T, x) This function will round x towards +Inf and converts the result to type T. It will throw an InexactError if the value is not representable. T trunc(x) This function will round x towards zero and returns the nearest integral value of the same type as x. The absolute value will be less than or equal to x. typeof(x) trunc(T, x) This function will round x towards zero and converts the result to type T. It will throw an InexactError if the value is not representable. T Example The example given below represent the rounding functions − julia> round(3.8) 4.0 julia> round(Int, 3.8) 4 julia> floor(3.8) 3.0 julia> floor(Int, 3.8) 3 julia> ceil(3.8) 4.0 julia> ceil(Int, 3.8) 4 julia> trunc(3.8) 3.0 julia> trunc(Int, 3.8) 3 Division functions Following table shows the division functions that are supported on Julia’s primitive numeric types − Sl.No Function & Description 1 div(x,y), x÷y It is the quotation from Euclidean division. Also called truncated division. It computes x/y and the quotient will be rounded towards zero. 2 fld(x,y) It is the floored division. The quotient will be rounded towards -Inf i.e. largest integer less than or equal to x/y. It is shorthand for div(x, y, RoundDown). 3 cld(x,y) It is ceiling division. The quotient will be rounded towards +Inf i.e. smallest integer less than or equal to x/y. It is shorthand for div(x, y, RoundUp). 4 rem(x,y) remainder; satisfies x == div(x,y)*y + rem(x,y); sign matches x 5 mod(x,y) It is modulus after flooring division. This function satisfies the equation x == fld(x,y)*y + mod(x,y). The sign matches y. 6 mod1(x,y) This is same as mod with offset 1. It returns r∈(0,y] for y>0 or r∈[y,0) for y<0, where mod(r, y) == mod(x, y). 7 mod2pi(x) It is modulus with respect to 2pi. It satisfies 0 <= mod2pi(x) < 2pi 8 divrem(x,y) It is the quotient and remainder from Euclidean division. It equivalents to (div(x,y),rem(x,y)). 9 fldmod(x,y) It is the floored quotation and modulus after division. It is equivalent to (fld(x,y),mod(x,y)) 10 gcd(x,y…) It is the greatest positive common divisor of x, y,… 11 lcm(x,y…) It represents the least positive common multiple of x, y,… Example The example given below represent the division functions − julia> div(11, 4) 2 julia> div(7, 4) 1 julia> fld(11, 4) 2 julia> fld(-5,3) -2 julia> fld(7.5,3.3) 2.0 julia> cld(7.5,3.3) 3.0 julia> mod(5, 0:2) 2 julia> mod(3, 0:2) 0 julia> mod(8.9,2) 0.9000000000000004 julia> rem(8,4) 0 julia> rem(9,4) 1 julia> mod2pi(7*pi/5) 4.39822971502571 julia> divrem(8,3) (2, 2) julia> fldmod(12,4) (3, 0) julia> fldmod(13,4) (3, 1) julia> mod1(5,4) 1 julia> gcd(6,0) 6 julia> gcd(1//3,2//3) 1//3 julia> lcm(1//3,2//3) 2//3 Sign and Absolute value functions Following table shows the sign and absolute value
Julia – Tuples
Julia – Tuples ”; Previous Next Similar to an array, tuple is also an ordered set of elements. Tuples work in almost the same way as arrays but there are following important differences between them − An array is represented by square brackets whereas a tuple is represented by parentheses and commas. Tuples are immutable. Creating tuples We can create tuples as arrays and most of the array’s functions can be used on tuples also. Some of the example are given below − julia> tupl=(5,10,15,20,25,30) (5, 10, 15, 20, 25, 30) julia> tupl (5, 10, 15, 20, 25, 30) julia> tupl[3:end] (15, 20, 25, 30) julia> tupl = ((1,2),(3,4)) ((1, 2), (3, 4)) julia> tupl[1] (1, 2) julia> tupl[1][2] 2 We cannot change a tuple: julia> tupl[2]=0 ERROR: MethodError: no method matching setindex!(::Tuple{Tuple{Int64,Int64},Tuple{Int64,Int64}}, ::Int64, ::Int64) Stacktrace: [1] top-level scope at REPL[7]:1 Named tuples A named tuple is simply a combination of a tuple and a dictionary because − A named tuple is ordered and immutable like a tuple and Like a dictionary in named tuple, each element has a unique key which can be used to access it. In next section, let us see how we can create named tuples − Creating named tuples You can create named tuples in Julia by − Providing keys and values in separate tuples Providing keys and values in a single tuple Combining two existing named tuples Keys and values in separate tuples One way to create named tuples is by providing keys and values in separate tuples. Example julia> names_shape = (:corner1, :corner2) (:corner1, :corner2) julia> values_shape = ((100, 100), (200, 200)) ((100, 100), (200, 200)) julia> shape_item2 = NamedTuple{names_shape}(values_shape) (corner1 = (100, 100), corner2 = (200, 200)) We can access the elements by using dot(.) syntax − julia> shape_item2.corner1 (100, 100) julia> shape_item2.corner2 (200, 200) Keys and values in a single tuple We can also create named tuples by providing keys and values in a single tuple. Example julia> shape_item = (corner1 = (1, 1), corner2 = (-1, -1), center = (0, 0)) (corner1 = (1, 1), corner2 = (-1, -1), center = (0, 0)) We can access the elements by using dot(.) syntax − julia> shape_item.corner1 (1, 1) julia> shape_item.corner2 (-1, -1) julia> shape_item.center (0, 0) julia> (shape_item.center,shape_item.corner2) ((0, 0), (-1, -1)) We can also access all the values as with ordinary tuples as follows − julia> c1, c2, center = shape_item (corner1 = (1, 1), corner2 = (-1, -1), center = (0, 0)) julia> c1 (1, 1) Combining two named tuples Julia provides us a way to make new named tuples by combining two named tuples together as follows − Example julia> colors_shape = (top = “red”, bottom = “green”) (top = “red”, bottom = “green”) julia> shape_item = (corner1 = (1, 1), corner2 = (-1, -1), center = (0, 0)) (corner1 = (1, 1), corner2 = (-1, -1), center = (0, 0)) julia> merge(shape_item, colors_shape) (corner1 = (1, 1), corner2 = (-1, -1), center = (0, 0), top = “red”, bottom = “green”) Named tuples as keyword arguments If you want to pass a group of keyword arguments to a function, named tuple is a convenient way to do so in Julia. Following is the example of a function that accepts three keyword arguments − julia> function ABC(x, y, z; a=10, b=20, c=30) println(“x = $x, y = $y, z = $z; a = $a, b = $b, c = $c”) end ABC (generic function with 1 method) It is also possible to define a named tuple which contains the names as well values for one or more keywords as follows − julia> options = (b = 200, c = 300) (b = 200, c = 300) In order to pass the named tuples to the function we need to use; while calling the function − julia> ABC(1, 2, 3; options…) x = 1, y = 2, z = 3; a = 10, b = 200, c = 300 The values and keyword can also be overridden by later function as follows − julia> ABC(1, 2, 3; b = 1000_000, options…) x = 1, y = 2, z = 3; a = 10, b = 200, c = 300 julia> ABC(1, 2, 3; options…, b= 1000_000) x = 1, y = 2, z = 3; a = 10, b = 1000000, c = 300 Print Page Previous Next Advertisements ”;
Julia – Environment Setup
Julia Programming – Environment Setup ”; Previous Next To install Julia, we need to download binary Julia platform in executable form which you can download from the link https://julialang.org/downloads/. On the webpage, you will find Julia in 32-bit and 64-bit format for all three major platforms, i.e. Linux, Windows, and Macintosh (OS X). The current stable release which we are going to use is v1.5.1. Installing Julia Let us see how we can install Julia on various platforms − Linux and FreeBSD installation The command set given below can be used to download the latest version of Julia programming language into a directory, let’s say Julia-1.5.1 − wget https://julialang-s3.julialang.org/bin/linux/x64/1.5/julia-1.5.1-linux-x86_64.tar.gz tar zxvf julia-1.5.1-linux-x86_64.tar.gz Once installed, we can do any of the following to run Julia − Use Julia’s full path, <Julia directory>/bin/Julia to invoke Julia executable. Here <Julia directory> refers to the directory where Julia is installed on your computer. You can also create a symbolic link to Julia programming language. The link should be inside a folder which is on your system PATH. You can add Julia’s bin folder with full path to system PATH environment variable by editing the ~/.bashrc or ~/.bash_profile file. It can be done by opening the file in any of the editors and adding the line given below: export PATH=”$PATH:/path/to/<Julia directory>/bin” Windows installation Once you downloaded the installer as per your windows specifications, run the installer. It is recommended to note down the installation directory which looks like C:UsersGaAppDataLocalProgramsJulia1.5.1. To invoke Julia programming language by simply typing Julia in cmd, we must add Julia executable directory to system PATH. You need to follow the following steps according to your windows specifications − On Windows 10 First open Run by using the shortcut Windows key + R. Now, type rundll32 sysdm.cpl, EditEnvironmentVariables and press enter. We will now find the row with “Path” under “User Variable” or “System Variable”. Now click on edit button to get the “Edit environment variable” UI. Now, click on “New” and paste in the directory address we have noted while installation (C:UsersGaAppDataLocalProgramsJulia1.5.1bin). Finally click OK and Julia is ready to be run from command line by typing Julia. On Windows 7 or 8 First open Run by using the shortcut Windows key + R. Now, type rundll32 sysdm.cpl, EditEnvironmentVariables and press enter. We will now find the row with “Path” under “User Variable” or “System Variable”. Click on edit button and we will get the “Edit environment variable” UI. Now move the cursor to the end of this field and check if there is semicolon at the end or not. If not found, then add a semicolon. Once added, we need to paste in the directory address we have noted while installation (C:UsersGaAppDataLocalProgramsJulia1.5.1bin). Finally click OK and Julia is ready to be run from command line by typing Julia. macOS installation On macOS, a file named Julia-<version>.dmg will be given. This file contains Julia-<version>.app and you need to drag this file to Applications Folder Shortcut. One other way to run Julia is from the disk image by opening the app. If you want to run Julia from terminal, type the below given command − ln -s /Applications/Julia-1.5.app/Contents/Resources/julia/bin/julia /usr/local/bin/julia This command will create a symlink to the Julia version we have chosen. Now close the shell profile page and quit terminal as well. Now once again open the Terminal and type julia in it and you will be with your version of Julia programming language. Building Julia from source To build Julia from source rather than binaries, we need to follow the below given steps. Here we will be outlining the procedure for Ubuntu OS. Download the source code from GitHub at https://github.com/JuliaLang/julia. Compile it and you will get the latest version. It will not give us the stable version. If you do not have git installed, use the following command to install the same − sudo apt-get -f install git Using the following command, clone the Julia sources − git clone git://github.com/JuliaLang/julia.git The above command will download the source code into a julia directory and that is in current folder. Now, by using the command given below, install GNU compilation tools g++, gfortran, and m4 − sudo apt-get install gfortran g++ m4 Once installation done, start the compilation process as follows − cd Julia make After this, successful build Julia programming language will start up with the ./julia command. Julia’s working environment REPL (read-eval-print loop) is the working environment of Julia. With the help of this shell we can interact with Julia’s JIT (Just in Time) compiler to test and run our code. We can also copy and paste our code into .jl extension, for example, first.jl. Another option is to use a text editor or IDE. Let us have a look at REPL below − After clicking on Julia logo, we will get a prompt with julia> for writing our piece of code or program. Use exit() or CTRL + D to end the session. If you want to evaluate the expression, press enter after input. Packages Almost all the standard libraries in Julia are written in Julia itself but the rest of the Julia’s code ecosystem can be found in Packages which are Git repositories. Some important points about Julia packages are given below − Packages provide reusable functionality that can be easily used by other Julia projects. Julia has built-in package manager named pkg.jl for package installation. The package manager handles installation, removal, and updates of packages. The package manager works only if the packages are in REPL. Installing packages Step 1 − First open