iTranslated by AI

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

Racket: How to Install and Configure Code Runner for Racket Programming

に公開

tl;dr

  • Install Code Runner in VS Code
  • Configure Code Runner to run Racket/Scheme/LISP programs using Racket
  • Run Racket programs on VS Code

Thanks to Code Runner, you can run Racket programs from Visual Studio Code .
Enjoy!

1. Introduction

In this article, I will explain in detail how to install Code Runner and configure it to run Racket programs.

1.1. What is Code Runner?

Code Runner is an extension that executes code for various programs within Visual Studio Code .
It supports a wide range of languages such as Python, JavaScript, Java, C#, PHP, Ruby, and Racket is one of them.

When you execute Code Runner, it runs a specified command and outputs the execution results to the Output window.
For example, if the program is a Racket program, it will be racket <source file>.

2. Installing Code Runner

There are two ways to install Code Runner in VS Code : using the [Extensions] menu within VS Code , or via the command line.
Here, I will explain each method.

2.1. Installing Code Runner in VS Code

First, I will explain the steps to install Code Runner within VS Code .

  1. Select Extensions:
    Click the [Extensions] icon from the left menu (or press Ctrl+Shift+X)
    Extensions

  2. Search for Code Runner:
    Enter Code Runner in the search bar and select the corresponding extension from the search results
    Code Runner

  3. Install Code Runner:
    Click [Install] to install Code Runner
    Install

This completes the installation of Code Runner within VS Code .

2.2. Installing Code Runner from the Command Line

In VS Code , you can install extensions from the command line.
Follow these steps to install Code Runner from the command line.

  1. Open PowerShell :
    PowerShell

  2. Execute the following command:

    code --install-extension formulahendry.code-runner
    

This completes the installation of Code Runner via the command line.

3. Configuring Code Runner

Code Runner allows you to configure execution commands for each language. To do so, you need to add an "Executor Map" to the VS Code settings file, "settings.json".

3.1. Adding the Executor Map

Follow these steps to add the Executor Map for running Racket programs.

  1. Open User Settings:
    Press Ctrl+Shift+P and select [Open User Settings] from the command palette.
    User Settings

  2. Add Settings:
    Add the following settings to "settings.json". This allows you to run Racket/Scheme/LISP programs using Racket.

    settings.json
    "code-runner.customCommand": "echo hello",
    "code-runner.executorMap": {
       "racket": "racket $fullFileName",
       "scheme": "racket $fullFileName",
       "lisp": "racket $fullFileName",
    },
    

    By using $fullFileName as shown above, you can specify the source file with its full path. This ensures that the program can be executed regardless of which directory the source file is located in.

  3. Save Settings:
    Save the settings file by pressing Ctrl+S and close it with Ctrl+W.

This completes the configuration of the Executor Map.

4. Verifying Code Runner Operation

4.1. Verifying with "Hello World"

In 3.1, we added the settings to run Racket programs. To confirm that these settings are correctly applied, we will create and run a "Hello World" program. Follow the steps below.

  1. Create Hello World:
    Create the following program in VS Code.

    hello.rkt
    #lang racket
    
    (display "Hello, my first racket!")
    
  2. Run the Program:
    Execute the "hello.rkt" program by pressing Ctrl+Alt+N on the source file or right-clicking and selecting [Run Code].

  3. Check the Output:
    Verify that the following message is displayed in the [Output] window.

    Hello, my first racket!
    

If the message you created is output as shown above, Code Runner is operating correctly.

Conclusion

In this article, I introduced how to install Code Runner in Visual Studio Code and configure it to run Racket programs. This makes it easier to verify the operation of Racket programs. I hope you leverage this new knowledge to enjoy the world of Racket programming.

Happy Hacking!

References

Websites

  • VS Code CLI: Official documentation regarding the VS Code command line.
  • Code Runner: Official GitHub repository for Code Runner.
GitHubで編集を提案

Discussion