﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Go Program - The First internet site for Go programming &#187; Defer</title>
	<atom:link href="http://www.go-program.com/category/basics/defer/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.go-program.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 19 Nov 2009 11:31:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Go &#8211; Defer</title>
		<link>http://www.go-program.com/go-defer/</link>
		<comments>http://www.go-program.com/go-defer/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 16:58:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Defer]]></category>

		<guid isPermaLink="false">http://www.go-program.com/?p=38</guid>
		<description><![CDATA[







The defer statement executes a function (or method) when the enclosing function returns. The arguments are evaluated at the point of the defer; the function call happens upon return.
func data(name string) string {
f := os.Open(name, os.O_RDONLY, 0);
defer f.Close();
contents := io.ReadAll(f);
return contents;
}
Useful for closing fds, unlocking mutexes, etc.
Tracing with defer
func trace(s string) { Print(&#8221;entering:&#8221;, s); }
func [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-9004887195759386";
/* Go programs text ads1 */
google_ad_slot = "3650915252";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<script type="text/javascript"><!--
google_ad_client = "pub-9004887195759386";
/* Goprograms1 */
google_ad_slot = "8587802801";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>The defer statement executes a function (or method) when the enclosing function returns. The arguments are evaluated at the point of the defer; the function call happens upon return.</p>
<p>func data(name string) string {</p>
<p>f := os.Open(name, os.O_RDONLY, 0);</p>
<p>defer f.Close();</p>
<p>contents := io.ReadAll(f);</p>
<p>return contents;</p>
<p>}</p>
<p>Useful for closing fds, unlocking mutexes, etc.</p>
<p>Tracing with defer</p>
<p>func trace(s string) { Print(&#8221;entering:&#8221;, s); }</p>
<p>func untrace(s string) { Print(&#8221;leaving:&#8221;, s); }</p>
<p>func a() {</p>
<p>trace(&#8221;a&#8221;);</p>
<p>defer untrace(&#8221;a&#8221;);</p>
<p>Print(&#8221;in a&#8221;)</p>
<p>}</p>
<p>func b() {</p>
<p>trace(&#8221;b&#8221;);</p>
<p>defer untrace(&#8221;b&#8221;);</p>
<p>Print(&#8221;in b&#8221;);</p>
<p>a()</p>
<p>}</p>
<p>func main() { b() }</p>
<p>Args evaluate now, defer later</p>
<p>func trace(s string) string {</p>
<p>Print(&#8221;entering:&#8221;, s);</p>
<p>return s</p>
<p>}</p>
<p>func un(s string) {</p>
<p>Print(&#8221;leaving:&#8221;, s)</p>
<p>}</p>
<p>func a() {</p>
<p>defer un(trace(&#8221;a&#8221;));</p>
<p>Print(&#8221;in a&#8221;)</p>
<p>}</p>
<p>func b() {</p>
<p>defer un(trace(&#8221;b&#8221;));</p>
<p>Print(&#8221;in b&#8221;);</p>
<p>a()</p>
<p>}</p>
<p>func main() { b() }</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.go-program.com/go-defer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
