On this page:
9.1 Source formats
9.1.1 Command syntax using ◊
9.1.2 Any command is valid
9.1.3 Standard exports
9.1.4 Custom exports
9.1.5 The directory-require.rkt file
9.1.6 Preprocessor (.pp extension)
9.1.7 Markdown (.pmd extension)
9.1.8 Markup (.pm extension)
9.1.9 Pagetree (.ptree extension)
9.2 Utility formats
9.2.1 Scribble (.scrbl extension)
9.2.2 Null (.p extension)
6.1.0.8

9 File formats

9.1 Source formats

 #lang pollen/pre package: pollen
 #lang pollen/markdown
 #lang pollen/markup
 #lang pollen/ptree

The Pollen language is divided into variants, or dialects, that are tailored to suit each of the core source formats.

These dialects can be invoked one of two ways: either by invoking a specific dialect in the first line of the file (also known as the #lang line), or by using the generic #lang pollen as the first line, and then the correct dialect will be automatically selected based on the source file extension.

If the #lang line specifies a dialect different from the one specified by the file extension, the #lang line will take precedence.

For ease of use, the behavior of the Pollen language departs from the standard Racket language in several ways. The differences are noted below.

9.1.1 Command syntax using ◊

Commands must start with the special lozenge character . Other material is interpreted as plain text. See ◊ command overview for more.

How is this different from Racket? In Racket, everything is a command, and plain text must be quoted.

9.1.2 Any command is valid

There are no undefined commands in Pollen. If a command has not already been defined, it’s treated as a tag function. See ◊ command overview for more.

How is this different from Racket? In Racket, if you try to treat an identifier as a function before defining it with define, you’ll get an error.

9.1.3 Standard exports

By default, every Pollen source file exports two symbols, which you can access by using the source file with require:

'doc contains the output of the file. The type of output depends on the source format (documented below).

'metas is a hash of key–value pairs with extra information that is extracted from the source. These 'metas will always contain the key 'here-path, which returns a string representation of the full path to the source file. Beyond that, the only 'metas are the ones that are specified within the source file (see the source formats below for more detail on how to specify metas).

How is this different from Racket? In Racket, you must explicitly define and then provide any values you want to export.

9.1.4 Custom exports

Any value or function that is defined within the source file using define is automatically exported.

How is this different from Racket? In Racket, you must explicitly provide any values you want to export. Unlike Racket, every Pollen source file impliedly uses (provide (all-defined-out)).

9.1.5 The directory-require.rkt file

If a file called directory-require.rkt exists in the same directory with a source file, it’s automatically imported when the source file is compiled.

How is this different from Racket? In Racket, you must explicitly import files using require.

9.1.6 Preprocessor (.pp extension)

Invoke the preprocessor dialect by using #lang pollen/pre as the first line of your source file, or by using #lang pollen with a file extension of .pp. These forms are equivalent:

"sample.css.pp"

#lang pollen
...source...

"sample.css"

#lang pollen/pre
...source...

When no dialect is explicitly specified by either the #lang line or the file extension, Pollen will default to using the preprocessor dialect. For instance, this file will be treated as preprocessor source:

"test.yyz"

#lang pollen
...source...

Of course, you’re better off specifying the preprocessor dialect explicitly rather than relying on this default behavior.

The output of the preprocessor dialect, provided by 'doc, is plain text.

9.1.7 Markdown (.pmd extension)

Invoke the Markdown dialect by using #lang pollen/markdown as the first line of your source file, or by using #lang pollen with a file extension of .pmd. These forms are equivalent:

"sample.txt.pmd"

#lang pollen
...source...

"sample.txt"

#lang pollen/markdown
...source...

The output of the Markdown dialect, provided by 'doc, is a tagged X-expression.

9.1.8 Markup (.pm extension)

Invoke the Pollen markup dialect by using #lang pollen/markup as the first line of your source file, or by using #lang pollen with a file extension of .pm. These forms are equivalent:

"about.html.pm"

#lang pollen
...source...

"about.html"

#lang pollen/markup
...source...

The output of the Pollen markup dialect, provided by 'doc, is a tagged X-expression.

9.1.9 Pagetree (.ptree extension)

Invoke the pagetree dialect by using #lang pollen/ptree as the first line of your source file, or by using #lang pollen with a file extension of .ptree. These forms are equivalent:

"main.ptree"

#lang pollen
...source...

"main.rkt"

#lang pollen/ptree
...source...

The output of the pagetree dialect, provided by 'doc, is a pagetree? that is checked for correctness using validate-pagetree.

9.2 Utility formats

These aren’t source formats because they don’t contain a #lang pollen line. But for convenience, they get special handling by the Pollen project server.

9.2.1 Scribble (.scrbl extension)

Scribble files are recognized by the project server and can be compiled and previewed in single-page mode.

9.2.2 Null (.p extension)

Files with the null extension are simply rendered as a copy of the file without the extension, so index.html.p becomes index.html.

This can be useful you’re managing your project with git. Most likely you’ll want to ignore *.html and other file types that are frequently regenerated by the project server. But if you have isolated static files — for instance, a index.html that doesn’t have source associated with it — they’ll be ignored too. You can cure this problem by appending the null extension to these static files, so they’ll be tracked in your source system without actually being source files.