Skip to content

Instantly share code, notes, and snippets.

View davidkellis's full-sized avatar

David Ellis davidkellis

View GitHub Profile
@davidkellis
davidkellis / gist:e1b9b5e6e406a47dfc0744114b6a77ca
Last active September 2, 2017 04:21
interfaces extreme 1
interface Enumerable T for E {
fn each(E, T -> Unit) -> Unit
}
impl Enumerable T for Array T {
fn each(array: Array T, f: T -> Unit) -> Unit { ... }
}
impl Enumerable T for I : Iterator T {
fn each(it: I, visit: T -> Unit) = ...
}
impl Enumerable T for Iterator T {
interface Enumerable T for E {
fn each(E, T -> Unit) -> Unit
}
impl Enumerable T for Array T {
fn each(array: Array T, f: T -> Unit) -> Unit { ... }
}
impl Enumerable T for I : Iterator T {
fn each(it: I, visit: T -> Unit) = ...
}
impl Enumerable T for Iterator T {
fn slowAdd(x: Int, y: Int) -> Int {
sleep(2.seconds)
x + y
}
// main1 takes 4 seconds to run
fn main1() {
a = slowAdd(1, 2)
b = slowAdd(10, 20)
puts(a + b)
package truthy
interface Truthy for T {
fn truthy?(T) -> Boolean
}
def ||[A: Truthy, B: Truthy](a: A, b: B): A | B => truthy?(a) ? a : b
def &&[A: Truthy, B: Truthy](a: A, b: B): A | B => truthy?(a) ? a : b
def !(a: Truthy): Boolean => !a.truthy?
0 * 0 = 0 5 * 0 = 0
0 * 1 = 0 5 * 1 = 5
0 * 2 = 0 5 * 2 = 10
0 * 3 = 0 5 * 3 = 15
0 * 4 = 0 5 * 4 = 20
0 * 5 = 0 5 * 5 = 25
0 * 6 = 0 5 * 6 = 30
0 * 7 = 0 5 * 7 = 35
0 * 8 = 0 5 * 8 = 40
0 * 9 = 0 5 * 9 = 45
C# program:
using System;
using System.Threading.Tasks;
namespace Scratch
{
class Program
{
static void Main()
davidellis@davidellis:~/Dropbox/projects/benchmarks (master) $ ./run.rb
Running base64 benchmark suite
base64/crystal0.25.0
base64/ruby2.5.1
Running helloworld benchmark suite
helloworld/crystal0.25.0
helloworld/ruby2.5.1
Running json benchmark suite
name: "confefe"
version: "1.2.0"
tags:
- "foo"
- "bar"
- "baz"
authors: ["Bill", "Bob"]
dependencies: [ # dependencies captured in a nested array
["stdlib", "~> 1.2"],
server:
address: "localhost:6667"
channel: "#hello"
greetings:
- passthru: true
filter: "boss"
message: "Hi, boss!"
- passthru: false
filter: ".*"

confefe

confefe, pronounced con-feef, is a simple configuration language

confefe supports 8 different data types, plus comments:

  • nil/null
  • bool
  • int
  • decimal
  • string