From 65ecbc1f168470605c72b4a62fc2ba0d42c8ecb7 Mon Sep 17 00:00:00 2001 From: Yuhao-C Date: Sun, 26 May 2024 01:18:12 -0400 Subject: [PATCH] add defer arg eager eval example --- _content/tour/flowcontrol.article | 2 +- _content/tour/flowcontrol/defer.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/_content/tour/flowcontrol.article b/_content/tour/flowcontrol.article index 448cb76765..4d02cef7ef 100644 --- a/_content/tour/flowcontrol.article +++ b/_content/tour/flowcontrol.article @@ -153,7 +153,7 @@ This construct can be a clean way to write long if-then-else chains. * Defer -A defer statement defers the execution of a function until the surrounding +A `defer` statement defers the execution of a function until the surrounding function returns. The deferred call's arguments are evaluated immediately, but the function call diff --git a/_content/tour/flowcontrol/defer.go b/_content/tour/flowcontrol/defer.go index 3314c056d2..1ca70ae2d1 100644 --- a/_content/tour/flowcontrol/defer.go +++ b/_content/tour/flowcontrol/defer.go @@ -4,8 +4,13 @@ package main import "fmt" +func helper() string { + fmt.Println("helper") + return "world" +} + func main() { - defer fmt.Println("world") + defer fmt.Println(helper()) fmt.Println("hello") }