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
nnoremap <A-Right> :vertical res +1<cr> | |
nnoremap <A-Left> :vertical res -1<cr> | |
nnoremap <A-Up> :res +1<cr> | |
nnoremap <A-Down> :res -1<cr> |
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 main | |
import "fmt" | |
// fibonacci is a function that returns | |
// a function that returns an int. | |
func fibonacci() func() int { | |
last := 0 | |
cur := 1 | |
count := 0 |
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
nnoremap <leader><Right> :vertical res +5<cr> | |
nnoremap <leader><Left> :vertical res -5<cr> | |
nnoremap <leader><Up> :res +5<cr> | |
nnoremap <leader><Down> :res -5<cr> |
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
/* 8*7 */ | |
val input1: {l:Int, op:[Plus:Unit, Minus:Unit, Times:Unit, Eq:Unit, Lt:Unit, Gt:Unit, Not:Unit, And:Unit, Or:Unit], r:Int} = | |
{l:8, op:inj[Plus:Unit, Minus:Unit, Times:Unit, Eq:Unit, Lt:Unit, Gt:Unit, Not:Unit, And:Unit, Or:Unit](Times:()), r:-7} | |
in | |
/* 0>10 */ | |
val input2: {l:Int, op:[Plus:Unit, Minus:Unit, Times:Unit, Eq:Unit, Lt:Unit, Gt:Unit, Not:Unit, And:Unit, Or:Unit], r:Int} = | |
{l:0, op:inj[Plus:Unit, Minus:Unit, Times:Unit, Eq:Unit, Lt:Unit, Gt:Unit, Not:Unit, And:Unit, Or:Unit](Gt:()), r:10} | |
in | |
/* 10+10 */ | |
val input3: {l:Int, op:[Plus:Unit, Minus:Unit, Times:Unit, Eq:Unit, Lt:Unit, Gt:Unit, Not:Unit, And:Unit, Or:Unit], r:Int} = |
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
def testInferType(inferType: (TypEnv, Expr) => Typ): Boolean = { | |
def tester( test: (Expr, Typ) ) = { | |
val (sourceExpr, expectRes) = test | |
val res = inferType(typenvEmpty,sourceExpr) == expectRes | |
if (res == false) { | |
println("Failed: " + test) | |
println("Result: " + inferType(typenvEmpty,sourceExpr)) | |
} | |
res | |
} |
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
def substr(sub, match): | |
'''Returns True if `sub` is a substring of `match`. | |
Example: substr("abc", "abababc") # True | |
''' | |
def sub_helper(sub, match, fc): | |
# Base case: empty string is always a substring | |
if len(sub) == 0: | |
return True | |
# Reached end of `match`, but haven't matched all of sub. | |
# Call failure continuation. |
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
def rev_words(s): | |
'''Returns the string `s` with its words in the reverse order. | |
Example: rev_words("Reverse this!") #"this! Reverse" | |
''' | |
def helper(s, word_acc, str_acc): | |
# Base case: Return `word_acc` plus whatever words | |
# you have in the string acc. | |
if len(s) == 0: | |
return word_acc + str_acc | |
# This is the end of a word. Clear `word_acc`, and start with |
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 gc | |
import inspect | |
gc.disable() | |
test_counter = 0 | |
def print_test_msg(message): | |
global test_counter | |
test_counter += 1 | |
print "%d. %s Line: %d" % (test_counter, message, inspect.currentframe().f_back.f_lineno) |
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
# Print each permutation. | |
def perm(l, n, str_a): | |
if len(str_a) == n: | |
print str_a | |
else: | |
for c in l: | |
perm(l, n, str_a+c) | |
# Return a list of permutations. | |
def perm2(l, n, str_a, perm_a): |
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
// Some Scala implementations of concepts from "Natural Language Processing For The Working Programmer" | |
// http://nlpwp.org/book/chap-ngrams.xhtml | |
/** | |
* Return all lists of n adjacent words. | |
* ngram("I love Scala!", 2) = List(List(I, love), List(love, Scala!) | |
*/ | |
def ngram(sent:String, n:Int):List[List[String]]={ | |
def helper(sent:List[String]):List[List[String]] = { | |
sent match{ |
OlderNewer