Skip to content

Instantly share code, notes, and snippets.

View abreslav's full-sized avatar

Andrey Breslav abreslav

View GitHub Profile
package ru.ifmo.rain.adsl;
import java.io.FileOutputStream
fun main(args: Array<String>) {
val generator = Generator(FileOutputStream("out.kt"), args[0], args[1])
generator.run()
}
@abreslav
abreslav / kotlin-2013-14.markdown
Last active December 26, 2015 20:39
Kotlin Project Theme(s) for Open Academy - 2013/14

The Kotlin Programming Language

Kotlin is a modern statically typed programming language targeting the Java and JavaScript platforms. It is conceived as a "modern language for industry", keeping a balance between flexibility and readability, expressiveness and safety.

Project Overview

A modern programming language is much more than a grammar. Principal susystems of Kotlin include

  • Compiler front-end
  • Lexer/Parser translates text into a syntax tree, reports syntax errors
@abreslav
abreslav / nlr.kt
Created October 10, 2013 11:24
Non-local returns in Kotlin
// Sometimes you are inside a lambda and want to return a value from some surrounding function (or surrounding lambda)
fun foo(): Any? {
return withNLR(default = 25) {
listOf(1, 2, 3).forEach {
if (it > 2) doReturn(it)
}
}
}
procedure permutations(var a: array[1..N] of Integer; pos: Integer);
begin
if pos >= N then begin
for i := 1 to N do
Write(a[i], ' ');
WriteLn;
end;
for i := 1 to N do begin
a[i] := i;
@abreslav
abreslav / Sample.java
Last active December 16, 2015 03:39
A question about getClass()
/*
* A question about Java (not Kotlin!), first asked by Alexander Udalov (@udalov).
*
* How many calls to getClass() does the code below make?
* Curiously enough, the answer is ONE (see the byte codes below).
*
* Now the questions is: why does javac emit the call to getClass()?
*/
class C {
/*
Play with this code at
[http://goo.gl/yPtkb](Kotlin Web Demo)
*/
fun Int.divides(d: Int) = this % d == 0
fun fizzbuzz(n: Int) = when {
n divides 15 -> "fizzbuzz"
n divides 3 -> "fizz"
n divides 5 -> "buzz"
else -> "$n"
}
fun result(max: Int) = (0..max) map { n -> fizzbuzz(n) }
package sample.hello
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.UntypedActor
import akka.actor.UntypedActorContext
import akka.actor.ActorPath
import scala.concurrent.duration.Duration
import java.util.HashMap
import akka.actor.ActorSystem
@abreslav
abreslav / kotlin-2012-13.markdown
Last active July 28, 2023 10:55
Kotlin Project Theme(s) - 2012/13

The Kotlin Programming Language

Kotlin is a modern statically typed programming language targeting for the Java and JavaScript platforms. We aim at creating what we call "a modern language for industry", keeping a balance between flexibility and readability, expressiveness and safety. Kotlin is under development, and we are rapidly approaching a Beta stage.

Project Overview

A modern programming language is much more than a grammar. Principal susystems of Kotlin include

  • Compiler front-end
  • Lexer/Parser translates text into a syntax tree, reports syntax errors
fun main(args: Array<String>) {
val array = Class.forName("java.util.Collection")?.getInterfaces()!!
for (c in array) {
println(c)
c!!.accept(ClassVisitor())
}
}
class ClassVisitor