Julia – 112 – suggerimenti operativi

Continuo da qui, copio qui.

Here are some tips for working with Julia efficiently.

Con la REPL
As already elaborated in Interacting With Julia [qui], Julia’s REPL provides rich functionality that facilitates an efficient interactive workflow. Here are some tips that might further enhance your experience at the command line.

Un editor nella REPL
The most basic Julia workflows involve using a text editor in conjunction with the julia command line. A common pattern includes the following elements:

  • Put code under development in a temporary module. Create a file, say Tmp.jl, and include within it
    module Tmp
     <your definitions here>

    Put your test code in another file. Create another file, say tst.jl, which begins with

  • import Tmp
    and includes tests for the contents of Tmp. The value of using import versus using is that you can call reload("Tmp") instead of having to restart the REPL when your definitions change. Of course, the cost is the need to prepend Tmp. to uses of names defined in your module. (You can lower that cost by keeping your module name short.)
    Alternatively, you can wrap the contents of your test file in a module, as

    module Tst
        using Tmp
        <scratch work>

    The advantage is that you can now do using Tmp in your test code and can therefore avoid prepending Tmp. everywhere. The disadvantage is that code can no longer be selectively copied to the REPL without some tweaking.

  • Lather. Rinse. Repeat. Explore ideas at the julia command prompt. Save good ideas in tst.jl. Occasionally restart the REPL, issuing

Semplificare l’inizializzazione
To simplify restarting the REPL, put project-specific initialization code in a file, say _init.jl, which you can run on startup by issuing the command:

julia -L _init.jl

If you further add the following to your .juliarc.jl file

isfile("_init.jl") && include(joinpath(pwd(), "_init.jl"))

then calling julia from that directory will run the initialization code without the additional command line argument.

Nel browser
It is also possible to interact with a Julia REPL in the browser via IJulia. See the package home for details.


Posta un commento o usa questo indirizzo per il trackback.



Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: