Racket – Eseguire e creare eseguibili – 1

CoreMemory03

Capitolo nuovo, [doc]/guide/running.html, impegnativo, lungo ma si comincia a vedere un barlume là in fondo al tunnel; poi si continua, nèh!

While developing programs, many Racket programmers use the DrRacket programming environment. To run a program without the development environment, use racket (for console-based programs) or gracket (for GUI programs). This chapter mainly explains how to run racket and gracket.

Io, perso, apprezzo DrRacket come editor (molto più immediato di Emacs/SLIME) per la corretta formattazione e cross-references; per le parentesi va (quasi) bene Gedit (o simili). Mi piace (tantissimissimo) la REPL fornita da racket con il turbo, fin da subito mi sono creato l’alias: rre='racket -il xrepl'.

Ma so di non sapere (cit.) quindi OK, passo a [doc]/guide/racket.html.

Eseguire racket e gracket

The gracket executable is the same as racket, but with small adjustments to behave as a GUI application rather than a console application. For example, gracket by default runs in interactive mode with a GUI window instead of a console prompt. GUI applications can be run with plain racket, however.

Depending on command-line arguments, racket or gracket runs in interactive mode, module mode, or load mode.

Modalità interattiva

When racket is run with no command-line arguments (other than confguration options, like -j [--no-jit : Disable the just-in-time compiler]), then it starts a REPL with a >  prompt:

e0

Note: For enhancing your REPL experience, see xrepl [[doc]/xrepl/index.html, quella che uso per il mio alias]; for information on GNU Readline support, see readline [[doc]/readline/index.html].

Nota: Uh! facciamo che farò una deviazione; il prossimo post tutto su readline 🙄

Ma per adesso continuo la lezione.
To initialize the REPL’s environment, racket first requires the racket/init module, which provides all of racket, and also installs pretty-print for display results. Finally, racket loads the file reported by (find-system-path 'init-file), if it exists, before starting the REPL.

If any command-line arguments are provided (other than configuration options), add -i or --repl to re-enable the REPL. For example,

e1

displays “hi Juhan” on start-up, but still presents a REPL.

If module-requiring flags appear before -i/--repl, they cancel the automatic requiring of racket/init. This behavior can be used to initialize the REPL’s environment with a different language. For example,

e2

starts a REPL using a much smaller initial language (that loads much faster). Beware that most modules do not provide the basic syntax of Racket, including function-call syntax and require. For example,

e3

produces a REPL that fails for every expression, because racket/date provides only a few functions, and not the #%top-interaction and #%app bindings that are needed to evaluate top-level function calls in the REPL.

If a module-requiring flag appears after -i/--repl instead of before it, then the module is required after racket/init to augment the initial environment. For example,

e4

starts a useful REPL with racket/date available in addition to the exports of racket.

Modalità modulo

If a file argument is supplied to racket before any command-line switch (other than configuration options), then the file is required as a module, and (unless -i/--repl is specified), no REPL is started. For example,

e5

requires the “hello.rkt” module and then exits. Any argument after the file name, flag or otherwise, is preserved as a command-line argument for use by the required module via current-command-line-arguments.

If command-line flags are used, then the -u or --require-script flag can be used to explicitly require a file as a module. The -t or --require flag is similar, except that additional command-line flags are processed by racket, instead of preserved for the required module. For example,

e6

requires the “hello.rkt” module, then requires the “goodbye.rkt” module, and then exits.

The -l or --lib flag is similar to -t/--require, but it requires a module using a lib module path instead of a file path. For example,

e7

is the same as running the raco executable with no arguments, since the raco module is the executable’s main module.

Note that if you wanted to pass command-line flags to raco above, you would need to protect the flags with a --, so that racket doesn’t try to parse them itself:

e8

Modalità load

The -f or --load flag supports loading top-level expressions in a file directly, as opposed to expressions within a module file. This evaluation is like starting a REPL and typing the expressions directly, except that the results are not printed. For example,

e9

loads “hi.rkts” and exits. Note that load mode is generally a bad idea, for the reasons explained in A Note to Readers with Lisp/Scheme Experience [[doc]/guide/intro.html#(part._use-module)]; using module mode is typically better.

The -e or --eval flag accepts an expression to evaluate directly. Unlike file loading, the result of the expression is printed, as in a REPL. For example,

e10

likely runs faster, because it initializes the environment for evaluation using the smaller racket/base language, instead of racket/init.

Pausa 😀 cioè deviazione su readline prima di continuare :mrgreen:

Posta un commento o usa questo indirizzo per il trackback.

Trackback

Rispondi

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: