Skip to content

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!

Getting started [NEW!]

Documentation

CLI tools

Markdown enhancements

Functions

Setting up

Multi-file projects

Layout

Charts & diagrams

Scripting & control flow

Utilities

Slides

I/O

Native content

Value types

Built-in libraries

  • Paper: abstract, definitions, theorems, and more

Extra features

Inside Quarkdown

Clone this wiki locally