Julia (programming language)

From Wikipedia, the free encyclopedia
  (Redirected from Julia language)
Jump to: navigation, search
Julia
Official Julia logo
Paradigm Multi-paradigm: multiple dispatch ("object-oriented"), procedural, functional, meta
Designed by Jeff Bezanson, Stefan Karpinski, Viral B. Shah, Alan Edelman
Developer Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and other contributors[1][2]
First appeared 2012; 3 years ago (2012)[3]
0.3.8 / 30 April 2015; 33 days ago (2015-04-30)[4][5]
0.4.0-dev / Updated daily
Dynamic with type inference and type annotations
OS Linux, OS X, FreeBSD, Windows
License MIT[1] / GPL v2[6][7] A make-file option drops the GPL libraries[8]
.jl
Website julialang.org

Julia is a high-level dynamic programming language designed to address the requirements of high-performance numerical and scientific computing while also being effective for general purpose programming,[10][11][12][13] even server/web use[14] or as a specification language.[15][16] Distinctive aspects of Julia's design include having a type system with parametric types in a fully dynamic programming language, and adopting multiple dispatch as its core programming paradigm. It allows for parallel and distributed computing, and direct calling of C and Fortran libraries without glue code. Julia is garbage collected,[17] uses eager evaluation, and includes efficient libraries for floating point, linear algebra, random number generation, fast Fourier transforms, and regular expression matching.

Language features[edit]

According to the official web site, 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 (also works for newer Python 3[18][19])
  • Call C functions directly: no wrappers or special APIs
  • Powerful shell-like capabilities for managing other processes
  • Designed for parallelism and distributed computation
  • 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

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 syntax rather than a Lisp-like prefix syntax) – also a multiple-dispatch-oriented dynamic language – and Fortress, another numerical programming language with multiple dispatch and a sophisticated parametric type system. While CLOS adds multiple dispatch to Common Lisp, the addition is opt-in: only user-defined functions explicitly declared to be generic can be extended with new multimethods.

In Julia, Dylan and Fortress, on the other hand, this 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 compilation and execution phases. This matrix of language features is summarized in the following table:

Language Type system Generic functions Parametric types
Julia dynamic default yes
Common Lisp dynamic opt-in yes (but no dispatch)
Dylan dynamic default partial (no dispatch)
Fortress static default yes

In version 0.4,[20] a standalone "executable that doesn't require any julia source code" can be built with build_executable.jl[21] while by default the Julia runtime needs to be pre-installed.

Interaction[edit]

The Julia official distribution includes an interactive session shell, called Julia's REPL, which can be used to experiment and test code quickly.[22] The following fragment represents a sample session on the REPL:

julia> p(x) = 2x^2 + 1; f(x, y) = 1 + 2p(x)y
julia> println("Hello world!", " I'm on cloud ", f(0, 4), 
               " as Julia supports recognizable syntax!")
Hello world! I'm on cloud 9 as Julia supports recognizable syntax![23]

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,[24] 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):[25]

$ julia <filename>

Packages[edit]

In the Julia packaging system each package is a Git repository that can be stored in any publicly accessible location. A master package listing that includes package dependency information is maintained in METADATA.jl,[26] enabling installation from the Julia prompt using Pkg.add("PackageName")

Packages are typically written in Julia but can also include source code written in C, Fortran, Python, or other languages (using BinDeps.jl), given a compiler is installed, that is automatically compiled at package install time by the package manager. Alternatively packages can include, using WinRPM.jl, machine code ("binaries")). To load the installed package into Julia, one can run using PackageName. As Julia is case sensitive, Using PackageName is not the same thing and produces an error. Updating Julia's installed packages can also be done using Pkg.update().

To use Julia with other languages[edit]

Many packages are available[27] e.g. to call other languages from within Julia. For example, a package, JavaCall.jl, is available to call Java from Julia;[28] Mathematica.jl, to call Mathematica,[29] calling Rust is possible,[30][31] and node-julia allows using (but currently not on Windows)[14] with JavaScript/node.js for asynchronous processing (web-)server use. Julia has native and wrapper packages for symbolic computation.

By default, Julia has support for UTF-8, UTF-16 and UTF-32 but for deeper Unicode support also has optional packages ICU.jl (a wrapper for International Components for Unicode) and UnicodeExtras.jl.

Other[edit]

There are wrapper (or meta-wrapper) libraries to work with graphical user interfaces (GUIs), such as cross-platform (for, at least, Linux, Windows and OS X) GTK+ (uses PySide written in Python), Qt or Tk – or JGUI.jl that hides the differences of those and works with what is available. Also for "creating and working with browser windows" Blink.jl is available.

There are wrappers for many individual SQL or NoSQL databases and generic ODBC.jl for cross-database access.

While Julia uses eager evaluation, a package Lazy.jl providing "cornerstones of functional programming - lazily-evaluated lists and a large library of functions for working with them"[32]

For use in statistics/data analysis[edit]

Julia was created to be "as easy for statistics as R" as one of its goals.[3]

When Julia may not have some software library for statistics, a package RCall.jl and another Rif.jl is available for Julia for "calling R whenever it has a library that would be needed"[33] (and vice versa, RJulia.jl to call Julia from R).

Also at least one package Gadfly.jl is available for Julia for "statistical graphics" a "plotting and data visualization system written in Julia".[34] For working with distributions a package Distributions.jl is available.[35]

As for what comes with Julia itself (without installing R and using together): "Rmath is a library from R, which includes basic statistical functions. Julia uses a patched version of Rmath, which uses DSFMT as its underlying generator, and faster normal random number generators."[36][37]

One academic said: "Julia code looks very much like R code and/or Matlab/Octave code. It is, of course, not identical but sufficiently similar to be readable."[38]

"There are now several packages that, taken as a whole, suggest that Julia may really live up to its potential and become the next generation language for data analysis."[39] See here for STATISTICS section (and OPERATIONS RESEARCH, Econometrics and Valuation - Finance) as an overview.

"In practical terms, multiple dispatch turns object-oriented programming on its head, instead of encapsulating functions or methods inside data structures or objects, functions are effectively overloaded on different data structures. The object oriented paradigm is not a natural way for data-scientists or algorithmists to work, one of the great things about R is to allow programs to be created quickly and simply by providing a nice and powerful programming interface. Julia takes this one step further and makes it explicit and clear, that we are writing functions for specific data structures - but with an option to write "catch-all" functions to deal with any data type [..] Sometimes people ask whether R or Python will be the most used "data science" programming language, we now have a dark horse, a late entrant to the race, a new kid on the block that could one day grab this particular crown."[40]

Displaying assembly code[edit]

You can see the compiled assembly code for any just typed in function (for built-in, after it has been run at least once); including in-built functions such as the operator + that is just a function through syntactic sugar:

julia> code_native(+, (Float64, Float64))
Warning: Unable to find function pointer
ERROR: no method found for the specified argument types
 in code_native at reflection.jl:159
 
julia> 1.0 + 2.0
3.0
julia> code_native(+, (Float64, Float64))
	.text
Filename: float.jl
Source line: 120
	push	RBP
	mov	RBP, RSP
Source line: 120
	addsd	XMM0, XMM1
	pop	RBP
	ret

Implementation[edit]

Julia's core is implemented in C and 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 (e.g. not for VM[41]) 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).[42] Development of Julia began in 2009 and an open-source version was publicized in February 2012.[3][43]

Julia uses a mark and sweep garbage collection (GC) algorithm. For typical HPC number-crunching, that choice is not a problem, but for real-time-sensitive such as audio work it can be, where an incremental implementation for Julia does much better.[44] It was marked as a milestone for version 0.4, but only generational GC behavior had been merged into that version (but it can be two times faster).[45]

Julia, the 0.3 line, is on a monthly release schedule where bugs are fixed and some new things from 0.4 are backported.[46]

Current and future platforms[edit]

While Julia uses JIT[47] (MCJIT[48] from LLVM) – Julia generates native machine code, directly, the first time a function is run (not bytecode to run on a VM, as e.g. with Java/Dalvik).

Current support is for newer x86 or older i386 processors and in 0.4.0-dev, 32-bit ARMv7 ("Experimental and early support"[49] with "work in progress - several tests are known to fail, and backtraces are not available"[50] with alpha support for Raspberry Pi 1/2[51][52] but "[on ARMv7] Samsung Chromebook [..] Julia starts up just fine"[53]), and PowerPC being worked on.[54][55]

Embedding in other languages[edit]

The Julia C API allows using Julia (the whole runtime/libraries); calling Julia functions from C without needing to copy data. As most languages can call C, those other languages can also be supported (unless the target CPU is not supported by all three), such as C++, potentially C# (for C#, 0.4 is required for Windows 8.1 but older Windows may work in stable release[56]), or Python[57] which currently is also supported for calling in the other direction (even recursively).[58] In languages that support exceptions, Julia's exceptions can be caught and rethrown natively as in the languages mentioned here (except for C that does not have exceptions; in those languages Julia's exceptions should be caught and handled).

A library to call C++ (without using C to avoid name-mangling issues) is available that relies on "staged functions", a feature only available in 0.4.0-dev.

Compilation of Julia to JavaScript for execution in a browser is in progress.[59]

Julia2C source-to-source compiler[edit]

A Julia2C source-to-source compiler from Intel Labs is available.[60] This source-to-source compiler is a fork of Julia, that implements the same Julia language syntax, which emits C code instead of native machine code, for functions or whole programs. It is also meant to be easier to analyze than C.[61]

References[edit]

  1. ^ a b "LICENSE.md". GitHub. 
  2. ^ "Contributors to JuliaLang/julia". GitHub. 
  3. ^ a b c "Why We Created Julia". Julia website. February 2012. Retrieved 7 February 2013. 
  4. ^ https://github.com/JuliaLang/julia/releases/tag/v0.3.8
  5. ^ https://github.com/JuliaLang/julia/tree/v0.3.8
  6. ^ https://julialang.org
  7. ^ Non-GPL Julia?
  8. ^ "Introduce USE_GPL_LIBS Makefile flag to build Julia without GPL libraries". Note that this commit does not remove GPL utilities such as git and busybox that are included in the Julia binary installers on Mac and Windows. It lets you build from source without any GPL library dependencies. 
  9. ^ http://julia.readthedocs.org/en/latest/manual/introduction/
  10. ^ "The Julia Language" (official website). 
  11. ^ Bryant, Avi (15 October 2012). "Matlab, R, and Julia: Languages for data analysis". O'Reilly Strata. 
  12. ^ Krill, Paul (18 April 2012). "New Julia language seeks to be the C for scientists". InfoWorld. 
  13. ^ Finley, Klint (3 February 2014). "Out in the Open: Man Creates One Programming Language to Rule Them All". Wired. 
  14. ^ a b "Limitations". node-julia. 
  15. ^ "JuliaCon 2015: Preliminary Schedule". 24–28 June 2015. Retrieved 16 May 2015. Robert Moss, Using Julia as a Specification Language for the Next-Generation Airborne Collision Avoidance System 
  16. ^ Shah, Viral (16 May 2015). "Julia will always be open source". 
  17. ^ "Suspending Garbage Collection for Performance...good idea or bad idea?". 
  18. ^ https://groups.google.com/forum/#!topic/julia-users/lDM7-YXT2LU
  19. ^ https://github.com/stevengj/PyCall.jl/blob/master/src/PyCall.jl#L419
  20. ^ https://groups.google.com/forum/#!topic/julia-users/MtF4wHc77sw
  21. ^ build_executable.jl
  22. ^ Julia REPL documentation
  23. ^ See also: http://julia.readthedocs.org/en/latest/manual/strings/ for string interpolation and the string(greet, ", ", whom, ".\n") example for preferred ways to concatenate strings. While the + operator is not used for string concatenation, it could easily be defined to do so. Julia has the println and print functions, but also a @printf macro, while not in a function form, to eliminate run-time overhead of formatting (unlike the same function in C).
  24. ^ "Julia Documentation". julialang.org. Retrieved 18 November 2014. 
  25. ^ Learn Julia in Y Minutes
  26. ^ "METADATA.jl" (central package listing for Julia)
  27. ^ "Julia Package Library". Julialang.org. Retrieved 18 November 2014. 
  28. ^ http://aviks.github.io/JavaCall.jl/
  29. ^ "calling Julia from Mathematica". Retrieved 9 April 2015. 
  30. ^ "Using Rust from Perl and Julia". Retrieved 15 May 2015. Julia is even easier to use [than Perl, in the given example] 
  31. ^ Karpinski, Stefan (5 September 2013). "Julia and the Rust Language". Retrieved 15 May 2015. Since Rust uses the C ABI, we can already call Rust libraries just as well as C. I have no idea what Erlang's ABI is like, but if it can expose a C ABI, then we can call it. Beyond that would take some work but is certainly possible. 
  32. ^ https://github.com/one-more-minute/Lazy.jl
  33. ^ https://github.com/lgautier/Rif.jl
  34. ^ statistical graphics for Julia
  35. ^ http://distributionsjl.readthedocs.org/en/latest/
  36. ^ http://dmbates.blogspot.com/2012/03/julia-functions-for-rmath-library.html
  37. ^ https://github.com/JuliaLang/julia/blob/master/DISTRIBUTING.md
  38. ^ http://www.stat.wisc.edu/~bates/JuliaForRProgrammers.pdf
  39. ^ http://www.johnmyleswhite.com/notebook/2012/12/02/the-state-of-statistics-in-julia/
  40. ^ http://active-analytics.com/blog/chainladder-julia-r-rcpp/
  41. ^ "Chris Lattner discusses the name LLVM". Retrieved 22 December 2011. 
  42. ^ "Julia: A Fast Dynamic Language for Technical Computing" (PDF). 2012. 
  43. ^ Gibbs, Mark (9 January 2013). "Pure and Julia are cool languages worth checking out". Network World (column). Retrieved 7 February 2013. 
  44. ^ https://github.com/JuliaLang/julia/pull/5227 WIP: Incremental GC
  45. ^ https://github.com/JuliaLang/julia/pull/8699 Generational behavior for the garbage collector
  46. ^ https://github.com/JuliaLang/julia/issues/9045
  47. ^ "Support MCJIT". Retrieved 26 May 2015. 
  48. ^ "Using MCJIT with the Kaleidoscope Tutorial". 22 July 2013. Retrieved 26 May 2015. 
  49. ^ https://github.com/JuliaLang/julia/
  50. ^ https://github.com/JuliaLang/julia/blob/master/README.arm.md
  51. ^ "Cross-compiling for ARMv6". Retrieved 16 May 2015. I believe #10917 should fix this. The CPU used there arm1176jzf-s. 
  52. ^ "ARM build failing during bootstrap on Raspberry Pi 2". Retrieved 16 May 2015. I can confirm (FINALLY) that it works on the Raspberry Pi 2 [..] I guess we can announce alpha support for arm in 0.4 as well. 
  53. ^ https://github.com/JuliaLang/julia/issues/10488
  54. ^ https://github.com/JuliaLang/julia/blob/master/Make.powerpc
  55. ^ "Porting Julia to PowerPC". Retrieved 9 May 2015. Wow, the latest git allows me to build to completion. 
  56. ^ "Unable to use 'libjulia.dll' in a C# application on Windows 8.1". 
  57. ^ https://github.com/JuliaLang/pyjulia
  58. ^ http://julia.readthedocs.org/en/latest/manual/embedding/
  59. ^ "Support compiling to JavaScript with Emscripten". Retrieved 28 January 2015. 
  60. ^ https://github.com/IntelLabs/julia/tree/j2c/j2c
  61. ^ "Julia2C initial release". By translating Julia to C, we leverage the high-level abstractions (matrix, vector, ..), which are easier to analyze, and can potentially add the rich extensions of C (like openmp, tbb, ...).
    The tool may also extend Julia to new architectures where the only available tool chain is for C [..]
    Translation from C to Julia might be harder.
     

External links[edit]