<?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>ps1.soapyfrog.com &#187; Odd</title>
	<atom:link href="http://ps1.soapyfrog.com/category/odd/feed/" rel="self" type="application/rss+xml" />
	<link>http://ps1.soapyfrog.com</link>
	<description>doing inappropriate things with powershell</description>
	<lastBuildDate>Sun, 26 Aug 2007 22:01:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Making functions *really* read-only</title>
		<link>http://ps1.soapyfrog.com/2007/01/26/making-functions-really-read-only/</link>
		<comments>http://ps1.soapyfrog.com/2007/01/26/making-functions-really-read-only/#comments</comments>
		<pubDate>Fri, 26 Jan 2007 10:24:34 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Odd]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://ps1.soapyfrog.com/2007/01/26/making-functions-really-read-only/</guid>
		<description><![CDATA[Over at the excellent PowerShell Team Blog, Bruce Payette wrote about Controlling PowerShell Function (Re)Definition. However, making a function constant does not prevent it from being shadowed in child scopes. Given that a child scope is created in any script, new function definition or script block, this makes it very unconstant. Consider this: # define [...]]]></description>
			<content:encoded><![CDATA[<p>Over at the excellent PowerShell Team Blog, Bruce Payette wrote about <a href="http://blogs.msdn.com/powershell/archive/2007/01/25/controlling-powershell-function-re-definition.aspx">Controlling PowerShell Function (Re)Definition</a>.</p>
<p>However, making a function <code>constant</code> does not prevent it from being shadowed in child scopes. Given that a child scope is created in any script, new function definition or script block, this makes it very <em>unconstant</em>. </p>
<p><span id="more-49"></span></p>
<p>Consider this:</p>
<pre># define a constant function, one that cannot be replaced
set-item function:/funca -option constant {
  write-host "this is the outer funca"
  # redefine the function in this new scope
  function funca {
    write-host "this is the inner funca"
  }
  # call this new funca
  funca
}

# call the outer one
funca
</pre>
<p>If you run it, you will see that the inner funca is defined and executed. So much for being constant.</p>
<p>You can, however, make it a bit more permanent by adding the <code>allscope</code> option to the outer function, like this:</p>
<pre># define a constant function, one that cannot be replaced
set-item function:/funca -option constant,<strong>allscope</strong> {
  write-host "this is the outer funca"
  # redefine the function in this new scope - this will fail!
  function funca {
    write-host "this is the inner funca"
  }
}

# call the outer one
funca
</pre>
<p>When we run this, we get an error:</p>
<pre style='color: #000; background-color: #eee; '>PS> funcs
this is the outer funca
<span style='color: #f00; background-color: #fff'>Cannot write to function funca because it is read-only or constant.</span>
<span style='color: #f00; background-color: #fff'>At C:/Documents and Settings/adrian/My Documents/proj/ps1/funcs.ps1:5 char:17</span>
<span style='color: #f00; background-color: #fff'>+   function funca  <span><</span><span><</span><span><</span><span><</span> {</span>
</pre>
<p>Why? Because <code>allscope</code> copies the function to all child scopes that are created. The default behaviour, when finding a function (or variable) is to look in the current scope, then the parent, and so on up to <code>global</code>. By automatically copying the constant function to all scopes, you can prevent the function from ever being redefined.</p>
<p>So to make a function as constant as possible, define it with <code>constant,allscope</code> in your <code>$profile</code>.</p>
<p>PS. It appears that you can use scope modifiers with <code>test-path</code>. These two commands do seem to work, although I&#8217;ve not seen any documentation regarding it:</p>
<pre>test-path function:/funca
test-path function:/script:funca
</pre>
<p>However, <code>get-childitem function:</code> only shows one.</p>
]]></content:encoded>
			<wfw:commentRss>http://ps1.soapyfrog.com/2007/01/26/making-functions-really-read-only/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What colour is yours?</title>
		<link>http://ps1.soapyfrog.com/2007/01/08/what-colour-is-yours/</link>
		<comments>http://ps1.soapyfrog.com/2007/01/08/what-colour-is-yours/#comments</comments>
		<pubDate>Mon, 08 Jan 2007 13:15:41 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Odd]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://ps1.soapyfrog.com/2007/01/08/what-colour-is-yours/</guid>
		<description><![CDATA[I noticed something very odd today. My PowerShell console thinks that the default white text is actually &#8220;DarkYellow.&#8221; If I set it to &#8220;White&#8221; there is no visible difference. What colour is your default console? Update: I&#8217;ve found a use for &#8220;darkyellow&#8221; being white. When you run something like findstr bla *.* the filename match [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed something very odd today.</p>
<p>My PowerShell console thinks that the default white text is actually &#8220;DarkYellow.&#8221;</p>
<p><img id="image23" src="http://ps1.soapyfrog.com/wp-content/uploads/2007/01/funny-colour.gif" alt="doesn't look yellow to me" /></p>
<p>If I set it to &#8220;White&#8221; there is no visible difference.</p>
<p>What colour is your default console?</p>
<p><strong>Update</strong>: I&#8217;ve found a use for &#8220;darkyellow&#8221; being white. When you run something like <code>findstr bla *.*</code> the filename match is brighter, and so becomes &#8220;yellow&#8221; and stands out nicely.</p>
<p><del>Consistently</del><ins>Weirdly</ins>, in CMD.exe, <code>color 6</code> (dark yellow) actually is dark yellow.</p>
<p>Lastly, why is the default background&#8217;s &#8220;darkmagenta&#8221; actually a somewhat de-saturated dark blue? </p>
]]></content:encoded>
			<wfw:commentRss>http://ps1.soapyfrog.com/2007/01/08/what-colour-is-yours/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

