This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We introduce two new keywords: | |
// suspend - Creates "suspended" functions, which will make your asynchronous code "synchronous" while keeping your UI responsive | |
// next - A "return" keyword for suspended functions | |
// Exhibit A: sleep function, no return value | |
external setTimeout; | |
suspend void sleep(int ms) { // use the 'suspend' modifier | |
setTimeout(void() { | |
next; // we do not return a value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Node {} | |
abstract class Statement : Node {} | |
abstract class Expression : Node {} | |
class Program : Node | |
{ | |
Statement[] body; | |
Program() { | |
this.body = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./node_modules/typescript/bin/tsc --version | |
Version 3.2.2 | |
$ cat test.ts | |
const xs: number[] = [1,2,3]; | |
let x:number = xs[100] // number, even with strictNullChecks | |
console.log(x); | |
$ time ./node_modules/typescript/bin/tsc --strictNullChecks test.ts | |
real 0m1.084s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System; | |
class Employee : IComparable<Employee> | |
{ | |
private string firstName; | |
private string lastName; | |
public Employee(string firstName, string lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ECMAScript regex | |
std::regex re_param(R"((\S+)\s+([\s\S]+))"); | |
// vs. | |
// PCRE | |
pcrecpp::RE re_param( | |
"(?# Match the annotation name)(\\S+)" | |
"(?# Skip over whitespace)\\s+" | |
"(?# Match the annotation description text)([\\s\\S]+)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bitset> | |
#include <cassert> | |
#include <cstdint> | |
int main() { | |
const uint64_t a = 3, b = 5; | |
const size_t diff = a ^ b; | |
std::bitset<64> diff_bits(diff); | |
assert(diff_bits.count() == 2); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System; | |
external Uint8Array; | |
class ByteArray | |
{ | |
var stack; | |
ByteArray(int size) { | |
this.stack = new Uint8Array(size); |