Programming Language Julia, an alternative to Python, R and Matlab

Programming Language Julia, an alternative to Python, R and Matlab
Programming Language Julia, an alternative to Python, R and Matlab

The programming language Julia has been developed open source for seven years. Its special properties make it ideal for processing large amounts of data and for scientific applications. Similar to C, C ++ and Python, Julia is also designed as a general purpose language. It can be used to write applications for almost any purpose, so that the language is in good hands even outside of niche science.

Programs written in Julia run just as fast as translated C programs. In the background, Julia uses the LLVM framework, which creates the actual native program code at runtime (Just-in-Time, JIT). The reference implementation of all tools and libraries is under the permissive MIT license.

Here is Raspberry Pi 4, with 4 GB of RAM and 4K output

Easy to understand syntax

The syntax is slightly reminiscent of a mix of Lisp and Python. Julia supports not only functional but also rudimentary object-oriented programming. The language relies heavily on the so-called multiple-dispatch concept: Developers may define several functions with the same name but different arguments. Julia then automatically chooses the best matching function when called.

The standard library includes functions for parallel processing, network communication and profiling. Finally, like Lisp, Julia supports metaprogramming, which the source code can modify itself before it runs.

Programs written in Julia run just as fast as translated C programs. In the background, Julia uses the LLVM framework, which creates the actual native program code at runtime (Just-in-Time, JIT). The reference implementation of all tools and libraries is under the permissive MIT license.

Stadia and the future of gaming according to WBIE

Easy to understand syntax

The syntax is slightly reminiscent of a mix of Lisp and Python. Julia supports not only functional but also rudimentary object-oriented programming. The language relies heavily on the so-called multiple-dispatch concept: Developers may define several functions with the same name but different arguments. Julia then automatically chooses the best matching function when called.

The standard library includes functions for parallel processing, network communication and profiling. Finally, like Lisp, Julia supports metaprogramming, which the source code can modify itself before it runs.

Like many scripting languages, Julia also has an interactive interpreter that directly executes the input source code. The interpreter can be fed with code from files and standard input.

The results of the Galaxy Zoo project force us to revise the theory of the formation of spiral arms of galaxies

Simple mathematical notation

Julia offers a dynamic typing that allows a variable to hold any content:

x = 5
x = hello world !

The variable names may consist of Unicode characters. Julia also takes advantage of Unicode support. So you can just type √4 to get the root out of 4. Julia automatically determines the type of a variable in the background. If required, however, it can also be explicitly specified with the :: operator on expressions and variables.

In the case of x :: UInt64 , Julia interprets the variable x as a 64-bit, unsigned integer. If the operator hangs on an expression, Julia checks to see if the returned value matches the type. In the following example, the result of 2 + 3 must be an integer, otherwise Julia will generate an error:

y = ( 2 + 3 ) :: int

A variable may be preceded directly by a number, such as in the expression 2x + 3 . Julia then automatically performs a multiplication with the variable content. Furthermore, comparison operators such as <or> can be concatenated:

1 < 2 < 3 == 3 > 2 > = 1

This expression is true in the eyes of Julia. Thanks to these conventions, quite elegant mathematical formulas can be noted.

Like UInt64 and Int, Julia knows many other integer and floating-point types, complex and rational numbers, and of course Boolean values. In addition, Julia integrates the GNU Multiple Precision Arithmetic Library (GMP) and the GNU MPFR Library, which enable efficient long-range arithmetic through the BigInt and BigFloat types.

Strings can be concatenated quickly using the * operator. Conversely, one can cut out a character or a part using appropriate index information. In the following example, y would contain the text lo W:

x = hello * world !
y = x [ 4 : 7 ]

Thanks to the integrated PCRE library, Julia even evaluates Perl-compatible regular expressions. As in Perl, you can also use variable content in strings:

name = Tim
x = Hello $ name !

Functions and good arguments

As in many scripting languages, functions can be quite compact in Julia:

function f ( x , y )
x + y
end

On top of that there is the short notation f (x, y) = x + y. By default, Julia returns the value of the last expression in the function. If in doubt, returnallows you to return a specific value. Several return values are also possible, which Julia packs into a corresponding tuple and then returns this.

Tuples complement arrays already known from other languages and can store arbitrary values: x = (2.3, Hello, 5 + 4). The access is made with the parenthesis notation, for example , x [2] returns hello.

Functions treated Julia as first-class objects. They can therefore be assigned to variables, passed as arguments and returned as return values. Anonymous functions are also possible:

function ( x )
2x + 3
end

For them there is also a short notation, which for the example is x -> 3x + 2. As in other languages, anonymous functions are mainly used to pass them directly as arguments to another function.

Wine project fears problems with 64-bit Ubuntu

Good arguments

The arguments of functions can be pre-populated with standard values: function f (a, b = 2). That would be enough to call f (1) . In addition one may give names to the arguments. This emphasizes the meaning, in addition one may exchange their order. These so-called keyword arguments stand behind a semicolon:

function male ( x , y ; brush = fine , thickness = 1 )
male ( 1 , 2 , thickness = 2 )

If desired, a function can also accept any number of arguments that Julia then makes available within the function in a tuple ( Varargs Functions ). Even the operators like + , * or  are all functions for Julia – 1 + 2 is just an alternative notation for + (1,2).

Always in the river

Conditional statements are made using the if-else construct known from many other languages, where the condition must always be true or false :

if x > 0
Positive number
else
Negative number
end

Julia offers only a while and a for loop. The latter iterates over a sequence of numbers or the elements in a container. In the following example, it outputs the numbers from 1 to 5:

for i = 1 : 5
println( i )
end

Loops can be aborted with break , continue immediately starts the next loop pass. Two nested loops can pull developers together to one:

for i = 1 : 2 , j = 3 : 4
println ( ( i , j ) )
end

Julia knows exceptions, which can throw functions with a throw throw. Similar to Java, the environment catches the errors with a try and catch block.

Typical

Among other things, Julia knows the intertext types Int8Int16 and Int32. Occasionally one would like to write code that can handle all types of integers. This is helped by the Abstract Types, which together form a hierarchy, the Type Graph. An abstract type is, for example, the type Number, which in turn stands for all numbers. The function foo (a :: Numbers)would therefore accept all numbers as arguments.

At the end of the hierarchy are the primitive types, which simply occupy a given number of bits in memory. If necessary, you can define abstract types and primitive types yourself. In the following example, the abstract data type MyNumber is a subtype of Number

abstract type mynumber <: Number end

In addition, Julia provides even more interesting data type concepts. In this way, Union {}can be used to combine several types in one and thus implement the data type String orNumber. Developers can also query and compare the type in the program code. For example, isa () checks to see if an object matches a particular type- for example , isa (1, int)would be true.

Windows 10 annoys users with ghost updates for uninstalled apps

Multiple dispatch

In Julia several functions with the same name but different arguments may exist. When calling up the function, Julia automatically selects the appropriate one. In the following example, there are two times a foo () function:

function foo ( a :: Numbers )
function foo ( a :: Float16 )

Both perform a calculation with a number a. If you later call foo () with a number of the type Float16, Julia would automatically resort to the second function, in all other cases choose the first one. In this way the programming language realizes polymorphism.

The individual variants of foo () designate Julia as methods. The term is thus interpreted somewhat differently than in object-oriented languages, where methods are usually part of a class. The selection of the appropriate method is generally called Dispatch.

Julia is always guided by all the arguments passed and their types, as well as the Type Graph. For object-oriented languages, however, the choice is usually based on the class to which the object belongs. Julia’s approach is therefore also referred to as multiple dispatch. This is especially useful for mathematical tasks. The best known example is the function + , which has to do an addition on all possible data types. In Julia, developers can + simply add suitable variants for their own data types. It is even possible to specify rules according to which Julia should translate mixed types (such as the addition of an integer with a floating-point number) into a separate type ( promotion ).

class replacement

Unlike object-oriented languages, Julia knows no classes. Similar to C, however, you can use the keyword struct to group multiple variables into a new data type:

struct person
Surname
age :: UInt8
end

Julia calls these composite data types composite types. The person created in the example can be used to create an object with a function call:

hans = person ( Hans Meier , 35 )

Hans is thus of the type person. The called function designates Julia as a constructor. Similar to the counterpart in object-oriented languages of the same name, you can overload the contructor automatically provided by Julia by simply defining other suitable methods.

By default, the elements of hans can be read via the dot operator ( a = hans.alter ), but they can not be changed. This is only possible if the struct is explicitly preceded by the keyword mutable. Julia always manages the corresponding objects on the heap.

Generic

Composite types can be parameterized. Other languages know the concept as generics. These, for example, are useful if the actual data type is still unknown:

struct point { T }
x :: T
y :: T
end
a = Point { UInt8 } ( 2 , 3 )

Only when creating an object decides which data stores “Point”. In the example, the type of a is then Point {UInt8}. Similarly, functions can also be parameterized.

parallel processing

Julia can perform several functions in parallel. These so-called tasks can be paused and continue later. Data is exchanged via so-called channels. These are First-In-First-Out (FIFO) queues, into which multiple tasks can simultaneously write and read data:

function count ( c :: Channel )
for number = 1 : 10
put !( c , number )
end
end ;
chnl = channel ( count ) ;
a = take !( chnl )
println ( a )

count is the task that pushes the corresponding value into channel c via put! (). After each put! () Julia stops the function count () and passes the control back to the calling code. The Channel Constructor Channel (count) creates a task bound to the channel. take! () reads a date from the channel and ensures that the producer () continues to run.

Internally, Julia realizes the tasks as coroutines. In addition, version 1.1 of the programming language also provides experimental support for multithreading. On the other hand, support for distributed computing is stable. The Julia interpreter runs several times locally or on remote computers. The programmer can then selectively call individual Julia functions on the remote computers.

Metaprogramming

Similar to Lisp, the Julia program code itself can change. The programming language provides suitable functions for this purpose. Added to this are the macros based on Lisp. These helpers take several arguments that they incorporate into an expression:

macro hello ( x )
return : ( println ( hello , $ x ) )
end
@ hello ( Paul )

@hello replaces Julia with println (hello, Paul). Julia compiles the code given by Makro even before the complete program starts. The mulitple dispatch principle also applies to macros, so there can be several method definitions.

Many other little things

In addition to the presented constructs Julia offers many more interesting concepts. For example, arrays can be created extremely flexibly via so-called comprehensions. Anyone who knows the set definition from mathematics should get warm quickly with the syntax. The following example provides the array [4,5]:

x = [ a + b for a = 1 : 2 , b = 3 ]

This notation can also be used in a so-called generator expression. sum (n for n = 1:10)calculates the sum of all numbers from 1 to 10.

Particularly interesting for matrix calculations is the function broadcast (), which applies a function passed to it to all elements of an array. If necessary, the function adjusts the dimensions of the participating arrays without occupying additional memory.

Furthermore, Julia offers a built-in documentation system: If you place a string alone in front of a function definition or other corresponding code, Julia interprets it as documentation (so-called docstrings). Among other things, these help texts can evaluate and search the command line version of Julia as well as the Juno IDE.

Finally, Julia code can be called up via appropriate interfaces from C programs. Conversely, programmers can start external programs from the Julia code and call C and Fortran code. In this way, numerous C libraries can be integrated and used further.

Julia combines the advantages of a scripting language with efficient and fast running binaries. Especially in mathematical calculations, the processing of data and in science, it offers an interesting alternative to Python, R and Matlab. Who wants to get into Julia, should consult the official documentation. It discusses all aspects of the language in great detail and provides numerous tips for the daily work and the development of Julia programs.