-
Notifications
You must be signed in to change notification settings - Fork 8
Declaring functions
Functions can also be declared in Quarkdown sources thanks to the .function
function (everything is a function!).
It accepts two arguments: the function name and its body.
.function {myfunc}
Hello, world!
It can then be called through a normal function call:
.myfunc <!-- Hello, world! -->
Note that there are no return statements: every reached statement is part of the output.
.function {myfunc}
.if {false}
A
B
.myfunc <!-- B -->
The body parameter is a lambda: each parameter of the function is as a parameter of the lambda block. Each argument can be accessed within the function body as a variable (which, in Quarkdown, is basically a function with no parameters).
.function {greet}
to from:
Hello, .to from .from!
.greet {world} {John} <!-- Hello, world from John! -->
Arguments can be named as well to improve readability:
.greet {world} from:{John}
Any Markdown content can be returned:
.function {greet}
to from:
**Hello, .to** from .from!
Quarkdown is weakly typed and any kind of value can be returned:
.function {area}
width height:
.multiply {width} by:{height}
The area of the rectangle is **.area {4} {2}**.
.function {isadult}
age:
.isgreater {.age} than:{18} orequals:{yes}
.if {.isadult age:{26}}
You're an adult!
If a function parameter ends in a question mark ?
, it becomes optional. If the corresponding argument is not provided, it will be assigned the value None
.
.function {greet}
to from?:
Hello, .to from .from!
.greet {world} <!-- Hello, world from None -->
.greet {world} {John} <!-- Hello, world from John -->
None
features several interesting operations, such as placeholders via .otherwise
which emulate the behavior of default parameters.
.function {greet}
to from?:
Hello, .to from .from::otherwise {unnamed}!
.greet {world} <!-- Hello, world from unnamed! -->
.greet {world} {John} <!-- Hello, world from John! -->
- Figures
- Image size
- TeX formulas
- Table caption
- Decorative headings
- Alerts (quote types)
- Quotation source
- Page breaks
- Text symbols (text replacement)
- Syntax of a function call
- Declaring functions
- Dynamic typing
- Localization
- Including other Quarkdown files
- Importing external libraries
- Document metadata
- Theme
- Page format
- Page margin content
- Page counter
- Automatic page break
- Numbering
- Table of contents
- Stacks (row, column, grid)
- Container
- Align
- Clip
- Box
- Collapsible
- Whitespace
- Variables
- Optionality
- Math
- Conditional statements
- Loops
- Let
- Destructuring
- String manipulation
- Generators
- String
- Number
- Markdown content
- Boolean
- None
- Enumeration entry
- Iterable
- Dictionary
- Range
- Lambda
- Size(s)
- Color
- Dynamic
- Paper: abstract, definitions, theorems, and more