17.3.4 Installing a Language

► |  | The Racket Guide

1 | Welcome to Racket
2 | Racket Essentials
3 | Built-In Datatypes
4 | Expressions and Definitions
5 | Programmer-Defined Datatypes
6 | Modules
7 | Contracts
8 | Input and Output
9 | Regular Expressions
10 | Exceptions and Control
11 | Iterations and Comprehensions
12 | Pattern Matching
13 | Classes and Objects
14 | Units
15 | Reflection and Dynamic Evaluation
16 | Macros
17 | Creating Languages
18 | Concurrency and Synchronization
19 | Performance
20 | Parallelism
21 | Running and Creating Executables
22 | More Libraries
23 | Dialects of Racket and Scheme
24 | Command-Line Tools and Your Editor of Choice
| Bibliography
| Index

► | 17 | Creating Languages

17.1 | Module Languages
17.2 | Reader Extensions
17.3 | Defining new #lang Languages

▼ | 17.3 | Defining new #lang Languages

17.3.1 | Designating a #lang Language
17.3.2 | Using #lang reader
17.3.3 | Using #lang s-exp syntax/ module-reader
17.3.4 | Installing a Language
17.3.5 | Source-Handling Configuration
17.3.6 | Module-Handling Configuration

top ← prev up next →

##### 17.3.4`` Installing a Language

So far, we have used the reader meta-language to access languages like "literal.rkt" and "dollar-racket.rkt". If you want to use something like #lang literal directly, then you must move "literal.rkt" into a Racket collection named "literal" (see also Adding Collections). Specifically, move "literal.rkt" to a reader submodule of "literal/main.rkt" for any directory name "literal", like so:

> > "literal/main.rkt"

> > > #lang racket
> > > (module reader racket
> > > (require syntax/strip-context)
> > > (provide (rename-out [literal-read read]
> > > [literal-read-syntax read-syntax]))
> > > (define (literal-read in)
> > > (syntax->datum
> > > (literal-read-syntax #f in)))
> > > (define (literal-read-syntax src in)
> > > (with-syntax ([str (port->string in)])
> > > (strip-context
> > > #'(module anything racket
> > > (provide data)
> > > (define data 'str))))))

Then, install the "literal" directory as a package:

cd /path/to/literal ; raco pkg install

After moving the file and installing the package, you can use literal directly after #lang:

> #lang literal
> Technology!
> System!
> Perfect!

> > > See raco: Racket Command-Line Tools for more information on using raco.

You can also make your language available for others to install by using the Racket package manager (see Package Management in Racket). After you create a "literal" package and register it with the Racket package catalog (see Package Catalogs), others can install it using raco pkg:

raco pkg install literal

Once installed, others can invoke the language the same way: by using #lang literal at the top of a source file.

If you use a public source repository (e.g., GitHub), you can link your package to the source. As you improve the package, others can update their version using raco pkg:

raco pkg update literal

> > > See Package Management in Racket for more information about the Racket package manager.

top ← prev up next →