<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Project Kotlin</title>
	
	<link>http://blog.jetbrains.com/kotlin</link>
	<description>New programming language for the JVM by JetBrains</description>
	<lastBuildDate>Mon, 17 Jun 2013 14:13:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/kotlin" /><feedburner:info uri="kotlin" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Type-Safe Web with Kotlin</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/KVnLELob02o/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/06/type-safe-web-with-kotlin/#comments</comments>
		<pubDate>Mon, 17 Jun 2013 14:13:40 +0000</pubDate>
		<dc:creator>Andrey Breslav</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=1091</guid>
		<description><![CDATA[We told you about Kara Web Framework a while ago. It is written in Kotlin and relies on type-safe builders. It doesn&#8217;t have to be the only web framework for Kotlin, but the general principles seem good, so I wrote &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/06/type-safe-web-with-kotlin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jetbrains.com/kotlin/files/2013/06/web1.png"><img class="alignleft size-medium wp-image-1096" src="http://blog.jetbrains.com/kotlin/files/2013/06/web1-300x225.png" alt="" width="300" height="225" /></a>We <a href="http://blog.jetbrains.com/kotlin/2013/01/an-interview-with-andy-selvig-author-of-kara-web-framework/">told you</a> about <a href="http://karaframework.com/">Kara Web Framework</a> a while ago. It is written in Kotlin and relies on type-safe builders. It doesn&#8217;t have to be the only web framework for Kotlin, but the general principles seem good, so I wrote an article about these principles: <strong><a href="http://jaxenter.com/type-safe-web-with-kotlin-47395.html">Type-Safe Web with Kotlin</a></strong>, it gives an overview of the framework design, and then gives many details about builders, extensions and so on.<span id="more-1091"></span></p>
<p><strong>Examples</strong> used in this article are available at <a href="https://github.com/abreslav/kara-files/blob/master/src/tutorial.kt">https://github.com/abreslav/kara-files/blob/master/src/tutorial.kt</a> and <a href="https://github.com/abreslav/kara-files/blob/master/src/small_builder.kt">https://github.com/abreslav/kara-files/blob/master/src/small_builder.kt</a></p>
<p><strong>Slides</strong> from my talk given at JPoint in Saint Petersburg are also available <a href="https://prezi.com/hndtabwcfy5h/type-safe-web-with-kotlin-jpoint/">online</a>.<br />
The talk was given in Russian, video accessible is <a href="http://javapoint.ru/talks/12/">here</a>.</p>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/KVnLELob02o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/06/type-safe-web-with-kotlin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/06/type-safe-web-with-kotlin/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=type-safe-web-with-kotlin</feedburner:origLink></item>
		<item>
		<title>Talk @ GeekOUT Tallinn: Language Design Trade-Offs (Kotlin and Beyond)</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/DUPNOxyK1Ww/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/06/talk-geekout-tallinn-language-design-trade-offs-kotlin-and-beyond/#comments</comments>
		<pubDate>Mon, 10 Jun 2013 11:27:11 +0000</pubDate>
		<dc:creator>Andrey Breslav</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=1080</guid>
		<description><![CDATA[This week I&#8217;m speaking at GeekOUT Tallin, and my colleagues Mikhail Vink and Sergey Karashevich are holding a 15-minute DEMO on Thursday, telling you about cool stuff in JetBrains&#8217; IDEs. The topic of my talk is &#8220;Language Design Trade-Offs (Kotlin &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/06/talk-geekout-tallinn-language-design-trade-offs-kotlin-and-beyond/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This week I&#8217;m speaking at <a href="http://geekout.ee/">GeekOUT Tallin</a>, and my colleagues Mikhail Vink and Sergey Karashevich are holding a 15-minute DEMO on Thursday, telling you about cool stuff in JetBrains&#8217; IDEs.</p>
<p>The topic of my talk is &#8220;<strong>Language Design Trade-Offs (Kotlin and Beyond)</strong>&#8220;, so one can summarize it as &#8220;why designing languages is SO interesting&#8221;.</p>
<p style="text-align: center"><img class="aligncenter" src="http://www.b-lay.com/wp-content/uploads/2013/01/finding_balance_news_625x430.jpg" alt="" width="350" /> <span id="more-1080"></span></p>
<p style="text-align: center"><strong>Abstract</strong></p>
<blockquote><p>If your programming language is small, you’re probably born before 1950, and your first computer was bigger than your present apartment. And even those languages are not so small. One spends quite some time to master a programming language. Why?</p>
<p>Because there are very many decisions “compressed” into the form of a language. Nothing limits a programmer’s imagination like a compiler, and nothing limits a language design like a real world with all of its “legacy”, compatibility concerns, performance limitations, generations-old habits and leaky abstractions.</p>
<p>This talk is about tradeoffs: why we, as language designers, do (or rather did) this and not that.</p></blockquote>
<p>See you on Friday, 14 June 2013 11:30 @ Room 2</p>
<p><a href="30 @ Room 2">http://geekout.ee/schedule/andrey-breslav-jetbrains-building-jvm-languages/</a></p>
<p>UPD:</p>
<ul>
<li><a href="http://www.slideshare.net/abreslav/trade-offs-22989326">Slides for this talk</a></li>
<li><a href="http://confluence.jetbrains.com/display/Kotlin/Talks+and+Publications">More slides and videos about Kotlin</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/DUPNOxyK1Ww" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/06/talk-geekout-tallinn-language-design-trade-offs-kotlin-and-beyond/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/06/talk-geekout-tallinn-language-design-trade-offs-kotlin-and-beyond/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=talk-geekout-tallinn-language-design-trade-offs-kotlin-and-beyond</feedburner:origLink></item>
		<item>
		<title>Kotlin M5.3: IntelliJ IDEA 13, Delegated Properties and more</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/w8U-OQRA2zM/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/06/kotlin-m5-3-idea-13-delegated-properties-and-more/#comments</comments>
		<pubDate>Thu, 06 Jun 2013 06:48:55 +0000</pubDate>
		<dc:creator>Andrey Breslav</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=1060</guid>
		<description><![CDATA[Kotlin M5.3 brings support for IntelliJ IDEA 13 and some new features for you to check out. We are moving towards powerful runtime support, including reflection and other framework-enabling features. This milestone marks our first steps in that direction. IntelliJ &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/06/kotlin-m5-3-idea-13-delegated-properties-and-more/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Kotlin M5.3 brings support for IntelliJ IDEA 13 and some new features for you to check out. We are moving towards powerful runtime support, including reflection and other framework-enabling features. This milestone marks our first steps in that direction.  <span id="more-1060"></span></p>
<h2>IntelliJ IDEA 12.1 and 13</h2>
<p>First early access versions of <a href="http://blogs.jetbrains.com/idea/2013/05/intellij-idea-13-early-preview-is-out/">IntelliJ IDEA 13</a> are coming out, and we ship a Kotlin plugin compatible with these versions. Remember it&#8217;s an EAP, use it at your own risk. Of course, good old <a href="http://www.jetbrains.com/idea/download/">IntelliJ IDEA 12.1</a> is supported as well.</p>
<p><strong>Note</strong>: Some news about Kotlin support in <a href="http://developer.android.com/sdk/installing/studio.html">Android Studio</a> are coming soon.</p>
<h2>Many Improvements</h2>
<p>As usual M5.3 brings many improvements both in the compiler and the IDE. In the compiler we are still mostly concerned with performance, which is gradually improving. The IDE gets new quick fixes and refactorings, some of which are described below. You can now navigate to properties overriding the one you are looking at (see icons in the left gutter). The editor recognizes the syntax of <a href="http://confluence.jetbrains.com/display/Kotlin/Kotlin+Doc">KDoc</a> (thanks to <a href="https://github.com/JetBrains/kotlin/pull/280">this pull request</a>)&#8230; But first, let&#8217;s talk about cool new language features, some long awaited, some unexpected (maybe).</p>
<h2>New Language Feature: Delegated Properties</h2>
<p>We often get feature requests like:</p>
<ul>
<li>Support lazy properties: the value gets computed only upon first access.</li>
<li>Support observable properties: listeners get notified about changes to this property.</li>
<li>Support storing properties in a map, not in separate field each.</li>
<li>Support &lt;my favorite kind of property semantics&gt;&#8230;</li>
</ul>
<p>One way of addressing these requests would be to say that life is tough and users have to suffer. Another way would be to support different kinds of properties on the language level. We do not like either of these approaches: too many unhappy users on the one hand, too many ad hoc features on the other hand. So, we take a third approach: support a unified mechanism that covers all these requests (and probably more), so that particular kinds of properties can be implemented in libraries, without altering the language.</p>
<p>Meet <strong>delegated properties</strong>:</p>
<pre>class Example {
  var p: String by Delegate()
}</pre>
<p>There&#8217;s some new syntax: you can say &#8220;val &lt;property name&gt;: &lt;Type&gt; by &lt;expression&gt;&#8221;. The expression after <strong>by</strong> is the <em>delegate</em>, because get() and set() methods corresponding to the property will be delegated to it.  Property delegates don&#8217;t have to implement any interface, but they have to provide methods named get() and set() to be called. For example:</p>
<pre><span style="color: #222222;font-family: 'Courier 10 Pitch', Courier, monospace;line-height: 21px">class Delegate() {</span>
  fun get(thisRef: Any?, prop: PropertyMetadata): String {
    return "$thisRef, thank you for delegating '${prop.name}' to me!"
  }

  fun set(<span style="color: #222222;font-family: 'Courier 10 Pitch', Courier, monospace;line-height: 21px">thisRef: Any?, prop: PropertyMetadata, value: String) {
    println("$value has been assigned")
</span>  }
}</pre>
<p>When we read from p, the get() function from Delegate is called, so that its first parameter is the object we read p from and the second parameter holds a description of p itself (e.g. you can take its name). For example:</p>
<pre>val e = Example()
println(e.p)</pre>
<p>This prints &#8220;Example@33a17727, thank you for delegating &#8216;p&#8217; to me!&#8221; Similarly, when we assign to p, the set() function is called. The first two parameters are the same, and the third hold the value being assigned:</p>
<pre>e.p = "NEW"</pre>
<p>This prints &#8220;NEW has been assigned to &#8216;p&#8217; in Example@33a17727&#8243;.</p>
<p>Probably, you already see how to implement things like lazy or observable with this mechanism. Try it as a metter of exercise, but most of it is already done in the <a href="https://github.com/JetBrains/kotlin/blob/build-0.5.742/libraries/stdlib/src/kotlin/properties/Delegation.kt">standard library</a>.</p>
<p>The <a href="https://github.com/JetBrains/kotlin/blob/build-0.5.742/libraries/stdlib/src/kotlin/properties/Delegation.kt#L12">kotlin.properties.Delegates</a> object holds the most useful stuff. Let&#8217;s start with lazy:</p>
<pre>import kotlin.properties.Delegates

class LazySample {
    val lazy: String by Delegates.lazy {
        println("computed!")
        "Hello"
    }
}</pre>
<p>Delegates.lazy() is a function that returns a delegate that implements a lazy property: the first call to get() executes the lambda expression passed to lazy() as an argument and remembers the result, subsequent calls to get() simply return the remembered result. If you want <strong>thread safety</strong>, use blockingLazy() instead: it guarantees that the values will be computed only in one thread, and that all threads will see the same value.</p>
<p>Now, let&#8217;s turn to observable:</p>
<pre>class User {
    var name: String by Delegates.observable("&lt;no name&gt;") {
        d, old, new -&gt;
        println("$old -&gt; $new")
    }
}</pre>
<p>The observable() function takes two arguments: initial value and a handler for modifications. The handler gets called every time we assign to &#8216;name&#8217;, it has three parameters: a property being assigned to, the old value and the new one. If you want to be able to &#8216;veto&#8217; the assignment, use vetoable() instead of observable().</p>
<p>Next may be somewhat unexpected: users frequently ask what to do when you have a non-null var, but you don&#8217;t have an appropriate value to assign to it in constructor (i.e. it must be assigned later)? You can&#8217;t have an uninitialized non-abstract property in Kotlin:</p>
<pre>class Foo {
  var bar: Bar // error: must be initialized
}</pre>
<p>You could initialize it with null, bit then you&#8217;d have to check every time you access it. Now you have a delegate to handle this:</p>
<pre>class Foo {
  var bar: Bar by Delegates.notNull()
}</pre>
<p>If you read from this property before writing to it, it throws an exception, after the first assignment it works as expected.</p>
<p>The last thing to show is properties stored in a map. This comes up a lot in applications like parsing JSON or doing other &#8220;dynamic&#8221; stuff:</p>
<pre>class User(val map: Map&lt;String, Any?&gt;) {
    val name: String by Delegates.mapVal(map)
    val age: Int     by Delegates.mapVal(map)
}</pre>
<p>In this example, the constructor takes a map:</p>
<pre>val user = User(mapOf(
    "name" to "John Doe",
    "age"  to 25
))</pre>
<p>Delegates take values from this map (by the string keys &#8211; names of properties):</p>
<pre>println(user.name) // Prints "John Doe"
println(user.age)  // Prints 25</pre>
<p>Of course, you can have var&#8217;s as well (with mapVar() function), that will modify the map upon assignment (note that you&#8217;d need MutableMap instead of read-only Map).</p>
<p>There are other use cases, and probably numerous improvements to these ones. Fantasize, experiment, enjoy! <img src='http://blog.jetbrains.com/kotlin/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h2>First Steps in SAM Conversions</h2>
<p>We introduced <a title="Kotlin M5.2: IntelliJ IDEA 12.1 and Gradle" href="http://blog.jetbrains.com/kotlin/2013/04/kotlin-m5-2-intellij-idea-12-1-and-gradle/">SAM constructors</a> last time. Of course, this is not enough, so we are working on full SAM conversions. The feature is not finished yet, but you can already use it in simple case like this:</p>
<pre>SwingUtilities.invokeLater {
  button.setVisible(true)
}</pre>
<p>To remind you, SAM conversions is what Java 8 uses for lambdas: when you have an interface with only one (abstract) method, like Comparator or Runnable, you are allowed to pass in a lambda where an instance of this interface is expected (in this example we pass a lambda instead of a Runnable). Kotlin does not have this as a language feature (for it is not needed in a language with proper function types), so it will only work for Java classes.</p>
<h2>First Steps in &#8220;Callable References&#8221;</h2>
<p>Another thing we are working on is &#8220;Callable References&#8221; or &#8220;Feature Literals&#8221;, i.e. an ability to pass named functions or properties as values. Users often ask &#8220;I have a foo() function, how do I pass it as an argument?&#8221;. The answer is: &#8220;you prefix it with a &#8216;::&#8217;&#8221;. For example:</p>
<pre>fun isOdd(x: Int) = x % 2 != 0

val numbers = listOf(1, 2, 3)
println(numbers.filter(::isOdd)) // Prints [1, 3]</pre>
<p>Here &#8220;::isOdd&#8221; is a value of function type &#8220;(Int) -&gt; Boolean&#8221;, and you can pass it as a filtering predicate. Another example:</p>
<pre>fun compose&lt;A, B, C&gt;(f: (B) -&gt; C, g: (A) -&gt; B): (A) -&gt; C {
    return {x -&gt; f(g(x))}
}</pre>
<p>This function return a composition of two functions passed to it: compose(f, g) = f(g(*)). Now, you can apply it to callable references:</p>
<pre>fun length(s: String) = s.size

val oddLength = compose(::isOdd, ::length)
val strings = listOf("a", "ab", "abc")
println(strings.filter(oddLength)) // Prints "[a, abc]"</pre>
<p>If you want to use a member of a class, you need to qualify it, and the result will be of type &#8220;extension function&#8221;,  e.g. String::toCharArray gives you an extension function for type String.</p>
<p>Note that this is <strong>early work in progress</strong>, so many things do not work yet, for example, overload disambiguation, type inference, support for properties etc. Eventually this feature will evolve into full type-safe reflection, but today we are only starting working on it.</p>
<h2>Change Signature Refactoring</h2>
<p>Adding/removing/reordering function parameters may be tedious when you have a lot of call sites to update. That&#8217;s why IDEs prove a &#8220;Change Signature&#8221; refactoring. Place your cursor on a function or a constructor and hit Ctrl+F6 (Cmd+F6 on Mac), and you&#8217;ll get a dialog like this:</p>
<p><img class="aligncenter" src="https://www.evernote.com/shard/s171/sh/b4eb0e6e-b866-4a12-83f9-b94ed3daf8d9/1ec5d8ee74c94a7c6433813dd3c488e9/deep/0/Screenshot%206/5/13%206:42%20PM.jpg" alt="" /></p>
<p>Change type, rename, reorder or delete parameters and all your call sites will be updates accordingly.</p>
<h2>Quick Fixes for &#8220;Type Mismatch&#8221; etc</h2>
<p>Thanks to contributions by <a href="https://github.com/univerio">Jack Zhou</a>, <a id="js_3" href="https://github.com/sapal">Michał Sapalski</a>, <a id="js_5" href="https://github.com/lopekpl">Wojciech Łopata</a> and other students of Open Source Mentorship program led by Stanford University, we now get many cool quick fixes. For example, when you get a type mismatch error, hit Alt+Enter and get some proposals to fix your code:</p>
<p><img class="aligncenter" src="https://www.evernote.com/shard/s171/sh/ff9bd33c-ecd1-4800-91f2-4a69db761a37/f829b15d7de80df501e39b64f6973754/deep/0/Screenshot%206/5/13%206:51%20PM.jpg" alt="" /></p>
<h2>Code Transformations</h2>
<p>Another group of useful IDE actions to convert between equivalent forms of code, like:<br />
<iframe width="640" height="360" src="http://www.youtube.com/embed/Cfwq-pYtiDY?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>You can also use Ctrl+Shift+Up/Down to move statements or declarations:</p>
<p><iframe width="640" height="480" src="http://www.youtube.com/embed/RRRROZc3-2g?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<h2>Installation</h2>
<p>As usual, the new plugin can be installed from <a href="http://plugins.jetbrains.com/plugin?pr=idea&amp;pluginId=6954">our plugin repository</a>.</p>
<p><strong>Have a nice Kotlin!</strong></p>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/w8U-OQRA2zM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/06/kotlin-m5-3-idea-13-delegated-properties-and-more/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/06/kotlin-m5-3-idea-13-delegated-properties-and-more/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=kotlin-m5-3-idea-13-delegated-properties-and-more</feedburner:origLink></item>
		<item>
		<title>Kotlin M5.2: IntelliJ IDEA 12.1 and Gradle</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/dVG6d971vsY/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/04/kotlin-m5-2-intellij-idea-12-1-and-gradle/#comments</comments>
		<pubDate>Thu, 04 Apr 2013 11:00:42 +0000</pubDate>
		<dc:creator>Andrey Breslav</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=1038</guid>
		<description><![CDATA[Another update of Kotlin comes out today. Welcome Kotlin M5.2.  Support for New IntelliJ IDEA Koltin M5.2 supports (in fact, requires) the recently released IntelliJ IDEA 12.1. The Kotlin IDE improvements include: Kotlin classes in the Class Hierarchy view. Just &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/04/kotlin-m5-2-intellij-idea-12-1-and-gradle/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Another update of <a href="http://kotlin.jetbrains.org/">Kotlin</a> comes out today. Welcome Kotlin M5.2. <span id="more-1038"></span></p>
<h2>Support for New IntelliJ IDEA</h2>
<p>Koltin M5.2 supports (in fact, requires) the recently released <a href="http://www.jetbrains.com/idea/download/index.html">IntelliJ IDEA 12.1</a>.</p>
<p>The Kotlin IDE improvements include:</p>
<ul>
<li>Kotlin classes in the <a href="http://www.jetbrains.com/idea/webhelp/viewing-hierarchies.html">Class Hierarchy</a> view. Just hit Ctrl+H on a class name to see its descendants and/or parents.</li>
<li>Folding for imports (you don&#8217;t have to scroll through imports to get to your code any more).</li>
<li>New UI for Kotlin library configuration: you can now control library names and location, and kotlin-runtime.jar is not copied to your project by default. It just works.</li>
<li>Support for JavaScript-targeted modules is significantly improved.</li>
<li>Optimizing imports on the fly: <em>IDE Settings -&gt; Editor -&gt; Auto Import -&gt; Optimize imports on the fly</em>.</li>
<li>New quick fixes: place the cursor on an error, and hit Alt+Enter.</li>
</ul>
<h2>SAM Constructors</h2>
<p>When using Java libraries, you can now create an instance of a SAM interface (one with a <strong>S</strong>ingle <strong>A</strong>bstract <strong>M</strong>ethod) by calling its name and passing a function literal. For example:</p>
<pre>SwingUtilities.invokeLater(Runnable { doItNow() })</pre>
<p><strong>This works only for Java classes</strong>. In fact, it is not a part of the language, but a feature of how Java classes are loaded into Kotlin: we define a <em>synthesized</em> function</p>
<pre>fun Runnable(body: () -&gt; Unit) = object : Runnable {
    override fun run() {
        body()
    }
<span style="color: #222222;font-family: 'Courier 10 Pitch', Courier, monospace;line-height: 21px">}</span></pre>
<p>So whenever you import Runnable, the function is there too, and you can use it.</p>
<p>This is the first chunk of SAM-conversion support for Java. Real SAM conversions will come soon, and you&#8217;ll be able to say simply</p>
<pre>SwingUtilities.invokeLater { doItNow(); }</pre>
<h2>New Gradle Plugin</h2>
<p>Starting with M5.2, in addition to the long-available Maven plugin, there&#8217;s a Gradle plugin for Kotlin from JetBrains.</p>
<p>Here&#8217;s an example for building a Kotlin module with Gradle:</p>
<pre>buildscript {
  repositories {
    mavenCentral()
    maven {
      url 'http://repository.jetbrains.com/all'
    }
  }
  dependencies {
    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT'
  }
}

apply plugin: "kotlin"

repositories {
  mavenCentral()
  maven {
    url 'http://repository.jetbrains.com/all'
  }
}

dependencies {
  compile 'org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT'
}</pre>
<p>More examples &amp; docs can be found <a href="http://confluence.jetbrains.com/display/Kotlin/Kotlin+Build+Tools#KotlinBuildTools-Gradle">here</a>.</p>
<h2>Reminder: KAnnotator</h2>
<p>Don&#8217;t forget that you now have <a title="KAnnotator 0.1 is out" href="http://blog.jetbrains.com/kotlin/2013/03/kannotator-0-1-is-out/">KAnnotator</a> at your service.</p>
<p><strong>Have a nice Kotlin!</strong></p>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/dVG6d971vsY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/04/kotlin-m5-2-intellij-idea-12-1-and-gradle/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/04/kotlin-m5-2-intellij-idea-12-1-and-gradle/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=kotlin-m5-2-intellij-idea-12-1-and-gradle</feedburner:origLink></item>
		<item>
		<title>The Dot Operator</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/gLxR4U6F4oY/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/04/the-dot-operator/#comments</comments>
		<pubDate>Mon, 01 Apr 2013 06:00:06 +0000</pubDate>
		<dc:creator>Andrey Breslav</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=1007</guid>
		<description><![CDATA[Point-free style is a big trend in modern functional programming: it allows to manipulate functions without mentioning their arguments which makes the code concise and compositional. Here is an example from Wikipedia: mf = (. map) . (.) . filter &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/04/the-dot-operator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Point-free_programming">Point-free</a> style is a big trend in modern functional programming: it allows to manipulate functions without mentioning their arguments which makes the code concise and compositional. Here is an example from Wikipedia:</p>
<pre>mf = (. map) . (.) . filter</pre>
<p>This function, written in Haskell, composes a map() function with a filter() function. As you can see, point-free style largely relies on dots.</p>
<p>Kotlin is not a functional language per se, but we are happy to borrow useful features from other languages. So, today I&#8217;ll write about dots.<span id="more-1007"></span></p>
<h1>The Dot</h1>
<p>We introduce the <strong>dot</strong> operator in Kotlin. As usual, it works by convention. If there&#8217;s a function like this</p>
<pre>fun Foo.dot() {
    println("a dot!")
}</pre>
<p>it will be called whenever there&#8217;s a dot (&#8220;.&#8221;) after an expression of type Foo:</p>
<pre>fun test(f: Foo) {
    f.foo()
    Foo().bar().baz()
}</pre>
<p>This function prints &#8220;a dot!&#8221; twice: once for each dot after a Foo. The bar() function doesn&#8217;t return a Foo, so the dot after it doesn&#8217;t count.</p>
<h1>Dot Chaining</h1>
<p>What if my dot() function returned something, for example, another Foo?</p>
<pre>class Foo(val count: Int)

fun Foo.dot(): Foo {
    return Foo(count + 1)
}</pre>
<p>then, of course, it&#8217;s result is used to call whatever comes after the dot:</p>
<pre>println(Foo(1).count)</pre>
<p>This prints 2, because the dot() function returned a new Foo with an increased counter.</p>
<p>As you can see, the dot operator gives us a lot of power and addresses most of the issues previously tackled only by <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming">aspect-oriented programming</a>.</p>
<h1>Flavors of the Dot</h1>
<p>The real power of the dot operator comes in when you declare it with a parameter:</p>
<pre>fun Any.dot(p: Dot) {
   ...
}</pre>
<p>The parameter must be of the Dot type, of which there are a few interesting predefined values:</p>
<pre>LEFT
RIGHT
TOP
BOTTOM</pre>
<p>These values correspond, obviously, to the position of the dot:</p>
<pre>fun test() {
    println(a.b[1..2])
}</pre>
<p>One might think that in this example dot() is called three times: one for &#8220;a.b&#8221;, with the argument BOTTOM, then twice for &#8220;1..2&#8243;: first with LEFT, and then with RIGHT (these are not two BOTTOMs, because &#8220;..&#8221; is a single <a href="http://en.wikipedia.org/wiki/Token_(parser)#Token">token</a> in Kotlin), but in fact it gets called four times, and the fourth time (in fact it comes first) with TOP as an argument.</p>
<p>I&#8217;m sure you already see why: in Kotlin, we never forget to dot out i&#8217;s, and that dot counts as well; its position is clearly TOP (we could introduce a separate <a href="http://en.wikipedia.org/wiki/Tittle">tittle</a>() function, but we found it too inconvenient). Tittles above j&#8217;s count just as well, same for dots in ; ! ? etc.</p>
<h1>The Depth of the Dot</h1>
<p>You may be wondering what happens if dot() is defined like this:</p>
<pre>fun Foo.dot() {
    println(this.count)
}</pre>
<p>There is a dot after <strong>this</strong>, which has type Foo, in the body of Foo.dot() function itself, so dot() should be called recursively at that point and, seemingly, never terminate. This is called a <em>higher-order dot</em>, and is executed only if there&#8217;s a function dot1() defined on Foo. If dot1(), in turn, contains a higher-order dot, then dot2() is called and so on:</p>
<pre>fun Foo.dot1() {
    println(this.count) // a call to dot2() if that is defined
}</pre>
<p>This corresponds to Russel&#8217;s approach to set theory called <a href="http://en.wikipedia.org/wiki/Type_theory">type theory</a> (with its notion of a <a href="http://en.wikipedia.org/wiki/Class_(set_theory)">class</a>), which lies the solid foundation for statically-typed object-oriented programming.</p>
<h1>Conclusion</h1>
<p>We are planning to support the dot operator very soon. The first version will be restricted to basic ASCII characters such as . : ; ! ? and, of course i, but in the future we plan to expand it to other characters like ё.</p>
<p><strong>Have a nice Dot!</strong></p>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/gLxR4U6F4oY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/04/the-dot-operator/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/04/the-dot-operator/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-dot-operator</feedburner:origLink></item>
		<item>
		<title>KAnnotator 0.1 is out</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/X4eTBUDRfOc/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/03/kannotator-0-1-is-out/#comments</comments>
		<pubDate>Fri, 29 Mar 2013 14:42:56 +0000</pubDate>
		<dc:creator>Andrey Breslav</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=1005</guid>
		<description><![CDATA[We announced KAnnotator back in December: it helps you against NPEs in Java and makes your Kotlin code nicer. Today we are pleased to announce a KAnnotator Plugin for IntelliJ, version 0.1. It is available from the plugin repository. Why &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/03/kannotator-0-1-is-out/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We announced KAnnotator back <a title="Kotlin M4 is Out!" href="http://blog.jetbrains.com/kotlin/2012/12/kotlin-m4-is-out/">in December</a>: it helps you against NPEs in Java and <a title="Using External Annotations" href="http://blog.jetbrains.com/kotlin/using-external-annotations/">makes your Kotlin code nicer</a>. Today we are pleased to announce a KAnnotator Plugin for IntelliJ, version 0.1. It is available from the plugin repository.<span id="more-1005"></span></p>
<h2>Why Infer Annotations</h2>
<p>An excerpt from an earlier <a title="Kotlin M4 is Out!" href="http://blog.jetbrains.com/kotlin/2012/12/kotlin-m4-is-out/">blog post</a>, explaining what KAnnotator is:</p>
<blockquote><p><span style="font-size: 16px">Since Kotlin M3</span><span style="font-size: 16px">, you can use </span><a href="http://blog.jetbrains.com/kotlin/using-external-annotations/">external annotations</a><span style="font-size: 16px"> to tell the system that your methods return/take non-null values. This mechanism is useful even if you don&#8217;t use Kotlin: you can turn on </span><a href="http://www.jetbrains.com/idea/documentation/howto.html">nullability inspections for Java</a><span style="font-size: 16px"> too (and I totally recommend you to do so).</span></p>
<p>One problem about this used to be that, while you can annotate your own code while you write it (and we do it <a href="https://github.com/JetBrains/kotlin/blob/master/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeConstructor.java">all</a> <a href="https://github.com/JetBrains/intellij-community/blob/master/platform/util/src/com/intellij/util/text/CharArrayUtil.java">the</a> <a href="https://github.com/JetBrains/la-clojure/blob/master/src/org/jetbrains/plugins/clojure/utils/ClojureUtils.java">time</a> at JetBrains), your favorite library is not annotated, and it is so big, you can&#8217;t annotate it manually.</p>
<p>The key thing here is that &#8216;manually&#8217;. A programmer is a lazy creature, and by virtue of our laziness, we want to automate as much as we can. <strong>KAnnotator </strong>is a tool that <strong>annotates your libraries automatically</strong> (the tool is written in Kotlin, of course).</p>
<p>How it works, in a nutshell: you have your library as a jar (or a number of jars), you tell KAnnotator to <em>infer</em> annotations for these jars, and get a bunch of .xml files back. They contain annotations for methods and fields, for example:</p>
<p><a href="http://blog.jetbrains.com/kotlin/files/2012/12/annotations.xml_.png"><img class="aligncenter" src="http://blog.jetbrains.com/kotlin/files/2012/12/annotations.xml_.png" alt="" width="409" height="149" /></a></p>
<p>Now, you can attach these annotations to your project, and both Java IDE and Kotlin compiler will see them.</p></blockquote>
<p>We used KAnnotator to infer annotations for JDK that ship with Kotlin. Now you can use it as well: to annotate your own libraries.</p>
<h2>Install</h2>
<p>KAnnotator ships as a separate plugin for <a href="http://www.jetbrains.com/idea/">IntelliJ IDEA 12</a> or higher (both 12.0.4 and 12.1 will work). Note that the Kotlin plugin<strong> is not required</strong>.  To install the plugin, follow the instructions from <a href="http://www.jetbrains.com/idea/plugins/index.html">here</a>.</p>
<h2>Infer</h2>
<p>No you can call Analyze -&gt; Annotate Jar Files&#8230; (from either Main menu or context menu)  <img src="https://www.evernote.com/shard/s171/sh/8242aa4b-939b-416c-9880-6a6b97f748ce/add22424ad329409984c8f1df963bfde/res/902508da-cf33-453b-9790-c2af86cfa407/skitch.png" alt="" /></p>
<p>You get a dialog like this:</p>
<p><img class="aligncenter" src="https://www.evernote.com/shard/s171/sh/7a64fc28-2eef-4fa5-ab4d-9c76d1e5b743/a39de23030a194a1c353d88bf08c88cf/res/764fc590-59e4-424a-9d63-134b9d15fd9c/skitch.png" alt="" /></p>
<p>There you specify what JAR files you want analyzed and where to put the results, i.e. XML files containing annotations. By default, KAnnotator will attach the annotation to the libraries you call it on.</p>
<h2>Enjoy</h2>
<p>So, when you see Kotlin complaining about nullable types coming from Java, all you need to do is run KAnnotator once on that Java library, and it will turn your red code green.</p>
<p>If it does not, maybe KAnnotator is not smart enough, but maybe that method actually returns null?</p>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/X4eTBUDRfOc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/03/kannotator-0-1-is-out/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/03/kannotator-0-1-is-out/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=kannotator-0-1-is-out</feedburner:origLink></item>
		<item>
		<title>Kotlin Session and JetBrains Booth at 33rd Degree Conference</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/uaGKgsJHz-I/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/03/kotlin-session-and-jetbrains-booth-at-33rd-degree-conference/#comments</comments>
		<pubDate>Fri, 01 Mar 2013 09:09:58 +0000</pubDate>
		<dc:creator>Robert Demmer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[33rd degree]]></category>
		<category><![CDATA[poland]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=975</guid>
		<description><![CDATA[JetBrains and Kotlin are participating in the 33rd Degree Conference in Warsaw, Poland. Join 1,200 attendees March 13-15 for 92 sessions from 58 speakers. Come by our booth and learn what&#8217;s new in Project Kotlin, as well as the upcoming IntelliJ IDEA 12.1 release. &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/03/kotlin-session-and-jetbrains-booth-at-33rd-degree-conference/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>JetBrains and Kotlin are participating in the 33rd Degree Conference in <strong>Warsaw, Poland</strong>. Join 1,200 attendees <strong>March 13-15</strong> for <a title="33rd Degree Conference Sessions" href="http://2013.33degree.org/main/schedule" target="_blank">92 sessions</a> from <a title="33rd Degree Conference Speakers" href="http://2013.33degree.org/speaker/list" target="_blank">58 speakers</a>. Come by our booth and learn what&#8217;s new in <strong>Project Kotlin</strong>, as well as the upcoming <strong><a title="IntelliJ IDEA 12.1" href="http://blogs.jetbrains.com/idea/category/eap-releases/" target="_blank">IntelliJ IDEA 12.1 release</a></strong>. Be sure to mark your calendar for our <strong>two sessions</strong> with JetBrains Technical Evangelist <a title="Follow Hadi Hariri on Twitter" href="https://twitter.com/hhariri" target="_blank">Hadi Hariri</a>.</p>
<p><span id="more-975"></span></p>
<p><strong>Kotlin: Beyond Dogmatism </strong><br />
<em>Thursday, March 14th, 10:10 AM – 11:10 AM, Room D</em></p>
<p>Kotlin is a new language developed by JetBrains and licenses under Apache 2 OSS License, targeting the JVM and JavaScript. When presented, the typical questions asked are &#8220;Why another language? What core fundamentals does it bring to the table?” Tell you what, let&#8217;s move beyond dogmatism and be pragmatic. Let&#8217;s focus on the problems we&#8217;re trying to solve when developing applications and see why and how Kotlin can help us.</p>
<p><strong>Developers: Prima Donnas of the 21st Century </strong><br />
<em>Friday, March 15th from 13:10 &#8211; 14:10</em></p>
<p><img class="size-thumbnail wp-image-1572 alignleft" src="http://blog.jetbrains.com/wp-content/uploads/2013/01/Hadi-Hariri-150x150.png" alt="" width="150" height="150" />“We are developers. We are creators. We are misunderstood by customers, by managers and even co-workers; we are undervalued and often overworked. People don’t appreciate the value we put in our craft and our drive for innovation. We are central to business in the 21st century yet people don’t appreciate us!” Of course you are, but you also forgot to mention: You suck at communication. You often put business at risk based on personal ambitions and waste serious amounts of time trying to improve and discuss the wrong things, all in the name of the next great thing that’s going to solve it all. You’ve completely forgotten the plot! Don’t believe me? Why don’t you come along to this talk and get a wakeup call. But don’t expect to be treated nicely.</p>
<p>For full details on the event please visit <a title="33rd Degree Conference Website" href="http://2013.33degree.org/" target="_blank">33rd Degree Conference website</a>.</p>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/uaGKgsJHz-I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/03/kotlin-session-and-jetbrains-booth-at-33rd-degree-conference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/03/kotlin-session-and-jetbrains-booth-at-33rd-degree-conference/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=kotlin-session-and-jetbrains-booth-at-33rd-degree-conference</feedburner:origLink></item>
		<item>
		<title>Kotlin M5.1</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/eQB-Igdyofg/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/02/kotlin-m5-1/#comments</comments>
		<pubDate>Wed, 27 Feb 2013 11:03:59 +0000</pubDate>
		<dc:creator>Andrey Breslav</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=971</guid>
		<description><![CDATA[There have been enough little improvements since Kotlin M5 so that we are rolling them out as M5.1 today. Some of them are not so little in fact, like enabling the use of Scala libraries, such as Akka. This post &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/02/kotlin-m5-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There have been enough little improvements since <a title="Kotlin M5 is Out!" href="http://blog.jetbrains.com/kotlin/2013/02/kotlin-m5-is-out/">Kotlin M5</a> so that we are rolling them out as M5.1 today. Some of them are not so little in fact, like enabling the use of Scala libraries, such as <a href="http://akka.io/">Akka</a>. This post gives a quick overview of these changes.<span id="more-971"></span></p>
<h2>Better Support for Scala Classes. Akka</h2>
<p>Theoretically, it is very easy for all JVM languages to interoperate. In practice, there appear to be numerous little problems that make it unpleasant or practically impossible.</p>
<p>One of such problems was related to the ambiguous use of &#8220;$&#8221; signs in class names, which is a well-known issue on the JVM. It being fixed now, allows you to use some Akka classes you couldn&#8217;t use before, such as Duration.</p>
<p>To get an impression of what Akka looks like in Kotlin, have a look at <a href="https://gist.github.com/abreslav/5046126">this example</a>.</p>
<h2>Even More Helpful IDE</h2>
<p>With the help of students of Cornell and Jagiellonian universities, we got quite a few quick fixes implemented in M5.1. When the IDE complains about some error or warns you, you can simply press Alt+Enter and get a list of proposed fixes:</p>
<p><img class="aligncenter" src="https://www.evernote.com/shard/s171/sh/b504e729-ddda-42b5-b330-e08e9ef3986c/3d16d58b507733588c1037d60d1ed0dc/res/33c7d0fd-b2e0-482a-ad71-aef35d452fb2/skitch.png?resizeSmall&amp;width=832" alt="" /></p>
<h2>Parameters are Immutable</h2>
<p>We removed support for mutable parameters, as in</p>
<pre>fun foo(var x: Int) {
  x = 5
}</pre>
<p>The main reason is that this was confusing: people tend to think that this means passing a parameter by reference, which we do not support (it is costly at runtime). Another source of confusion is primary constructors: &#8220;val&#8221; or &#8220;var&#8221; in a constructor declaration means something different from the same thing if a function declarations (namely, it creates a property). Also, we all know that mutating parameters is no good style, so writing &#8220;val&#8221; or &#8220;var&#8221; infront of a parameter in a function, catch block of for-loop is no longer allowed.</p>
<p>If some of your existing code breaks, you can quick-fix the whole project in one click using the IDE:</p>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/JY-Vx8FjtIM?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<h2>Support for Java&#8217;s<strong> protected static </strong>methods</h2>
<p>Some Java frameworks, like Android, rely on protected static methods to be available in subclasses. Although this seems like a questionable pattern, Kotlin now supports it (only for Java compatibility), i.e. you can access a <strong>protected static </strong>member of a Java class if you extend this class in Kotlin.</p>
<h2>Anonymous Objects</h2>
<p>Consider the following code (that uses a Kotlin analog to anonymous inner class):</p>
<pre>val x = object : A() { ... }</pre>
<p>What is the type of x? It used to be the anonymous type, but if you use x from the outside, you can not access it: the type is not valid. Now the type will be A. This applies only to properties that can be seen from the outside, i.e. if x is a local variable it will still have the anonymous type, since it is harmless.</p>
<h2>Class Objects are Usable from Java</h2>
<p>Kotlin classes do not have static members, but rather have <em><a href="http://confluence.jetbrains.com/display/Kotlin/Classes+and+Inheritance#ClassesandInheritance-Classobjects">class objects</a></em>:</p>
<pre>class A {
    class object {
        val x = 1
    }
}</pre>
<p>Now, with a few bugs fixed, you can access members of class objects from your Java code:</p>
<pre>public static void main(String[] args) {
    System.out.println(A.object.instance$.getX());
}</pre>
<h2>Compiler</h2>
<p>The compiler is being improved too: a few fixes for corner cases of nullable types interacting with generics and optimizations for loops over ranges.</p>
<h2>Requirements</h2>
<p>Kotlin M5.1 requires <a href="http://www.jetbrains.com/idea/download/index.html">IntelliJ IDEA 12.0.4</a> (EAPs of 12.1 are not supported yet), you can download it from the plugin repository.</p>
<p><strong>Have a nice Kotlin!</strong></p>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/eQB-Igdyofg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/02/kotlin-m5-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/02/kotlin-m5-1/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=kotlin-m5-1</feedburner:origLink></item>
		<item>
		<title>“Surround with…” comes to Kotlin</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/Lzfb68Y9sKE/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/02/surround-with-comes-to-kotlin/#comments</comments>
		<pubDate>Tue, 26 Feb 2013 09:20:22 +0000</pubDate>
		<dc:creator>Natalia Ukhorskaya</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=868</guid>
		<description><![CDATA[Great news for fans of Intellij IDEA: &#8220;Surroud with&#8230;&#8221; action is now available for Kotlin! What is the &#8220;Surround with&#8230;&#8221; action? This action allows you to surround a block of code with if, try or other statements (see the full &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/02/surround-with-comes-to-kotlin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Great news for fans of Intellij IDEA: &#8220;Surroud with&#8230;&#8221; action is now available for Kotlin!</p>
<h2>What is the &#8220;Surround with&#8230;&#8221; action?</h2>
<p><strong></strong>This action allows you to surround a block of code with <em>if</em>, <em>try</em> or other statements (see <a href="#full_list">the full list</a> bellow). Simply select a block of code, press <em>Ctrl + Alt + T</em> and choose the template (<em>Cmd + Alt + T</em> for Mac):<span id="more-868"></span></p>
<p><img src="https://www.evernote.com/shard/s119/sh/30b15c39-ad04-4960-a4ac-63a0c44b7798/15300fa96a0fb6466f48c2abdd2f5f8b/deep/0/surroundwith1.jpg" alt="" /></p>
<p>The IDE will add the neccessary code and put the caret at the position that allows you to finish your refactoring:</p>
<p><img src="https://www.evernote.com/shard/s119/sh/7423c1e1-9464-4839-80a5-5c45e5cb981f/ee1a2a5c7f7ba1727f7cd59b3dde48dc/deep/0/surroundwith2.jpg" alt="" /></p>
<p>If the surrounded block contains variable declarations that are used after the block, they will be moved out of the block:</p>
<p><img src="https://www.evernote.com/shard/s119/sh/38c06e91-2f1d-4140-9feb-f444b8c73a83/8bf36356ade04ec4ac35fef45dda5187/deep/0/surroundwith3.jpg" alt="" /></p>
<p><img src="https://www.evernote.com/shard/s119/sh/07b88a70-2214-45e4-a83b-a798a3902e11/f973c8b777dc6854aefc7c63bd081266/deep/0/surroundwith4.jpg" alt="" /></p>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/Bwuj15P8yOQ?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<h2>Function Literal Template</h2>
<p>You can surround a block of code like this:</p>
<p><img src="https://www.evernote.com/shard/s119/sh/c6ee3d36-5c3e-4b8c-976d-b9761c190390/af84ab8fcf8d47df3d7a77eff5244452/deep/0/surroundwith5.jpg" alt="" /></p>
<p>Use this template if you want to &#8220;hide&#8221; some variables in the scope of the block, to create a property with function type or a local function and if you want to call any function with function literal as an argument.</p>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/ufSDvAxo544?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<h2>When template</h2>
<p>You don&#8217;t need to write <em>when </em>expression by hand any more: you can simply select a subject expression, choose &#8220;surround with <em>when(expr) {}</em>&#8221; and the result will be:</p>
<p><img src="https://www.evernote.com/shard/s119/sh/08db9fde-304e-4226-a261-0a8d6724ebc1/7d45417b3110edfb4091e8dcc03b97c9/deep/0/surroundwith6.jpg" alt="" /></p>
<h2><a name="full_list">Full list</a> of  &#8220;Surround with&#8230;&#8221; templates</h2>
<p>When a block of code is selected:</p>
<ul>
<li>if</li>
<li>if / else</li>
<li>{ }                       &#8211; function literal</li>
<li>try</li>
<li>try / catch</li>
<li>try / catch / finally</li>
</ul>
<p>When an expression is selected:</p>
<ul>
<li>!(expr)                &#8211; add negation for Boolean</li>
<li>(expr)                 &#8211; surround with parentheses</li>
<li>&#8220;${expr}&#8221;           &#8211; surround with quotes</li>
<li>when(expr) {}</li>
</ul>
<h2>Kotlin M5.1</h2>
<p>We release &#8220;Surround with&#8230;&#8221; as a part of Kotlin M5.1 that will be out very soon.</p>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/Lzfb68Y9sKE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/02/surround-with-comes-to-kotlin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/02/surround-with-comes-to-kotlin/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=surround-with-comes-to-kotlin</feedburner:origLink></item>
		<item>
		<title>Ranges Reloaded</title>
		<link>http://feedproxy.google.com/~r/kotlin/~3/IxgKI_PvptE/</link>
		<comments>http://blog.jetbrains.com/kotlin/2013/02/ranges-reloaded/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 14:47:53 +0000</pubDate>
		<dc:creator>Evgeny Gerashchenko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jetbrains.com/kotlin/?p=855</guid>
		<description><![CDATA[In Kotlin M5 we have redesigned our ranges a little bit. Range expressions are formed with rangeTo functions that have the operator form of .. which are complemented by in and !in. Range is defined for any comparable type (subclass of Comparable), but for number &#8230; <a href="http://blog.jetbrains.com/kotlin/2013/02/ranges-reloaded/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://blog.jetbrains.com/kotlin/2013/02/kotlin-m5-is-out/">Kotlin M5</a> we have redesigned our ranges a little bit.<span id="more-855"></span></p>
<p>Range expressions are formed with <tt>rangeTo</tt> functions that have the <a href="http://confluence.jetbrains.com/display/Kotlin/Operator+overloading#Operatoroverloading-Binaryoperations">operator form of <tt>..</tt></a> which are complemented by <a href="http://confluence.jetbrains.com/display/Kotlin/Operator+overloading#Operatoroverloading-in"><strong>in</strong> and <strong>!in</strong></a>. Range is defined for any comparable type (subclass of <code>Comparable</code>), but for number primitives it is optimized. Here are examples of using ranges:</p>
<pre>if (i in 1..10) { // equivalent of 1 &lt;= i &amp;&amp; i &lt;= 10
  println(i)
} 

if (x !in 1.0..3.0) println(x) 

if (str in "island".."isle") println(str)
// equivalent of "island" &lt;= str &amp;&amp; str &lt;= "isle"</pre>
<p>Numerical ranges have extra feature: they can be iterated over. Compiler takes care about converting this in simple analogue of Java&#8217;s indexed for-loop, without extra overhead. Examples:</p>
<pre>for (i in 1..4) print(i) // prints "1234"  

for (i in 4..1) print(i) // prints nothing 

for (x in 1.0..2.0) print("$x ") // prints "1.0 2.0 "</pre>
<p>What if you want to iterate over numbers in reversed order? It&#8217;s simple. You can use <tt>downTo()</tt> function defined in standard library:</p>
<pre>for (i in 4 downTo 1) print(i) // prints "4321"</pre>
<p>Is it possible to iterate over numbers with arbitrary step, not equal to 1? Sure, <tt>step()</tt> function will help you:</p>
<pre>for (i in 1..4 step 2) print(i) // prints "13"  

for (i in 4 downTo 1 step 2) print(i) // prints "42"  

for (i in 1.0..2.0 step 0.3) print("$x ") // prints "1.0 1.3 1.6 1.9 "</pre>
<h2><a name="howitworks"></a>How it works</h2>
<p>There are two traits in the library: <tt>Range&lt;T&gt;</tt> and <tt>Progression&lt;N&gt;</tt>.</p>
<p><tt>Range&lt;T&gt;</tt> denotes an interval in the mathematical sense, defined for comparable types. It has two endpoints: <tt>start</tt> and <tt>end</tt>, which are included in the range. Main operation is <tt>contains()</tt>, usually used in the form of <tt>in</tt>/<tt>!in</tt> operators.</p>
<p><tt>Progression&lt;N&gt;</tt> denotes <a rel="nofollow" href="http://en.wikipedia.org/wiki/Arithmetic_progression">arithmetic progression</a>, defined for number types. It has <tt>start</tt>, <tt>end</tt> and non-zero <tt>increment</tt>. <tt>Progression&lt;N&gt;</tt> is a subtype of <tt>Iterable&lt;N&gt;</tt>, so it can be used in for-loops and functions like <tt>map</tt>, <tt>filter</tt>, etc. First element is <tt>start</tt>, every next element equals previous plus <tt>increment</tt>. Iteration over <tt>Progression</tt> is equivalent to an indexed for-loop in Java/JavaScript:</p>
<pre>// if increment &gt; 0
for (int i = start; i &lt;= end; i += increment) {
  // ...
}

// if increment &lt; 0
for (int i = start; i &gt;= end; i += increment) {
  // ...
}</pre>
<p>For numbers, the &#8220;<tt>..</tt>&#8221; operator creates an object which is both <tt>Range</tt> and <tt>Progression</tt>. Result of <tt>downTo()</tt> and <tt>step()</tt> functions is always a <tt>Progression</tt>.</p>
<img src="http://feeds.feedburner.com/~r/kotlin/~4/IxgKI_PvptE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.jetbrains.com/kotlin/2013/02/ranges-reloaded/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://blog.jetbrains.com/kotlin/2013/02/ranges-reloaded/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=ranges-reloaded</feedburner:origLink></item>
	</channel>
</rss>
