Julia (programming language) Learning

- 08.36

Shakespeare Meets Tech: A Julia Tragicomedy - Tech/Life Ireland
photo src: www.techlifeireland.com

Julia is a high-level dynamic programming language designed to address the needs of high-performance numerical analysis and computational science while also being effective for general-purpose programming, web use or as a specification language.

Distinctive aspects of Julia's design include a type system with parametric polymorphism and types in a fully dynamic programming language and multiple dispatch as its core programming paradigm. It allows concurrent, parallel and distributed computing, and direct calling of C and Fortran libraries without glue code.

Julia is garbage-collected, uses eager evaluation and includes efficient libraries for floating-point calculations, linear algebra, random number generation, fast Fourier transforms and regular expression matching.


Coursera's machine learning course (implemented in Python) · Linbug
photo src: linbug.github.io


Maps, Directions, and Place Reviews



Language features

According to the official website, the main features of the language are:

  • Multiple dispatch: providing ability to define function behavior across many combinations of argument types
  • Dynamic type system: types for documentation, optimization, and dispatch
  • Good performance, approaching that of statically-typed languages like C
  • Built-in package manager
  • Lisp-like macros and other metaprogramming facilities
  • Call Python functions: use the PyCall package
  • Call C functions directly: no wrappers or special APIs
  • Powerful shell-like abilities to manage other processes
  • Designed for parallel and distributed computing
  • Coroutines: lightweight green threading
  • User-defined types are as fast and compact as built-ins
  • Automatic generation of efficient, specialized code for different argument types
  • Elegant and extensible conversions and promotions for numeric and other types
  • Efficient support for Unicode, including but not limited to UTF-8

Multiple dispatch (also termed multimethods in Lisp) is a generalization of single dispatch - the polymorphic mechanism used in common object-oriented programming (OOP) languages - that uses inheritance. In Julia, all concrete types are subtypes of abstract types, directly or indirectly subtypes of the Any type, which is the top of the type hierarchy. Concrete types can not be subtyped, but composition is used over inheritance, that is used by traditional object-oriented languages (see also Inheritance vs subtyping).

Julia draws significant inspiration from various dialects of Lisp, including Scheme and Common Lisp, and it shares many features with Dylan (such as an ALGOL-like free-form infix syntax rather than a Lisp-like prefix syntax, while in Julia "everything" is an expression) - also a multiple-dispatch-oriented dynamic language - and Fortress, another numerical programming language with multiple dispatch and a sophisticated parametric type system. While Common Lisp Object System (CLOS) adds multiple dispatch to Common Lisp, not all functions are generic functions.

In Julia, Dylan and Fortress extensibility is the default, and the system's built-in functions are all generic and extensible. In Dylan, multiple dispatch is as fundamental as it is in Julia: all user-defined functions and even basic built-in operations like + are generic. Dylan's type system, however, does not fully support parametric types, which are more typical of the ML lineage of languages. By default, CLOS does not allow for dispatch on Common Lisp's parametric types; such extended dispatch semantics can only be added as an extension through the CLOS Metaobject Protocol. By convergent design, Fortress also features multiple dispatch on parametric types; unlike Julia, however, Fortress is statically rather than dynamically typed, with separate compiling and executing phases. The language features are summarized in the following table:

By default, the Julia runtime must be pre-installed as user-provided source code is run, while another way is possible, where a standalone executable can be made that needs no Julia source code built with BuildExecutable.jl.

Julia's syntactic macros (used for metaprogramming), like Lisp macros, are more powerful and different from text-substitution macros used in the preprocessor of some other languages such as C, because they work at the level of abstract syntax trees (ASTs). Julia's macro system is hygienic, but also supports deliberate capture when desired (like for anaphoric macros) using the esc construct.


Julia Machine Learning Video



Interaction

The Julia official distribution includes an interactive session shell, called Julia's read-eval-print loop (REPL), which can be used to experiment and test code quickly. The following fragment represents a sample session on the REPL:

The REPL gives user access to the system shell and to help mode, by pressing ; or ? after the prompt (preceding each command), respectively. The REPL also keeps the history of commands, even between sessions. For other examples, see the Julia documentation, which gives code that can be tested inside the Julia's interactive section or saved into a file with a .jl extension and run from the command line by typing (for example):

  $ julia <filename>  

Julia is also supported by Jupyter, an online interactive "notebooks" environment (project Jupyter is a multi-language extension, that "evolved", from the IPython command shell; now includes IJulia). See for other ways in the next section.

Use with other languages

Julia's ccall keyword is used to call C-exported or Fortran shared library functions individually.

Julia has Unicode 9.0 support, with UTF-8 used for source code (and by default for strings) and e.g. optionally allowing common math symbols for many operators, such as ? for the in operator.

Julia has packages supporting markup languages such as HTML, (and also for HTTP), XML, JSON and BSON.


Julia for Data Science Book | Data Science 101
photo src: 101.datascience.community


Implementation

Julia's core is implemented in C and C++ (the LLVM dependency is in C++), its parser in Scheme ("femtolisp"), and the LLVM compiler framework is used for just-in-time (JIT) generation of 64-bit or 32-bit optimized machine code (i.e. not for VM) depending on the platform Julia runs on. With some exceptions (e.g., libuv), the standard library is implemented in Julia itself. The most notable aspect of Julia's implementation is its speed, which is often within a factor of two relative to fully optimized C code (and thus often an order of magnitude faster than Python or R). Development of Julia began in 2009 and an open-source version was publicized in February 2012.

Julia, the 0.5.x line, is on a monthly release schedule where bugs are fixed and some new features from 0.6-dev are backported (and possibly also to 0.4.x).

Current and future platforms

While Julia uses JIT (MCJIT from LLVM) - it still means Julia generates native machine code, directly, before a function is first run (not a bytecode that is run on a virtual machine (VM) or translated as the bytecode is running, as with e.g., Java; the JVM or Dalvik in Android).

Current support is for 32- and 64-bit (all except for ancient pre-Pentium 4-era, to optimize for newer) x86 processors (and with download of executables or source code also available for other architectures). Experimental and early support for ARM, AArch64, and POWER (little-endian) is available too. Including support for Raspberry Pi 1 and later (e.g., requires at least ARMv6).

Support for GNU Hurd is being worked on.

Julia version 0.6 is planned for 2016 and 1.0 for 2017 and some features are discussed for 2+ that is also planned, e.g., "multiple inheritance for abstract types".

Julia2C source-to-source compiler

A Julia2C source-to-source compiler from Intel Labs is available. This compiler is a fork of Julia, that implements the same Julia language syntax, which emits C code (for compatibility with more CPUs) instead of native machine code, as an intermediate language, for functions or whole programs. The compiler is also meant to allow analyzing code at a higher level than C.

Intel's ParallelAccelerator.jl can be thought of as a partial Julia to C++ compiler (and then to machine code transparently), but the objective is parallel speedup (can be "100x over plain Julia", for the older 0.4 version, and could in cases also speed up serial code manyfold for that version); not compiling the full Julia language to C++ (C++ is only an implementation detail, later versions might not compile to C++). It doesn't need to compile all of Julia's syntax, as the rest is handled by Julia.

Source of the article : Wikipedia



EmoticonEmoticon

 

Start typing and press Enter to search