<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Pragmatic Forums | Posts in topic 'GString lazy init/Google taking over the world example'</title>
    <link>/forums/55/topics/2356.rss</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <item>
      <title>GString lazy init/Google taking over the world example posted by Jeremy Gordon Flowers @ Mon, 30 Mar 2009 14:05:25 +0000</title>
      <description>&lt;p&gt;Hi Venkat, I&amp;#8217;ll have a look again&amp;#8230; I was actually referencing section 6.2 (thread corresponds to section heading).&lt;br /&gt;Specifically honing in on the example starting half way down &lt;span class="caps"&gt;P105&lt;/span&gt;.&lt;br /&gt;Thanks for clarification though, since it hit the nail on the head! &lt;br /&gt;My thinking way half-right: I had hypothsised&amp;#8230;&lt;br /&gt;If the quote was &amp;#8216;defined&amp;#8217; again inside the closure too, then you wouldn&amp;#8217;t have the problem. (Breaks &lt;span class="caps"&gt;DRY&lt;/span&gt; principle I know!)&lt;br /&gt;- Because the quote is defined at the script level it is bound to the variables &amp;#8216;price&amp;#8217; &amp;#38; &amp;#8216;company&amp;#8217; just above at that same level?&lt;br /&gt;Hence when you enter the closure &amp;#8216;company&amp;#8217; and &amp;#8216;stock&amp;#8217; are in a new context? &lt;br /&gt;Hence initial diagnosis of shadowing the script level ones..&lt;/p&gt;


	&lt;p&gt;As you say when the closure completes if you were to do the print again it would show Microsoft.&lt;br /&gt;This is where shadowing theory broke down and I had muddied the water! &lt;br /&gt;I&amp;#8217;d seen examples later in your book that conveyed this fact and realised something was amiss in my theory, but couldn&amp;#8217;t quite put my finger on it!&lt;br /&gt;Thanks for putting me straight.&lt;br /&gt;Have a great day.&lt;br /&gt;Jeremy&lt;/p&gt;</description>
      <pubDate>Mon, 30 Mar 2009 14:12:24 +0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:55:2356:9378</guid>
      <author>Jeremy Gordon Flowers</author>
      <link>https://forums.pragprog.com/forums/55/topics/2356</link>
    </item>
    <item>
      <title>GString lazy init/Google taking over the world example posted by Venkat Subramaniam @ Mon, 30 Mar 2009 12:08:53 +0000</title>
      <description>&lt;p&gt;Jeremy, in a direct email communication you mentioned you are referring to Section 6.1 with respect to the above message. Since we are dealing with a closure, it is not variable shadowing. The closure is binding to the variable define above and not defining a new one. In fact, if you print the value of price and company at the end of the code on page 115, you will see it is the value changed in the closure. Thanks.&lt;/p&gt;</description>
      <pubDate>Mon, 30 Mar 2009 12:08:53 +0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:55:2356:9372</guid>
      <author>Venkat Subramaniam</author>
      <link>https://forums.pragprog.com/forums/55/topics/2356</link>
    </item>
    <item>
      <title>GString lazy init/Google taking over the world example posted by Jeremy Gordon Flowers @ Sat, 28 Mar 2009 18:05:53 +0000</title>
      <description>&lt;p&gt;Isn&amp;#8217;t the problem caused by shadowing?&lt;br /&gt;See: &lt;a href="http://en.wikipedia.org/wiki/Variable_shadowing"&gt;http://en.wikipedia.org/wiki/Variable_shadowing&lt;/a&gt;&lt;br /&gt;You have the same variables price and company defined in two different scopes. One scope is shadowing the other.&lt;br /&gt;The ones outside the stocks.each closure are at the script level. I think Dierk covered this in Groovy in Action. You do too later in your book in chapter 11.&lt;/p&gt;</description>
      <pubDate>Sat, 28 Mar 2009 18:15:39 +0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:55:2356:9343</guid>
      <author>Jeremy Gordon Flowers</author>
      <link>https://forums.pragprog.com/forums/55/topics/2356</link>
    </item>
  </channel>
</rss>
