Skip to content

Function calls

circular17 edited this page Sep 20, 2023 · 2 revisions

In Append, function calls adopt a more fluid syntax by placing the function name after the first parameter. This approach enhances readability, drawing inspiration from the fluent design and binary operators.

Basic function calls

Instead of wrapping arguments in brackets, you simply follow them with the function:

  • "hello" print

Operator precedence matters. For instance, (1+3) sqr yields 16. Without parentheses, + has lower priority than function calls. Likewise, 2*2 sqr results in 16 since multiplication precedes function calls. Refer to operator precedence for more details.

Chaining function calls

The backpipe \ allows for chaining function calls seamlessly:

  • 4 sqr \ print will display 16.

Functions with Multiple Parameters

When a function requires two parameters, simply append the second parameter:

  • mut myList add 12: the mut keyword here denotes that myList will be modified.

Asynchronous functions

Append handles asynchronous functions gracefully. By default, they are awaited, ensuring synchronous behavior. However, if you wish to proceed without waiting, use the defer keyword:

  • "phonebook.txt" readFile defer will return a promise rather than directly providing the file content.