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
reduce :: (a -> b -> b) -> b -> [a] -> b | |
reduce f b [] = b | |
reduce f b (x:xs) = f x (reduce f b xs) | |
map :: (a -> b) -> [a] -> [b] | |
map f = reduce (\a b -> (f a) : b) [] |
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
/////////////////// | |
/// PARSER CORE /// | |
/////////////////// | |
// There is an annotated configuration object in the GRAMMAR section below | |
function Parser(config) { | |
var prio = this.priorities = config.priorities; | |
prio["boundary:$"] = [-1, -1]; | |
this.re = config.re; | |
this.toktypes = config.toktypes; |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
// We demonstrate three ways of labeling a binary tree with unique | |
// integer node numbers: (1) by hand, (2) non-monadically, but | |
// functionally, by threading an updating counter state variable | |
// through function arguments, and (3) monadically, by using a | |
// partially generalized state-monad implementation to handle the |
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
package sum.odd | |
object Main { | |
def f(arr: List[Int]): Int = arr.map(x => (if (0 == x % 2) 0 else x)).reduce((x, y) => x + y) | |
def main(args: Array[String]) { | |
val r = f(List(2, 3, 4, 5, -7)); | |
println(r); | |
} | |
} |
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
package filter.array | |
object Main { | |
def filter[T](arr: List[T], cond: T => Boolean): List[T] = arr match { | |
case x :: xs => if (cond(x)) x :: filter(xs, cond) else filter(xs, cond) | |
case _ => List[T]() | |
} | |
def f(delim: Int,arr: List[Int]): List[Int] = filter(arr, (x: Int) => x < delim) | |
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
package list.replication | |
object Main { | |
def repeat[T](num: Int, e: T): List[T] = if (num <= 0) List[T]() else e :: repeat(num - 1, e); | |
def f(num: Int, arr: List[Int]): List[Int] = arr.flatMap(e => repeat(num, e)); | |
def main(args: Array[String]) { | |
val lst1 = f(4, List(1, 2, 3)); | |
lst1.map(e => println(e)) |
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
package list.length | |
object Main { | |
def f(arr: List[Int]): Int = arr match { | |
case x :: xs => 1 + f(xs) | |
case _ => 0 | |
} | |
def main(args: Array[String]) { | |
val len = f(List(1, 2, 3)); |
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
#!/usr/bin/env perl | |
use File::Basename | |
$nargs = @ARGV; | |
sub usage() { | |
my $prog = basename($0); | |
print "Usage: $prog <start-text> <end-text>\n"; | |
} |
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 Boolean { | |
def == (other: Boolean): Boolean; | |
def != (other: Boolean): Boolean; | |
def && (other: Boolean): Boolean; | |
def || (other: Boolean): Boolean; | |
def unary_! (): Boolean; | |
} | |
object True extends Boolean { | |
def == (other: Boolean) = other; |
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
# Bash command aliases and utils | |
# code format | |
function astyle-java { | |
astyle --mode=java --style=linux -s4 $@ | |
} | |
function astyle-c { | |
astyle --mode=c --style=linux -s4 $@ | |
} |