<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Commenti a: Fantom vs Scala: semicolon inference and something more</title>
	<link>http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html</link>
	<description>Linguaggio Scala, Java, AS400 e...cose più serie</description>
	<pubDate>Fri, 30 Jul 2010 17:17:24 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>Di: Carlos</title>
		<link>http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html#comment-9432</link>
		<dc:creator>Carlos</dc:creator>
		<pubDate>Fri, 16 Jul 2010 10:13:39 +0000</pubDate>
		<guid>http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html#comment-9432</guid>
		<description>Hey there!
Good comparison on both langs. I'm trying to do a comparison between JVM and CLR languages. 19 languages I'm including on that comparison including Scala and Fantom. You can have a look on my blog: http://carlosqt.blogspot.com/

The comparison goes like this: you have the same program (OO Hello World) implemented in 19 languages using exactly the same features and rules) and then compare them based on some metrics. The comparisons so far are between Keywords and Lines of code :) 

Fantom:
http://carlosqt.blogspot.com/2010/07/oo-hello-world-fantom.html
Scala:
http://carlosqt.blogspot.com/2010/07/oo-hello-world-scala.html

Then you have:
http://carlosqt.blogspot.com/2010/07/how-many-keywords-do-you-type-in-your.html
and
http://carlosqt.blogspot.com/2010/07/how-many-lines-to-code-same.html</description>
		<content:encoded><![CDATA[<p>Hey there!<br />
Good comparison on both langs. I&#8217;m trying to do a comparison between JVM and CLR languages. 19 languages I&#8217;m including on that comparison including Scala and Fantom. You can have a look on my blog: <a href="http://carlosqt.blogspot.com/" rel="nofollow">http://carlosqt.blogspot.com/</a></p>
<p>The comparison goes like this: you have the same program (OO Hello World) implemented in 19 languages using exactly the same features and rules) and then compare them based on some metrics. The comparisons so far are between Keywords and Lines of code <img src='http://www.francolombardo.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Fantom:<br />
<a href="http://carlosqt.blogspot.com/2010/07/oo-hello-world-fantom.html" rel="nofollow">http://carlosqt.blogspot.com/2010/07/oo-hello-world-fantom.html</a><br />
Scala:<br />
<a href="http://carlosqt.blogspot.com/2010/07/oo-hello-world-scala.html" rel="nofollow">http://carlosqt.blogspot.com/2010/07/oo-hello-world-scala.html</a></p>
<p>Then you have:<br />
<a href="http://carlosqt.blogspot.com/2010/07/how-many-keywords-do-you-type-in-your.html" rel="nofollow">http://carlosqt.blogspot.com/2010/07/how-many-keywords-do-you-type-in-your.html</a><br />
and<br />
<a href="http://carlosqt.blogspot.com/2010/07/how-many-lines-to-code-same.html" rel="nofollow">http://carlosqt.blogspot.com/2010/07/how-many-lines-to-code-same.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: Franco Lombardo</title>
		<link>http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html#comment-8146</link>
		<dc:creator>Franco Lombardo</dc:creator>
		<pubDate>Tue, 05 Jan 2010 22:55:30 +0000</pubDate>
		<guid>http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html#comment-8146</guid>
		<description>Klaus,

another great comment! 
You say "expectations for some reason go higher when it starts looking like a real programming language construct, which perhaps is unreasonable." 
You're right, but I think also that if you give more power you need more safety too. Scala is like a Ferrari race car: as it can run so much, I expect it has good brakes too!!!</description>
		<content:encoded><![CDATA[<p>Klaus,</p>
<p>another great comment!<br />
You say &#8220;expectations for some reason go higher when it starts looking like a real programming language construct, which perhaps is unreasonable.&#8221;<br />
You&#8217;re right, but I think also that if you give more power you need more safety too. Scala is like a Ferrari race car: as it can run so much, I expect it has good brakes too!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: Klaus</title>
		<link>http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html#comment-8051</link>
		<dc:creator>Klaus</dc:creator>
		<pubDate>Mon, 04 Jan 2010 23:55:44 +0000</pubDate>
		<guid>http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html#comment-8051</guid>
		<description>Yes, the period helps in the sense that:

&lt;code&gt;
  .unless &#124;-&#62;Bool&#124; {i == 0} 
&lt;/code&gt;

can occur on a line for itself. This is also the case in Scala if one uses the dot notation. 

Below is the example in Scala with several uses, so one can see the different scenarios.

First the definition of the loop construct:

&lt;pre lang="scala"&gt;
object Loop {
  def loop(stmt : =&#62; Unit) : Unless = {
    new Unless(stmt)
  }

  protected class Unless(stmt : =&#62; Unit) {
    def unless(cond : =&#62; Boolean) {
      stmt
      if(!cond)unless(cond)
    }
  }
}

import Loop._
&lt;/pre&gt;

Then the calls:

&lt;pre lang= "scala"&gt;
// call 1 (using mixfix notation - works):                                                                                        

var i : Int = 10;
loop {
  println(i)
  i = i - 1
} unless (i == 0)

// call 2 (also using mixfix notation, but with unless on a line for itself - gives a compile time error):                                                                           

i = 10;
loop {
  println(i)
  i = i - 1
}
unless (i == 0) // occurs on a line for itself - does not work

// Also, if this last line is left out, no error message is given.
// This is how other OO languages work. Not a problem as such in OO languages,
// but it does reduce the value of this mixfix notation for writing DSLs. It makes a DSL unsafe to use.

//  call 3 (using dot notation - works as expected):                                                                                          

i = 10;
loop {
  println(i)
  i = i - 1
}.unless(i == 0)

// call 4 (using dot notation, with unless on a line for itself - works):                                                                                           

i = 10;
loop {
  println(i)
  i = i - 1
}.
unless(i == 0) // occurs on a line for itself     
&lt;/pre&gt;

Scala offers this mixfix notation for defining DSLs, and it looks very appealing. However, one can 
provide only a partial instantiation of a DSL construct and the Scala compiler will be happy. We normally accept this in the case of dot-notation (that's how it is in Java and Python) but our expectations for some reason go higher when it starts looking like a real programming language construct, which perhaps is unreasonable.
Something to think about. Could one think of imposing "static liveness" constraints? Like: 'this intermediate object shouldnever be the result of a statement'.

Note that this problem can be avoided if instead we define the loop-unless construct as a curried function:

&lt;pre lang="scala"&gt;
def loop_unless(stmt : =&#62; Unit)(cond : =&#62; Boolean) {
  stmt
  if(!cond)loop_unless(stmt)(cond)
}
&lt;/pre&gt;

Then one can write:                                                                                                                 

&lt;pre lang="scala"&gt;
i = 20;
loop_unless {
  println(i)
  i = i - 1
} (i == 0)
&lt;/pre&gt;

However, if we write:

&lt;pre lang="scala"&gt;
i = 20;
loop_unless {
  println(i)
  i = i - 1
} 
&lt;/pre&gt;

leaving out the second parameter, the compiler will complain. This approach currently seems the safest way to
define DSLs in Scala.</description>
		<content:encoded><![CDATA[<p>Yes, the period helps in the sense that:</p>
<p><code><br />
  .unless |-&gt;Bool| {i == 0}<br />
</code></p>
<p>can occur on a line for itself. This is also the case in Scala if one uses the dot notation. </p>
<p>Below is the example in Scala with several uses, so one can see the different scenarios.</p>
<p>First the definition of the loop construct:</p>
<pre lang="scala">
object Loop {
  def loop(stmt : =&gt; Unit) : Unless = {
    new Unless(stmt)
  }

  protected class Unless(stmt : =&gt; Unit) {
    def unless(cond : =&gt; Boolean) {
      stmt
      if(!cond)unless(cond)
    }
  }
}

import Loop._
</pre>
<p>Then the calls:</p>
<pre lang= "scala">
// call 1 (using mixfix notation - works):                                                                                        

var i : Int = 10;
loop {
  println(i)
  i = i - 1
} unless (i == 0)

// call 2 (also using mixfix notation, but with unless on a line for itself - gives a compile time error):                                                                           

i = 10;
loop {
  println(i)
  i = i - 1
}
unless (i == 0) // occurs on a line for itself - does not work

// Also, if this last line is left out, no error message is given.
// This is how other OO languages work. Not a problem as such in OO languages,
// but it does reduce the value of this mixfix notation for writing DSLs. It makes a DSL unsafe to use.

//  call 3 (using dot notation - works as expected):                                                                                          

i = 10;
loop {
  println(i)
  i = i - 1
}.unless(i == 0)

// call 4 (using dot notation, with unless on a line for itself - works):                                                                                           

i = 10;
loop {
  println(i)
  i = i - 1
}.
unless(i == 0) // occurs on a line for itself
</pre>
<p>Scala offers this mixfix notation for defining DSLs, and it looks very appealing. However, one can<br />
provide only a partial instantiation of a DSL construct and the Scala compiler will be happy. We normally accept this in the case of dot-notation (that&#8217;s how it is in Java and Python) but our expectations for some reason go higher when it starts looking like a real programming language construct, which perhaps is unreasonable.<br />
Something to think about. Could one think of imposing &#8220;static liveness&#8221; constraints? Like: &#8216;this intermediate object shouldnever be the result of a statement&#8217;.</p>
<p>Note that this problem can be avoided if instead we define the loop-unless construct as a curried function:</p>
<pre lang="scala">
def loop_unless(stmt : =&gt; Unit)(cond : =&gt; Boolean) {
  stmt
  if(!cond)loop_unless(stmt)(cond)
}
</pre>
<p>Then one can write:                                                                                                                 </p>
<pre lang="scala">
i = 20;
loop_unless {
  println(i)
  i = i - 1
} (i == 0)
</pre>
<p>However, if we write:</p>
<pre lang="scala">
i = 20;
loop_unless {
  println(i)
  i = i - 1
}
</pre>
<p>leaving out the second parameter, the compiler will complain. This approach currently seems the safest way to<br />
define DSLs in Scala.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
