<?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>3 + 4 &#187; what-if</title>
	<atom:link href="http://blog.3plus4.org/category/what-if/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.3plus4.org</link>
	<description>The neighbourhood of 7</description>
	<lastBuildDate>Thu, 23 Apr 2009 02:40:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>A Taste of Nested Classes, intermission</title>
		<link>http://blog.3plus4.org/2009/02/22/a-taste-of-nested-classes-intermission/</link>
		<comments>http://blog.3plus4.org/2009/02/22/a-taste-of-nested-classes-intermission/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 02:38:33 +0000</pubDate>
		<dc:creator>Vassili Bykov</dc:creator>
				<category><![CDATA[newspeak]]></category>
		<category><![CDATA[what-if]]></category>

		<guid isPermaLink="false">http://blog.3plus4.org/?p=131</guid>
		<description><![CDATA[(Continues from part 3). This post is an intermission because it&#8217;s not specifically about nested classes. In fact, it&#8217;s not about anything that really exists in Newspeak. Instead, it reviews a few hypothetical examples to show off some of the expressive capabilities of implicit receiver sends. Most expressions in Newspeak begin with an implicit receiver [...]]]></description>
			<content:encoded><![CDATA[<p>(Continues from <a href="http://blog.3plus4.org/2009/02/15/a-taste-of-nested-classes-part-3/">part 3</a>).</p>
<p>This post is an intermission because it&#8217;s not specifically about nested classes. In fact, it&#8217;s not about anything that really exists in Newspeak. Instead, it reviews a few hypothetical examples to show off some of the expressive capabilities of implicit receiver sends.</p>
<p>Most expressions in Newspeak begin with an implicit receiver send, at least conceptually. In something like</p>
<pre class="smalltalk">
foo size
</pre>
<p>or </p>
<pre class="smalltalk">
OrderedCollection new
</pre>
<p>both foo and OrderedCollection really are message sends, for some definition of &#8220;really&#8221;.</p>
<p>Of course, in some cases we can&#8217;t do without real receivers. There are literals, as well as traditional pseudo-variables (&#8220;reserved words&#8221;), whose interpretation should be hard-coded into the language.</p>
<p>Or should it be?</p>
<p>Starting with literals, imagine that every occurrence of a literal is compiled as an implicit receiver send identifying the type of the literal, with the &#8220;primitive&#8221; value of the literal as the argument. For example,</p>
<pre class="smalltalk">
'Hello, brave new world!'
</pre>
<p>would really mean</p>
<pre class="smalltalk">
(literalString: 'Hello, brave new world!')
</pre>
<p>with <code>literalString:</code> implemented in Object as</p>
<pre class="smalltalk">
literalString: primitiveValue &lt;String&gt; = (
    ^primitiveValue
)
</pre>
<p>At this point this is only a possibility, but one that is explicitly mentioned in <a href="http://bracha.org/newspeak-spec.pdf">the language spec</a> (5.1). If implemented, this would allow user code to redefine the interpretation of what appears to be literals for greater flexibility when implementing internal DSLs.</p>
<p>As for pseudo-variables, consider this implementation of the class Object:</p>
<pre class="smalltalk">
class Object = (
    ...

    self = (
        "empty - return the receiver"
    )

    true = (
        ^True soleInstance
    )

    false = (
        ^False soleInstance
    )

    nil = (
        ^UndefinedObject soleInstance
    )

    thisContext = (
        ^ActivationMirror forSenderContext
    )
)
</pre>
<p>With this, most of the reserved words of Smalltalk become regular messages. The expression</p>
<pre class="smalltalk">
^self foo: nil
</pre>
<p>now really means</p>
<pre class="smalltalk">
^σ self foo: σ nil
</pre>
<p>with σ denoting a reference to (usually!) the receiver unrepresentable in the language syntax. We use the fact that an empty method effectively reads as</p>
<pre class="smalltalk">
^σ
</pre>
<p>to grab that elusive σ in the <code>self</code> method.</p>
<p><code>super</code> is more complicated because it doesn&#8217;t denote a separate object but rather <code>self</code> with a special mode of message lookup. However, even that can be lifted from language magic into a reflective implementation at the library level:</p>
<pre class="smalltalk">
super = (
    ^SuperDispatcher forReceiver: self
)
</pre>
<p>with SuperDispatcher implementing <code>doesNotUndestand:</code> to reflectively look for the method implementing the message starting from the superclass of the implementor of the sender context&#8217;s method. (A mouthful, but that really is what it should do).</p>
<p>In a similar way, <code>outer</code>, the new reserved word of Newspeak not found in Smalltalk could be implemented as a message send handled by reflective code at the image level.</p>
<p>The last two examples, <code>super</code> and <code>outer</code>, are even more hypothetical than the other pseudo-variables. While technically possible, a reflective implementation of those is quite expensive compared to the usual &#8220;language magic&#8221; solution. </p>
<p>Also, this scheme in general leaves the meaning of things like <code>self</code> or <code>nil</code> open to changes by a class for all its subclasses and nested classes. Perhaps there is such a thing as too much flexibility. But even if these ideas are too much or too expensive for the core language, all of the same mechanisms are available to a designer of an internal DSL, and that&#8217;s what makes them interesting. For example, the &#8220;dispatcher receiver&#8221; pattern illustrated with <code>super</code> and <code>outer</code> was conceived in Hopscotch and used there to support <a href="http://waltersmith.us/wp-content/uploads/2005/12/OOPSLA95.pdf">NewtonScript</a>-like object hierarchy-bound message dispatch.</p>
<p>(Continues in <a href="http://blog.3plus4.org/2009/03/08/a-taste-of-nested-classes-part-4/">part 4</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.3plus4.org/2009/02/22/a-taste-of-nested-classes-intermission/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rethinking the comma</title>
		<link>http://blog.3plus4.org/2007/09/02/rethinking-the-comma/</link>
		<comments>http://blog.3plus4.org/2007/09/02/rethinking-the-comma/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 00:37:06 +0000</pubDate>
		<dc:creator>Vassili Bykov</dc:creator>
				<category><![CDATA[what-if]]></category>

		<guid isPermaLink="false">http://blog.3plus4.org/2007/09/02/rethinking-the-comma/</guid>
		<description><![CDATA[This is a follow-up to the post about message chains from a few days ago. Like any syntax-related issue, the choice of the operator is one of those delightful things that encourage a lively exchange of opinions by virtue of being easy to have an opinion about. I ended the post half-seriously considering &#8220;:)&#8221;, but [...]]]></description>
			<content:encoded><![CDATA[<p>This is a follow-up to <a href="http://blog.3plus4.org/2007/08/30/message-chains/">the post about message chains</a> from a few days ago. Like any syntax-related issue, the choice of the operator is one of those delightful things that encourage a lively exchange of opinions by virtue of being easy to have an opinion about. I ended the post half-seriously considering &#8220;:)&#8221;, but here is an interesting thought experiment.</p>
<p>Suppose we abolish a comma as a binary message. A + could just as well work as a generic &#8220;join these two things&#8221; message a comma usually is. Instead, suppose that the comma becomes the new chain operator. Here is what it would look like.</p>
<pre class="smalltalk">
something thingsAt: aKey, includes: aThing,
    ifTrue: [...]
    ifFalse: [...]
</pre>
<p>This fits nicely with the original Smalltalk idea of using natural language punctuation for message control, and continues the line-up of a period and a semicolon by being the weakest message separator of them all.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.3plus4.org/2007/09/02/rethinking-the-comma/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Message chains</title>
		<link>http://blog.3plus4.org/2007/08/30/message-chains/</link>
		<comments>http://blog.3plus4.org/2007/08/30/message-chains/#comments</comments>
		<pubDate>Thu, 30 Aug 2007 18:45:43 +0000</pubDate>
		<dc:creator>Vassili Bykov</dc:creator>
				<category><![CDATA[squeak]]></category>
		<category><![CDATA[what-if]]></category>

		<guid isPermaLink="false">http://blog.3plus4.org/2007/08/30/message-chains/</guid>
		<description><![CDATA[On the squeak-dev mailing list, Fabio Filasieno raised the issue of &#8220;pipes&#8221; in Smalltalk, which generated quite a discussion. Since I&#8217;ve provided an implementation, I&#8217;m also writing down my thoughts on the subject. In a nutshell, this is what the idea is about. While the &#8220;classic&#8221; Smalltalk syntax allows us to write chains of unary [...]]]></description>
			<content:encoded><![CDATA[<p>On the squeak-dev mailing list, Fabio Filasieno <a href="http://lists.squeakfoundation.org/pipermail/squeak-dev/2007-August/119717.html">raised the issue</a> of &#8220;pipes&#8221; in Smalltalk, which generated quite a discussion. Since I&#8217;ve provided an <a href='http://blog.3plus4.org/wp-content/uploads/2007/08/pipe1.zip' title='pipe1.zip'>implementation</a>, I&#8217;m also writing down my thoughts on the subject.</p>
<p>In a nutshell, this is what the idea is about. While the &#8220;classic&#8221; Smalltalk syntax allows us to write chains of unary messages such as</p>
<pre class="smalltalk">
x foo bar
</pre>
<p>without explicit parentheses, this is not the case with keyword messages.</p>
<pre class="smalltalk">
(x foo: 1) bar: 2
</pre>
<p>is a chain similar to the one above, yet its syntactic form is somewhat further removed from the idea of a &#8220;smooth&#8221; linear progression of operations, especially so when there are more than two consecutive message sends:</p>
<pre class="smalltalk">
(((x foo: 1) bar: 2) baz: 3) zork: 4
</pre>
<p>Imagine now that we have an operator which I will for now designate as &#8220;:>&#8221; allowing us to rewrite the above as</p>
<pre class="smalltalk">
x foo: 1 :> bar: 2 :> baz: 3 :> zork: 4
</pre>
<p>In other words, it makes the result of the preceding expression the receiver of the following message send, so that in fact</p>
<pre class="smalltalk">
x foo :> bar :> baz
</pre>
<p>and </p>
<pre class="smalltalk">
x foo bar baz
</pre>
<p>are two syntactic forms of the same chain of messages.</p>
<p>One obvious example of the use of this operator is rewriting something like</p>
<pre class="smalltalk">
(aCollection select: [:some | some foo]) collect: [:each | each bar]
</pre>
<p>as</p>
<pre class="smalltalk">
aCollection select: [:some | some foo] :> collect: [:each | each bar]
</pre>
<p>An even more likely case, which I don&#8217;t believe was mentioned on squeak-dev, are complex conditions:</p>
<pre class="smalltalk">
something thingsAt: aKey :> includes: aThing :>
    ifTrue: [...]
    ifFalse [...]
</pre>
<p>Writing the &#8220;standard&#8221; form often involves going back to the beginning of the expression to add parentheses once you&#8217;ve written enough of the expression to realize what it will look like. The chain operator exactly follows the &#8220;do this, then this, then that&#8221; structure of such expressions and does not require going back.</p>
<p>The change set linked at the beginning of the post implements the operator for Squeak. The inevitable question now is, Is This A Good Thing?</p>
<p>Clearly it adds nothing new to the language&#8212;chaining messages was always possible&#8212;only a new ability to express something in a different syntactic form. Such things generally invite (justified) suspicion and tossing around the various &#8220;less is more&#8221; quotes. Without questioning the value of minimalism and structured approach, some prior &#8220;sugary&#8221; additions such as tuples (brace Array constructors) or ifNil:/ifNotNil: could be (and have been) criticized on the same grounds. Any Array constructor discussion usually involves someone pointing out how the ease of array creation is overrated because redesigning the code to replace arrays with structured objects or store them in self-documenting variables only improves the code. This is true, of course&#8212;and yet in some contexts, one of which are DSL-like Smalltalk expressions, syntactically lightweight array creation turns out quite useful. Perhaps there is a similar &#8220;killer use&#8221; out there waiting for lightweight message chains to become available. Or perhaps not. My take is that this operator <em>might</em> be a good thing, and only practice can show if there are use cases out there waiting for it.</p>
<p>As for less is more&#8212;perhaps the power of Smalltalk is not as much in having a small untouchable core (and if anything, Object and UndefinedObject protocols in Squeak live to prove that more is more) as in having a core small and malleable enough to support this sort of extensions and experimentation. I&#8217;d rather say Squeak core is still not small and malleable enough if something like this can only be done by modifying the compiler rather than tweaking the meta-level.</p>
<p>Having said this, I should comment on <a href="http://lists.squeakfoundation.org/pipermail/squeak-dev/2007-August/119787.html">Bert Freudenberg&#8217;s elegant #asPipe implementation</a>. There are two reasons why I consider it very neat but still not enough of the real thing. One is the look of the code. The value proposition of pipes is improving readability. Getting rid of parentheses is only one step towards that, the other is having the links of the chain stand out enough for the reader to easily see where the distinct steps are. This is partly an issue of formatting, but proper &#8220;graphic design&#8221; of a visually distinct special operator is still unbeatable.</p>
<p>In fact, in terms of visibility I think the operator even better than &#8220;:>&#8221; (which already looks quite like a smiley) is &#8220;:)&#8221;:</p>
<pre class="smalltalk">
something thingsAt: aKey&nbsp;:) includes: aThing&nbsp;:)
    ifTrue: [...]
    ifFalse [...]
</pre>
<p>The other issue are minor anomalies that are always hard to hide with DNU tricks because of the need for the DNU handler to have some rudimentary behavior of its own, and because some things are not handled by messages. For example:</p>
<pre class="smalltalk">
2 asPipe between: 1 and: 3; == true
</pre>
<p>evaluates to false. </p>
<pre class="smalltalk">
2 asPipe between: 1 and: 3; ifTrue: [#foo]
</pre>
<p>fails to compile, ruling out the use of pipes to simplify conditions. </p>
<pre class="smalltalk">
foo := [#nil].
bar := [#notNil].
nil asPipe value; ifNil: foo ifNotNil: bar
</pre>
<p>does compile because the branches are not literal blocks, but then the result of the &#8220;pipe&#8221; is #notNil.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.3plus4.org/2007/08/30/message-chains/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
