mollusk 0e4acfb8f2 fix incorrect folder name for julia-0.6.x
Former-commit-id: ef2c7401e0876f22d2f7762d182cfbcd5a7d9c70
2018-06-11 03:28:36 -07:00

77 lines
18 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Getting Started · The Julia Language</title><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-28835595-6', 'auto');
ga('send', 'pageview');
</script><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css" rel="stylesheet" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link href="../assets/documenter.css" rel="stylesheet" type="text/css"/><link href="../assets/julia-manual.css" rel="stylesheet" type="text/css"/></head><body><nav class="toc"><a href="../index.html"><img class="logo" src="../assets/logo.png" alt="The Julia Language logo"/></a><h1>The Julia Language</h1><select id="version-selector" onChange="window.location.href=this.value" style="visibility: hidden"></select><form class="search" id="search-form" action="../search.html"><input id="search-query" name="q" type="text" placeholder="Search docs"/></form><ul><li><a class="toctext" href="../index.html">Home</a></li><li><span class="toctext">Manual</span><ul><li><a class="toctext" href="introduction.html">Introduction</a></li><li class="current"><a class="toctext" href="getting-started.html">Getting Started</a><ul class="internal"><li><a class="toctext" href="#Resources-1">Resources</a></li></ul></li><li><a class="toctext" href="variables.html">Variables</a></li><li><a class="toctext" href="integers-and-floating-point-numbers.html">Integers and Floating-Point Numbers</a></li><li><a class="toctext" href="mathematical-operations.html">Mathematical Operations and Elementary Functions</a></li><li><a class="toctext" href="complex-and-rational-numbers.html">Complex and Rational Numbers</a></li><li><a class="toctext" href="strings.html">Strings</a></li><li><a class="toctext" href="functions.html">Functions</a></li><li><a class="toctext" href="control-flow.html">Control Flow</a></li><li><a class="toctext" href="variables-and-scoping.html">Scope of Variables</a></li><li><a class="toctext" href="types.html">Types</a></li><li><a class="toctext" href="methods.html">Methods</a></li><li><a class="toctext" href="constructors.html">Constructors</a></li><li><a class="toctext" href="conversion-and-promotion.html">Conversion and Promotion</a></li><li><a class="toctext" href="interfaces.html">Interfaces</a></li><li><a class="toctext" href="modules.html">Modules</a></li><li><a class="toctext" href="documentation.html">Documentation</a></li><li><a class="toctext" href="metaprogramming.html">Metaprogramming</a></li><li><a class="toctext" href="arrays.html">Multi-dimensional Arrays</a></li><li><a class="toctext" href="linear-algebra.html">Linear algebra</a></li><li><a class="toctext" href="networking-and-streams.html">Networking and Streams</a></li><li><a class="toctext" href="parallel-computing.html">Parallel Computing</a></li><li><a class="toctext" href="dates.html">Date and DateTime</a></li><li><a class="toctext" href="interacting-with-julia.html">Interacting With Julia</a></li><li><a class="toctext" href="running-external-programs.html">Running External Programs</a></li><li><a class="toctext" href="calling-c-and-fortran-code.html">Calling C and Fortran Code</a></li><li><a class="toctext" href="handling-operating-system-variation.html">Handling Operating System Variation</a></li><li><a class="toctext" href="environment-variables.html">Environment Variables</a></li><li><a class="toctext" href="embedding.html">Embedding Julia</a></li><li><a class="toctext" href="packages.html">Packages</a></li><li><a class="toctext" href="profile.html">Profiling</a></li><li><a class="toctext" href="stacktraces.html">Stack Traces</a></li><li><a class="toctext" href="performance-tips.html">Performance Tips</a></li><li><a class="toctext" href="workflow-tips.html">Workflow Tips</a></li><li><a class="toctext" href="style-guide.html">Style Guide</a></li><li><a class="toctext" href="faq.html">Frequently Asked Questions</a></li><li><a class="toctext" href="noteworthy-differences.html">Noteworthy Differences from other Languages</a></li><li><a class="toctext" href="unicode-input.html">Unicode Input</a></li></ul></li><li><span class="toctext">Standard Library</span><ul><li><a class="toctext" href="../stdlib/base.html">Essentials</a></li><li><a class="toctext" href="../stdlib/collections.html">Collections and Data Structures</a></li><li><a class="toctext" href="../stdlib/math.html">Mathematics</a></li><li><a class="toctext" href="../stdlib/numbers.html">Numbers</a></li><li><a class="toctext" href="../stdlib/strings.html">Strings</a></li><li><a class="toctext" href="../stdlib/arrays.html">Arrays</a></li><li><a class="toctext" href="../stdlib/parallel.html">Tasks and Parallel Computing</a></li><li><a class="toctext" href="../stdlib/linalg.html">Linear Algebra</a></li><li><a class="toctext" href="../stdlib/constants.html">Constants</a></li><li><a class="toctext" href="../stdlib/file.html">Filesystem</a></li><li><a class="toctext" href="../stdlib/io-network.html">I/O and Network</a></li><li><a class="toctext" href="../stdlib/punctuation.html">Punctuation</a></li><li><a class="toctext" href="../stdlib/sort.html">Sorting and Related Functions</a></li><li><a class="toctext" href="../stdlib/pkg.html">Package Manager Functions</a></li><li><a class="toctext" href="../stdlib/dates.html">Dates and Time</a></li><li><a class="toctext" href="../stdlib/iterators.html">Iteration utilities</a></li><li><a class="toctext" href="../stdlib/test.html">Unit Testing</a></li><li><a class="toctext" href="../stdlib/c.html">C Interface</a></li><li><a class="toctext" href="../stdlib/libc.html">C Standard Library</a></li><li><a class="toctext" href="../stdlib/libdl.html">Dynamic Linker</a></li><li><a class="toctext" href="../stdlib/profile.html">Profiling</a></li><li><a class="toctext" href="../stdlib/stacktraces.html">StackTraces</a></li><li><a class="toctext" href="../stdlib/simd-types.html">SIMD Support</a></li></ul></li><li><span class="toctext">Developer Documentation</span><ul><li><a class="toctext" href="../devdocs/reflection.html">Reflection and introspection</a></li><li><span class="toctext">Documentation of Julia&#39;s Internals</span><ul><li><a class="toctext" href="../devdocs/init.html">Initialization of the Julia runtime</a></li><li><a class="toctext" href="../devdocs/ast.html">Julia ASTs</a></li><li><a class="toctext" href="../devdocs/types.html">More about types</a></li><li><a class="toctext" href="../devdocs/object.html">Memory layout of Julia Objects</a></li><li><a class="toctext" href="../devdocs/eval.html">Eval of Julia code</a></li><li><a class="toctext" href="../devdocs/callconv.html">Calling Conventions</a></li><li><a class="toctext" href="../devdocs/compiler.html">High-level Overview of the Native-Code Generation Process</a></li><li><a class="toctext" href="../devdocs/functions.html">Julia Functions</a></li><li><a class="toctext" href="../devdocs/cartesian.html">Base.Cartesian</a></li><li><a class="toctext" href="../devdocs/meta.html">Talking to the compiler (the <code>:meta</code> mechanism)</a></li><li><a class="toctext" href="../devdocs/subarrays.html">SubArrays</a></li><li><a class="toctext" href="../devdocs/sysimg.html">System Image Building</a></li><li><a class="toctext" href="../devdocs/llvm.html">Working with LLVM</a></li><li><a class="toctext" href="../devdocs/stdio.html">printf() and stdio in the Julia runtime</a></li><li><a class="toctext" href="../devdocs/boundscheck.html">Bounds checking</a></li><li><a class="toctext" href="../devdocs/locks.html">Proper maintenance and care of multi-threading locks</a></li><li><a class="toctext" href="../devdocs/offset-arrays.html">Arrays with custom indices</a></li><li><a class="toctext" href="../devdocs/libgit2.html">Base.LibGit2</a></li><li><a class="toctext" href="../devdocs/require.html">Module loading</a></li></ul></li><li><span class="toctext">Developing/debugging Julia&#39;s C code</span><ul><li><a class="toctext" href="../devdocs/backtraces.html">Reporting and analyzing crashes (segfaults)</a></li><li><a class="toctext" href="../devdocs/debuggingtips.html">gdb debugging tips</a></li><li><a class="toctext" href="../devdocs/valgrind.html">Using Valgrind with Julia</a></li><li><a class="toctext" href="../devdocs/sanitizers.html">Sanitizer support</a></li></ul></li></ul></li></ul></nav><article id="docs"><header><nav><ul><li>Manual</li><li><a href="getting-started.html">Getting Started</a></li></ul><a class="edit-page" href="https://github.com/JuliaLang/julia/blob/master/doc/src/manual/getting-started.md"><span class="fa"></span> Edit on GitHub</a></nav><hr/><div id="topbar"><span>Getting Started</span><a class="fa fa-bars" href="#"></a></div></header><h1><a class="nav-anchor" id="Getting-Started-1" href="#Getting-Started-1">Getting Started</a></h1><p>Julia installation is straightforward, whether using precompiled binaries or compiling from source. Download and install Julia by following the instructions at <a href="https://julialang.org/downloads/">https://julialang.org/downloads/</a>.</p><p>The easiest way to learn and experiment with Julia is by starting an interactive session (also known as a read-eval-print loop or &quot;repl&quot;) by double-clicking the Julia executable or running <code>julia</code> from the command line:</p><pre><code class="language-none">$ julia
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type &quot;?help&quot; for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.5.0-dev+2440 (2016-02-01 02:22 UTC)
_/ |\__&#39;_|_|_|\__&#39;_| | Commit 2bb94d6 (11 days old master)
|__/ | x86_64-apple-darwin13.1.0
julia&gt; 1 + 2
3
julia&gt; ans
3</code></pre><p>To exit the interactive session, type <code>^D</code> the control key together with the <code>d</code> key or type <code>quit()</code>. When run in interactive mode, <code>julia</code> displays a banner and prompts the user for input. Once the user has entered a complete expression, such as <code>1 + 2</code>, and hits enter, the interactive session evaluates the expression and shows its value. If an expression is entered into an interactive session with a trailing semicolon, its value is not shown. The variable <code>ans</code> is bound to the value of the last evaluated expression whether it is shown or not. The <code>ans</code> variable is only bound in interactive sessions, not when Julia code is run in other ways.</p><p>To evaluate expressions written in a source file <code>file.jl</code>, write <code>include(&quot;file.jl&quot;)</code>.</p><p>To run code in a file non-interactively, you can give it as the first argument to the <code>julia</code> command:</p><pre><code class="language-none">$ julia script.jl arg1 arg2...</code></pre><p>As the example implies, the following command-line arguments to <code>julia</code> are taken as command-line arguments to the program <code>script.jl</code>, passed in the global constant <code>ARGS</code>. The name of the script itself is passed in as the global <code>PROGRAM_FILE</code>. Note that <code>ARGS</code> is also set when script code is given using the <code>-e</code> option on the command line (see the <code>julia</code> help output below) but <code>PROGRAM_FILE</code> will be empty. For example, to just print the arguments given to a script, you could do this:</p><pre><code class="language-none">$ julia -e &#39;println(PROGRAM_FILE); for x in ARGS; println(x); end&#39; foo bar
foo
bar</code></pre><p>Or you could put that code into a script and run it:</p><pre><code class="language-none">$ echo &#39;println(PROGRAM_FILE); for x in ARGS; println(x); end&#39; &gt; script.jl
$ julia script.jl foo bar
script.jl
foo
bar</code></pre><p>The <code>--</code> delimiter can be used to separate command-line args to the scriptfile from args to Julia:</p><pre><code class="language-none">$ julia --color=yes -O -- foo.jl arg1 arg2..</code></pre><p>Julia can be started in parallel mode with either the <code>-p</code> or the <code>--machinefile</code> options. <code>-p n</code> will launch an additional <code>n</code> worker processes, while <code>--machinefile file</code> will launch a worker for each line in file <code>file</code>. The machines defined in <code>file</code> must be accessible via a passwordless <code>ssh</code> login, with Julia installed at the same location as the current host. Each machine definition takes the form <code>[count*][user@]host[:port] [bind_addr[:port]]</code> . <code>user</code> defaults to current user, <code>port</code> to the standard ssh port. <code>count</code> is the number of workers to spawn on the node, and defaults to 1. The optional <code>bind-to bind_addr[:port]</code> specifies the ip-address and port that other workers should use to connect to this worker.</p><p>If you have code that you want executed whenever Julia is run, you can put it in <code>~/.juliarc.jl</code>:</p><pre><code class="language-none">$ echo &#39;println(&quot;Greetings! 你好! 안녕하세요?&quot;)&#39; &gt; ~/.juliarc.jl
$ julia
Greetings! 你好! 안녕하세요?
...</code></pre><p>There are various ways to run Julia code and provide options, similar to those available for the <code>perl</code> and <code>ruby</code> programs:</p><pre><code class="language-none">julia [switches] -- [programfile] [args...]
-v, --version Display version information
-h, --help Print this message
-J, --sysimage &lt;file&gt; Start up with the given system image file
--precompiled={yes|no} Use precompiled code from system image if available
--compilecache={yes|no} Enable/disable incremental precompilation of modules
-H, --home &lt;dir&gt; Set location of `julia` executable
--startup-file={yes|no} Load ~/.juliarc.jl
--handle-signals={yes|no} Enable or disable Julia&#39;s default signal handlers
-e, --eval &lt;expr&gt; Evaluate &lt;expr&gt;
-E, --print &lt;expr&gt; Evaluate and show &lt;expr&gt;
-L, --load &lt;file&gt; Load &lt;file&gt; immediately on all processors
-p, --procs {N|auto} Integer value N launches N additional local worker processes
&quot;auto&quot; launches as many workers as the number of local cores
--machinefile &lt;file&gt; Run processes on hosts listed in &lt;file&gt;
-i Interactive mode; REPL runs and isinteractive() is true
-q, --quiet Quiet startup (no banner)
--color={yes|no} Enable or disable color text
--history-file={yes|no} Load or save history
--compile={yes|no|all|min}Enable or disable JIT compiler, or request exhaustive compilation
-C, --cpu-target &lt;target&gt; Limit usage of cpu features up to &lt;target&gt;
-O, --optimize={0,1,2,3} Set the optimization level (default is 2 if unspecified or 3 if specified as -O)
-g, -g &lt;level&gt; Enable / Set the level of debug info generation (default is 1 if unspecified or 2 if specified as -g)
--inline={yes|no} Control whether inlining is permitted (overrides functions declared as @inline)
--check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)
--math-mode={ieee,fast} Disallow or enable unsafe floating point optimizations (overrides @fastmath declaration)
--depwarn={yes|no|error} Enable or disable syntax and method deprecation warnings (&quot;error&quot; turns warnings into errors)
--output-o name Generate an object file (including system image data)
--output-ji name Generate a system image data file (.ji)
--output-bc name Generate LLVM bitcode (.bc)
--output-incremental=no Generate an incremental output file (rather than complete)
--code-coverage={none|user|all}, --code-coverage
Count executions of source lines (omitting setting is equivalent to &quot;user&quot;)
--track-allocation={none|user|all}, --track-allocation
Count bytes allocated by each source line</code></pre><h2><a class="nav-anchor" id="Resources-1" href="#Resources-1">Resources</a></h2><p>In addition to this manual, there are various other resources that may help new users get started with Julia:</p><ul><li><p><a href="http://math.mit.edu/~stevenj/Julia-cheatsheet.pdf">Julia and IJulia cheatsheet</a></p></li><li><p><a href="https://learnxinyminutes.com/docs/julia/">Learn Julia in a few minutes</a></p></li><li><p><a href="https://github.com/chrisvoncsefalvay/learn-julia-the-hard-way">Learn Julia the Hard Way</a></p></li><li><p><a href="http://samuelcolvin.github.io/JuliaByExample/">Julia by Example</a></p></li><li><p><a href="https://github.com/dpsanders/hands_on_julia">Hands-on Julia</a></p></li><li><p><a href="http://homerreid.dyndns.org/teaching/18.330/JuliaProgramming.shtml">Tutorial for Homer Reid&#39;s numerical analysis class</a></p></li><li><p><a href="https://raw.githubusercontent.com/ViralBShah/julia-presentations/master/Fifth-Elephant-2013/Fifth-Elephant-2013.pdf">An introductory presentation</a></p></li><li><p><a href="https://julialang.org/blog/2013/03/julia-tutorial-MIT">Videos from the Julia tutorial at MIT</a></p></li><li><p><a href="https://www.youtube.com/user/JuliaLanguage/playlists">YouTube videos from the JuliaCons</a></p></li></ul><footer><hr/><a class="previous" href="introduction.html"><span class="direction">Previous</span><span class="title">Introduction</span></a><a class="next" href="variables.html"><span class="direction">Next</span><span class="title">Variables</span></a></footer></article></body></html>