28. defer and defer_delete macros

Apply module implements defer and defer_delete pattern, i.e. ability to attach a bit of code or a delete operation to a finally section of the block, without leaving the context of the code.

All functions and symbols are in “defer” module, use require to get access to it.

require daslib/defer

28.1. Function annotations

DeferMacro

This macro covnerts defer() <| block expression into {}, and move block to the finally section of the current block

28.2. Call macros

defer_delete

This macro converts defer_delete() expression into {}, and add delete expression to the finally section of the current block

28.3. Defer

defer(blk: block<void> const)

argument

argument type

blk

block<> const

defer a block of code. For example:

var a = fopen("filename.txt","r")
defer <|
    fclose(a)

Will close the file when ‘a’ is out of scope.

28.4. Stub

nada()

helper function which does nothing and will be optimized out