On this page:
racket-module-input-variant/  c
list/  syntax?
code/  c
racket-module-variant/  c
any-racket-module-code?
racket-module-code?
get-racket-module-body
make-racket-module-datum
coerce-datum
read-racket-module
34.1 Stripping and Dressing
bare-racket-module
strip
dress
34.2 Fetching Racket Modules in Package Definition
keep-standalone-racket-module
8.12

34 Racket Module Operations🔗ℹ

 (require denxi/racket-module) package: denxi

A contract matching accepted value types when reading a Racket module.

procedure

(list/syntax? v)  boolean?

  v : any/c
Returns (and (syntax? v) (list? (syntax-e v))).

A contract matching accepted value types for an in-memory representation of a Racket program. In the context of this library, this can either be a Racket module form, or some list of instructions and/or data.

A contract matching accepted value types for an in-memory representation of Racket module code.

procedure

(any-racket-module-code? v)  boolean?

  v : any/c
Returns (racket-module-code? #f v).

procedure

(racket-module-code? modlang v)  boolean?

  modlang : symbol?
  v : any/c
Returns #t if (get-racket-module-body modlang v) would not fail. This does not verify the functionality of the module.

procedure

(get-racket-module-body expected-lang code)  (or/c #f code/c)

  expected-lang : (or/c #f symbol?)
  code : racket-module-variant/c
Returns the top level forms of code, or #f if the module language does not match expected-lang. If expected-lang is #f, then the module language is not checked.

The return type value mirrors that of the input value type. That is, (list? code) implies (list? (get-racket-module-body #f code)).

procedure

(make-racket-module-datum [#:id id]    
  lang    
  top-level)  list?
  id : symbol? = 'anon
  lang : symbol?
  top-level : list?
Equivalent to (apply list 'module id lang top-level).

procedure

(coerce-datum code)  list?

  code : code/c
If code is a list, then returns code. Otherwise, returns (syntax->datum code).

procedure

(read-racket-module expected-reader-lang 
  expected-module-lang 
  variant) 
  (subprogram/c syntax?)
  expected-reader-lang : symbol?
  expected-module-lang : symbol?
  variant : racket-module-input-variant/c
Returns a subprogram that reads a Racket module’s code and returns the resulting syntax object with minimal expansion. Reading is limited to the reader extension provided by the collection path in expected-reader-lang, and the module language must match expected-module-lang.

If variant is an input port, read-racket-module will attempt to read code directly from variant.

If variant is a path, string, or byte string, then the behavior is equivalent to applying read-racket-module to an input port for the file, string content, or byte content respectively.

If variant is a list, then the behavior is equivalent to applying read-racket-module to an input port for (~s variant).

34.1 Stripping and Dressing🔗ℹ

To strip a Racket module in code/c form is to convert it to a bare module. To dress the module is to do the reverse. Stripping and dressing are not inverse operations, because stripping does not preserve lexical and location information.

In the context of Denxi, programs are restricted to a small, fixed grammar and are subject to meaningful module-level overrides. This makes source location information meaningless in some cases, but lexical information remains constant. Denxi uses bare modules when only the content matters for code transformations.

struct

(struct bare-racket-module (name lang code)
    #:transparent)
  name : symbol?
  lang : symbol?
  code : list?
A bare Racket module (or “bare module”) is an instance of bare-racket-module.

Each instance holds parts of a Racket module code without lexical information, source location information, or an implicit form for a module body such as #%plain-module-begin.

procedure

(strip module-datum)  bare-racket-module?

  module-datum : code/c
Strips a Racket module.

> (equal? (strip #'(module anon racket/base (#%module-begin (define a 1) (provide a))))
          (bare-racket-module 'anon 'racket/base '((define a 1) (provide a))))

procedure

(dress stripped)  list?

  stripped : bare-racket-module?
Returns

(make-racket-module-datum
  #:id
  (bare-racket-module-name stripped)
  (bare-racket-module-lang stripped)
  (bare-racket-module-code stripped))

34.2 Fetching Racket Modules in Package Definition🔗ℹ

procedure

(keep-standalone-racket-module [#:compile-with compile-with] 
  name) 
  subprogram?
  compile-with : (or/c #f path-string?) = "raco"
  name : string?
Behaves like keep-input when compile-with is #f.

If compile-with is not #f, it is used as the first argument to run for selecting a raco executable. Once the module is available, it is immediately compiled using the make subcommand.