diff --git a/manual/template_lang.rst b/manual/template_lang.rst index 362180e409..069dd327bc 100644 --- a/manual/template_lang.rst +++ b/manual/template_lang.rst @@ -258,7 +258,7 @@ General Program Mode times_div_op ::= '*' | '/' unary_op_expr ::= [ add_sub_op unary_op_expr ]* | expression expression ::= identifier | constant | function | assignment | field_reference | - if_expr | for_expr | break_expr | continue_expr | + if_expr | for_expr | break_expr | continue_expr | return_stmt '(' expression_list ')' | function_def field_reference ::= '$' [ '$' ] [ '#' ] identifier identifier ::= id_start [ id_rest ]* @@ -282,6 +282,7 @@ General Program Mode list_expr ::= top_expression break_expr ::= 'break' continue_expr ::= 'continue' + return_stmt ::= 'return' top_expression separator_expr ::= top_expression start_expr ::= top_expression stop_expr ::= top_expression @@ -380,6 +381,10 @@ If the original Genre is `History.Military, Science Fiction.Alternate History, R Note: the last line in the template, ``new_tags``, isn't strictly necessary in this case because ``for`` returns the value of the last top_expression in the expression list. The value of an assignment is the value of its expression, so the value of the ``for`` statement is what was assigned to ``new_tags``. +**Return stmt** + +Return the value of the ``expression``. If executed in a function then it returns the value of the expression to the caller. If executed in the outermost context (the template) then it sets the value of the template to the value of the expression and exits the template. + **Function definition** If you have repeated code in a template then you can put that code into a local function. The ``def`` keyword starts the definition. It is followed by the function name, the argument list, then the code in the function. The function definition ends with the ``fed`` keyword.