Macros

The macros the bootstrap defines. Each expands at compile time to special forms or to other macros, and the expansion is then compiled as if it had been written. macroexpand at the REPL shows the expansion of any of them.

Binding and assignment

Macro

Does

set!

Store into a name, attribute, subscript, or ref, choosing the special by target shape

incr!, decr!

Add to or subtract from a binding in place

del!

Delete a name, attribute, or subscript

take!

Read a name, attribute, or subscript and clear it

bind!

Bind a name to a ref, typed by the target shape

ref

A ref to a name, attribute, subscript, or parameter

unassigned?, default!

Whether a location holds a value; store one unless it already does

let*

Sequential let, each binding seeing the ones before

let-values

let with unpacking

labels, flet

Local functions for a body, mutually recursive and not

define-parameter

Declare a dynamic parameter

define-environ

Bind a name to an environment variable

declare-exports

Name the module’s public features

entry-point

Mark the function a program runs once its module has loaded

Conditionals

Macro

Does

if

Two-armed conditional over cond

when, unless

One-armed conditionals

?

Conditional with a boolean default

bool

Truthiness as a boolean

None?

Identity test against the None singleton

has?

Membership

assert

Raise AssertionError unless a test holds; removable by pragma

pass

A no-op expression, and a bare control word

Definitions

Macro

Does

def

Define a function and bind it in the current scope

global

Prefix over var, def, class and syntax that binds the form at the module

class

Define a class and bind it in the current scope

super

The superclass proxy inside a method

decorate, decorate-subject

What @ lines lower to, and the per-decorator dispatch

when-main

Python’s __name__ guard; prefer entry-point for a program’s work

Iteration and collections

Macro

Does

each

A generator over a [var seq] binding, with when: and unless: filters

list-each

A list from the same shape

dict-each

A dict from key: and value: clauses

slice, item-slice

A slice object; a slice of a sequence

item*, attr*

Nested item and attribute chains

cadr … caddddr, first … fifth

Positions in a pair chain

function-compose

Compose functions right to left

Macros about macros

Macro

Does

syntax

A transformer bound at the module from top level, or for the rest of a body inside one

define-syntax

The Scheme-layer spelling: a transformer bound at the module, with any of the rule and match kinds or a bare form; its template names are kept apart from the use site, see Hygiene

extend-syntax

Add arms to an existing transformer

let-syntax

A transformer scoped to a body

inline-macro

Run a body at expand time and splice its result

datum

Capture a form with its source position for hygiene

datumq

The same without evaluating the argument; in a template, writes a form raw (-'form)

define-fence

Define a fence handler for a triple-backtick literal

macroexpand, macroexpand-1

Expand a form fully, or by one step

macroexpandq, macroexpandq-1

The same without quoting the form

compileq, evaluate, get-compiler

Compile, evaluate, and reach the compiler from a program

pragma

Set or read a module’s reader and compiler settings

help

Documentation for a name