Not the same semantics, as least compared to Golang. This is block-scoped, but &quot;defer&quot; in Go is function-scoped and has highly dynamic semantics—for example, call it in a loop and the compiler may not be able to statically prove how many times it will run.<p>(Note that, IMO, the semantics of the feature as implemented in the article are preferable to those of Golang, so I wouldn&#x27;t personally go to the effort of trying to duplicate Go&#x27;s behavior.)