iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🎾

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.

  1. Starting Windows Terminal
    Press [Win+R], type [wt], and launch Windows Terminal.

    Windows Terminal
    Figure 1: Starting Windows Terminal

  2. Exiting Windows Terminal
    Type exit in the command line to exit Windows Terminal.

    Note:
    Even if you close the current tab with exit, other tabs will remain open and Windows Terminal will 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:

  1. Starting Windows Terminal
    Press [Win+R], type [wt debian], and launch Windows Terminal with the debian profile.

    Note:
    You need to replace the debian profile with your own WSL profile.

    Windows Terminal
    Figure 2: Starting Windows Terminal (WSL)

  2. Exiting Windows Terminal
    Type exit in the command line to exit Windows Terminal.

    Note:
    Even if you close the current tab with exit, other tabs will remain open and Windows Terminal will 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.

  1. Starting Racket
    Enter racket in the command line.

    racket
    
  2. Prompt Display
    The REPL starts 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:

  1. Normal EOF input
    Enter Ctrl+D (Ctrl+Z on Windows).

    Welcome to Racket v8.11 [cs].
    > [Ctrl+D]
    
    $
    
  2. EOF input during input
    If you are in the middle of an input, press Ctrl+C to interrupt and then enter EOF.

    Welcome to Racket v8.11 [cs].
    > Hell [Ctrl+C]
    ; user break [,bt for context]
    > [Ctrl+D]
    
    $
    
  3. EOF input when suspended by Ctrl+Z
    In a WSL environment, entering Ctrl+Z will suspend Racket. In this case, return to Racket using the fg command and then enter EOF.

    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 the Scheme language.

  • WSL (Windows Subsystem for Linux):
    A compatibility layer for running Linux binary executables natively on Windows.

  • 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 the REPL that adds features such as error tracing and external file editing functionality to the standard REPL.

  • CLI (Command Line Interface):
    A text-based user interface for operating a computer through a command line or terminal.

  • Windows Terminal:
    A terminal application for Windows that allows managing multiple command-line tools and shells using tabs.

References

Web Sites

GitHubで編集を提案

Discussion