From 252295fea959e7f37d06a53d693717e59b7ab7e8 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Tue, 24 Sep 2024 19:34:52 +0800 Subject: [PATCH] mini spec: func --- doc/spec-mini.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/spec-mini.md b/doc/spec-mini.md index cef5cd4f6..565d73ddf 100644 --- a/doc/spec-mini.md +++ b/doc/spec-mini.md @@ -1686,7 +1686,26 @@ println ## Functions -TODO +A function declaration binds an identifier, the function name, to a function. + +```go +FunctionDecl = "func" FunctionName Signature [ FunctionBody ] . +FunctionName = identifier . +FunctionBody = Block . +``` + +If the function's [signature](#function-types) declares result parameters, the function body's statement list must end in a [terminating statement](#terminating-statements). + +```go +func IndexRune(s string, r rune) int { + for i, c := range s { + if c == r { + return i + } + } + // invalid: missing return statement +} +``` ## Packages