-
-
Notifications
You must be signed in to change notification settings - Fork 212
Declaring functions
Giorgio Garofalo edited this page Sep 6, 2024
·
7 revisions
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 and thus follows the lambda syntax, with each parameter of the function appearing as a parameter of the lambda. 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, thus the following example is legal:
.function {isadult}
age:
.isgreater {.age} than:{18} orequals:{yes}
.if {.isadult age:{26}}
You're an adult!
- Figures
- Image size
- TeX formulae
- Table caption
- Code caption
- Decorative headings
- Alerts (quote types)
- Quotation source
- Cross-references
- Page breaks
- Text symbols (text replacement)
- Document metadata
- Theme
- CSS
- Fonts
- Page format
- Page margin content
- Page counter
- Automatic page break
- Numbering
- Paragraph style
- Caption position
- Table of contents
- Bibliography
- Footnotes
- Stacks (row, column, grid)
- Container
- Align
- Float
- Figure
- Clip
- Box
- Collapsible
- Landscape
- Whitespace
- Variables
- Optionality
- Math
- Conditional statements
- Loops
- Let
- Destructuring
- String manipulation
- Table manipulation: sorting, computing, and more
- Generators
- String
- Number
- Markdown content
- Boolean
- None
- Enumeration entry
- Iterable
- Dictionary
- Range
- Lambda
- Size(s)
- Color
- Dynamic
- Paper: abstract, definitions, theorems, and more