OpenSCAD User Manual/WIP/Module Literals

module literals / module references
A module_reference is a type of variable that refers to a module

Module literal and module reference syntax
The module_reference is initialised using a module_literal. In the following snippet  is the module_reference and is the module_literal. A module literal is an expression which is syntactically identified by being prefixed with the  keyword.

Syntax in detail
There are several ways to define a module reference, depending on what you want to do.

Simple syntax
In this syntax you define the module exactly as you want to see it output.

The above code creates the variable  but doesn't instantiate it, so there will be no output in the graphics window. To instantiate the module you use the existing syntax that you use with modules.

Alias syntax
In this variation, the name of the module reference is just another name for the module. To instantiate the module, the alias takes exactly the same arguments as the module it aliases

Arguments forwarding syntax
In another form you provide arguments to the module_literal. The arguments are forwarded to the original module.

In this case you call the reference with the modified arguments

Anonymous module syntax without arguments
In the final forms you can create an anonymous module_literal and initialise the reference to it. ( Note that in this form there must be a semicolon after the closing curly brace )

The module can be instantiated in the usual way.

Anonymous module syntax with arguments
The anonymous module form can of course also take arguments

The module reference is instantiated in the usual way.

Instantiating a module via an expression
Module literals can be stored in arrays and returned from functions In these cases it can be inconvenient to assign them to a symbol before invoking them. You can instantiate an expression resolving to a module_literal by encasing the expression before the instantiation arguments, in brackets.

Further examples
For more advanced uses of module_literals and module references see https://github.com/kwikius/openscad/tree/module_literal_v3/examples/ModuleLiterals