iTranslated by AI
Racket: Starting and Exiting Racket on Windows/WSL
Introduction
This article explains in detail how to start and exit Racket on Windows and WSL (Windows Subsystem for Linux).
Let's master the basic operations of Racket and improve your programming skills through functional programming.
Enjoy!
1. Prerequisites
1.1 OS Environment (Windows & WSL)
Racket is compatible with multiple OSs, and can be used in both Windows and WSL environments.
In this article, I will explain operations common to both Windows and WSL.
1.2 Racket Implementation
You must have Racket installed on both Windows and WSL.
If you haven't installed it yet, please refer to the following articles to install Racket.
1.3 CLI Environment
We will use the CLI (Command Line Interface) to start Racket.
This approach is very effective for learning and using Racket.
2. How to use Windows Terminal
We will use Windows Terminal to use the CLI on Windows and WSL.
This chapter explains how to start and exit Windows Terminal.
2.1. Starting and Exiting Windows Terminal
To start Windows Terminal, use the wt command.
Follow these steps to start and exit Windows Terminal.
-
Starting
Windows Terminal
Press [Win+R], type [wt], and launchWindows Terminal.
Figure 1: Starting Windows Terminal -
Exiting
Windows Terminal
Typeexitin the command line to exitWindows Terminal.Note:
Even if you close the current tab withexit, other tabs will remain open andWindows Terminalwill not close.exit
2.2 Starting and Exiting the Console for WSL
You can use the console for WSL by starting Windows Terminal with a specific profile for WSL.
Follow these steps to start and exit the WSL console:
-
Starting
Windows Terminal
Press [Win+R], type [wt debian], and launchWindows Terminalwith thedebianprofile.Note:
You need to replace thedebianprofile with your ownWSLprofile.
Figure 2: Starting Windows Terminal (WSL) -
Exiting
Windows Terminal
Typeexitin the command line to exitWindows Terminal.Note:
Even if you close the current tab withexit, other tabs will remain open andWindows Terminalwill not close.exit
3. Starting and Exiting Racket
This section explains the steps for starting and exiting Racket in detail.
3.1 Starting Racket
You can start Racket by entering the racket command in the command line.
If no program file is specified, the REPL (Read-Eval-Print Loop), Racket's interactive interface, will start.
Follow these steps to start Racket.
-
Starting
Racket
Enterracketin the command line.racket -
Prompt Display
TheREPLstarts and a prompt is displayed.Welcome to Racket v8.11.1 [cs]. >
3.2 Exiting Racket REPL
When the REPL is running, exiting the REPL will also terminate Racket.
There are several ways to exit the REPL.
| Exit Method | Description | Remarks |
|---|---|---|
EOF input |
Enter EOF into the standard input. |
You can enter EOF with Ctrl+Z on Windows and Ctrl+D on WSL. |
exit function |
Enter (exit) and execute the exit function. |
|
exit command |
Enter ,exit and execute the exit command. |
Only executable in XREPL. |
3.3 Racket REPL
When Racket is executed without arguments, an interactive interface called REPL (Read-Eval-Print-Loop) starts.
When the REPL is running, you can enter Racket programs into the command line.
The REPL evaluates the entered Racket program and returns the result immediately.
This allows you to program interactively in Racket from the command line.
3.4 XREPL
XREPL (eXtended REPL) is an interactive interface that extends the standard REPL.
It features various function extensions via meta-commands, ranging from basic functions like help, shell, and exit, to loading external files, editing in an editor, and debugging.
Mastering XREPL will improve your productivity in Racket programming.
4. Basic Operations of XREPL
This chapter introduces simple ways to operate XREPL.
4.1 Exit via EOF
Exit XREPL by entering EOF. Follow these steps to exit XREPL:
-
Normal EOF input
EnterCtrl+D(Ctrl+ZonWindows).Welcome to Racket v8.11 [cs]. > [Ctrl+D] $ -
EOF input during input
If you are in the middle of an input, pressCtrl+Cto interrupt and then enterEOF.Welcome to Racket v8.11 [cs]. > Hell [Ctrl+C] ; user break [,bt for context] > [Ctrl+D] $ -
EOF input when suspended by
Ctrl+Z
In aWSLenvironment, enteringCtrl+Zwill suspendRacket. In this case, return toRacketusing thefgcommand and then enterEOF.Welcome to Racket v8.11 [cs]. > [Ctrl+Z] [1]+ Stopped racket $ fg racket [Ctrl+D] $
4.2 Basic Meta-commands
In XREPL, you can use extended functions via meta-commands. The main meta-commands are as follows.
| Meta-command | Description | Details |
|---|---|---|
| ,help | Help | Displays a list of available meta-commands |
| ,exit | Exit | Exits Racket and returns to the command line |
| ,shell | Shell | Executes the specified shell command. Used for moving directories, displaying content, etc. |
| ,edit | Edit | Edits the specified file using the editor designated by the OS |
There are many other meta-commands available. For details, please refer to XREPL: eXtended REPL.
4.3 Referencing Previous Values
In XREPL, you can reference the results of previous expressions using ^. Use ^ for the previous result, ^^ for the result before that, and increasing the number of ^ symbols allows you to reference even earlier values. For example:
> "Hello "
"Hello "
> (string-append ^ ^ "World")
"Hello Hello World"
Conclusion
This concludes the basic operations of Racket.
Through this article, you have learned how to perform simple programming using the Racket REPL and how to exit Racket.
By reading the reference materials, you will also be able to master XREPL, the extended REPL for Racket.
Get familiar with Racket and continue learning functional programming.
Happy Hacking!
Technical Terms and Notes
-
Racket:
A functional programming language developed for education and research based on theSchemelanguage. -
WSL(Windows Subsystem for Linux):
A compatibility layer for runningLinuxbinary executables natively onWindows. -
REPL(Read-Eval-Print Loop):
An interactive programming environment where program code is entered line by line, and each execution result is obtained immediately. -
XREPL(eXtended REPL):
An enhanced version of theREPLthat adds features such as error tracing and external file editing functionality to the standardREPL. -
CLI(Command Line Interface):
A text-based user interface for operating a computer through a command line or terminal. -
Windows Terminal:
A terminal application forWindowsthat allows managing multiple command-line tools and shells using tabs.
References
Web Sites
-
The Racket Guide:
A guide providing basic concepts and tutorials forRacket. -
XREPL: eXtended REPL:
Documentation providing detailed information about the extendedREPL. -
Racket Official Documentation:
Official documentation providing comprehensive information about theRacketlanguage.
Discussion