Jump to content

Julia (programming language): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m typo
Many languages support web site creation
Line 52: Line 52:
| publisher = Wired
| publisher = Wired
| date = 3 February 2014
| date = 3 February 2014
}}</ref> even web use<ref name="Escher.jl">{{cite web |url=https://shashi.github.io/Escher.jl/ |title=Escher lets you build beautiful interactive Web UIs in Julia |accessdate=27 July 2015}}</ref><ref name = "node-js"/> or as a [[specification language]].<ref name="spec">{{cite web |url=http://juliacon.org/talks.html#friday
}}</ref> web use<ref name="Escher.jl">{{cite web |url=https://shashi.github.io/Escher.jl/ |title=Escher lets you build beautiful interactive Web UIs in Julia |accessdate=27 July 2015}}</ref><ref name = "node-js"/> or as a [[specification language]].<ref name="spec">{{cite web |url=http://juliacon.org/talks.html#friday
|first=Robert |last=Moss
|first=Robert |last=Moss
|title=Using Julia as a Specification Language for the Next-Generation Airborne Collision Avoidance System
|title=Using Julia as a Specification Language for the Next-Generation Airborne Collision Avoidance System

Revision as of 09:01, 20 October 2015

Julia
Official Julia logo
ParadigmMulti-paradigm: multiple dispatch ("object-oriented"), procedural, functional, meta
Designed byJeff Bezanson, Stefan Karpinski, Viral B. Shah, Alan Edelman
DeveloperJeff Bezanson, Stefan Karpinski, Viral B. Shah, and other contributors[1][2]
First appeared2012; 12 years ago (2012)[3]
Stable release
0.4.0 / 8 October 2015; 8 years ago (2015-10-08)[4]
Preview release
0.5.0-dev / updated daily
Typing disciplineDynamic with type inference and type annotations (optional manifest typing)
OSLinux, OS X, FreeBSD, Windows
LicenseMIT[1] / GPL v2[5][6] A make-file option drops the GPL libraries[7]
Filename extensions.jl
Websitejulialang.org
Influenced by
MATLAB, Lisp, C, Fortran, Mathematica[3] (strictly its Wolfram Language), Python, Perl, R, Ruby, Lua[8]

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,[9][10][11][12] web use[13][14] or as a specification language.[15] 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 concurrent, parallel and distributed computing, and direct calling of C and Fortran libraries without glue code. Julia is garbage-collected,[16] uses eager evaluation, and includes efficient libraries for floating-point calculations, linear algebra, random number generation, fast Fourier transforms, and regular expression matching.

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[a]
  • 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

Multiple dispatch (also known as multimethods in Lisp) is a generalization of single dispatch – the polymorphic mechanism used in common object oriented (OO) 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"[20] 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 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.

Julia's macros – also known as hygienic macros, used to implement metaprogramming, similar to macros used in Lisp – are more powerful and different from non-hygienic macros used in some other languages such as C.

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

Interaction

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

 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!

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

$ 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.

To use Julia with other languages

Julia's ccall keyword is used to call C-exported (or Fortran) shared library functions individually or: "Clang.jl includes a generator to create Julia wrappers for C libraries from a collection of header files. [..] Clang.jl tends to be used on large codebases".[25] Calling name mangled C++ functions directly is possible, but a "library to call C++ (without using C to avoid name-mangling issues) is available that relies on "staged functions", that requires 0.4.0."[26]

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 (and Scala or other JVM languages) from Julia;[28] Mathematica.jl, to call Mathematica,[29] ObjectiveC.jl "allows you to call Objective-C methods using native syntax",[30] support for using with Erlang is possible with ErlPort.jl, calling Rust is possible,[31][32] and node-julia allows using[14] JavaScript/node.js for asynchronous processing web/server use. For PHP, Perl and more languages (and PyPy), Polyglot.jl allows "transparent remote/recursive evaluation [calling] functions in other languages as if they were regular Julia functions. It also allows other languages to call Julia functions as if they were native."[19] For use with Ruby see the For web use-section. Julia also has native and wrapper packages for symbolic computation.

An interface "between Julia and Torch (Lua) using ZMQ" is available for machine learning.[33]

Julia has Unicode support, with UTF-8 used for source code and e.g. optionally allowing common math symbols for many operators, such as ∈ for the in operator. For strings UTF-8, UTF-16 and UTF-32 (and ASCII) are fully supported encodings, but for more support, see optional packages ICU.jl (a wrapper for International Components for Unicode) and UnicodeExtras.jl.

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

Displaying assembly code

It is possible to display the compiled assembly code for any function typed in the REPL (for built-in functions, this is only true after they have been run at least once). For instance, the operator +, which 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

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 (e.g. not for VM[34]) 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).[35] Development of Julia began in 2009 and an open-source version was publicized in February 2012.[3][36]

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

Current and future platforms

While Julia uses JIT[38] (MCJIT[39] 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: 32-bit ARM architecture ("Experimental and early support"[40] with "work in progress - several tests are known to fail, and backtraces are not available"[41] with alpha support for Raspberry Pi 1/2[42][43] but "[on ARMv7] Samsung Chromebook [..] Julia starts up just fine"[44]), 64-bit ARMv8[45] and PowerPC being worked on.[46][47]

Julia2C source-to-source compiler

A Julia2C source-to-source compiler from Intel Labs is available.[48] This source-to-source 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, for functions or whole programs. The compiler is also meant to allow analyzing code at a higher level than C.[49]

Notes

  1. ^ Calling newer Python 3 also works[17][18] (and PyPy[19]) and calling in the other direction, from Python to Julia, is also supported with pyjulia. Even calling recursively (back and forth) between these languages is possible, without (or with) using Polyglot.jl, that supports additional languages to Python.

References

  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.4.0
  5. ^ https://julialang.org
  6. ^ Non-GPL Julia?
  7. ^ "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.
  8. ^ http://julia.readthedocs.org/en/latest/manual/introduction/
  9. ^ "The Julia Language" (official website).
  10. ^ Bryant, Avi (15 October 2012). "Matlab, R, and Julia: Languages for data analysis". O'Reilly Strata.
  11. ^ Krill, Paul (18 April 2012). "New Julia language seeks to be the C for scientists". InfoWorld.
  12. ^ Finley, Klint (3 February 2014). "Out in the Open: Man Creates One Programming Language to Rule Them All". Wired.
  13. ^ "Escher lets you build beautiful interactive Web UIs in Julia". Retrieved 27 July 2015.
  14. ^ a b "Getting Started with Node Julia". node-julia.
  15. ^ Moss, Robert (26 June 2015). "Using Julia as a Specification Language for the Next-Generation Airborne Collision Avoidance System". Retrieved 29 June 2015. Airborne collision avoidance system
  16. ^ "Suspending Garbage Collection for Performance...good idea or bad idea?".
  17. ^ https://groups.google.com/forum/#!topic/julia-users/lDM7-YXT2LU
  18. ^ https://github.com/stevengj/PyCall.jl/blob/master/src/PyCall.jl#L419
  19. ^ a b https://github.com/wavexx/Polyglot.jl
  20. ^ http://learnxinyminutes.com/docs/julia/
  21. ^ Julia REPL documentation
  22. ^ 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).
  23. ^ "Julia Documentation". julialang.org. Retrieved 18 November 2014.
  24. ^ Learn Julia in Y Minutes
  25. ^ https://github.com/ihnorton/Clang.jl
  26. ^ https://github.com/Keno/Cxx.jl
  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. ^ https://github.com/one-more-minute/ObjectiveC.jl
  31. ^ "Using Rust from Perl and Julia". Retrieved 15 May 2015. Julia is even easier to use with our Rust library [than Perl with their Rust library]
  32. ^ 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.
  33. ^ https://github.com/mrkulk/Julia-Torch Julia-Tourch
  34. ^ "Chris Lattner discusses the name LLVM". Retrieved 22 December 2011.
  35. ^ "Julia: A Fast Dynamic Language for Technical Computing" (PDF). 2012.
  36. ^ Gibbs, Mark (9 January 2013). "Pure and Julia are cool languages worth checking out". Network World (column). Retrieved 7 February 2013.
  37. ^ https://github.com/JuliaLang/julia/issues/9045
  38. ^ "Support MCJIT". Retrieved 26 May 2015.
  39. ^ "Using MCJIT with the Kaleidoscope Tutorial". 22 July 2013. Retrieved 26 May 2015.
  40. ^ https://github.com/JuliaLang/julia/
  41. ^ https://github.com/JuliaLang/julia/blob/master/README.arm.md
  42. ^ "Cross-compiling for ARMv6". Retrieved 16 May 2015. I believe #10917 should fix this. The CPU used there arm1176jzf-s.
  43. ^ "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. {{cite web}}: line feed character in |quote= at position 65 (help)
  44. ^ https://github.com/JuliaLang/julia/issues/10488
  45. ^ https://github.com/JuliaLang/julia/issues/10791#issuecomment-91735439
  46. ^ https://github.com/JuliaLang/julia/blob/master/Make.powerpc
  47. ^ "Porting Julia to PowerPC". Retrieved 9 May 2015. Wow, the latest git allows me to build to completion.
  48. ^ https://github.com/IntelLabs/julia/tree/j2c/j2c
  49. ^ "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.
    {{cite web}}: line feed character in |quote= at position 196 (help)

External links