Skip to content

Instantly share code, notes, and snippets.

@liuhuajin
liuhuajin / closure.py
Created August 2, 2015 06:43
一个经典的闭包示例
def too_big(limit):
def compare(x):
return x > limit
return compare
f = too_big(100)
print f(100)
print f(101)
import java.util.*;
//环境类:用于存储和操作需要解释的语句,在本实例中每一个需要解释的单词可以称为一个动作标记(Action Token)或命令
class Context {
private StringTokenizer tokenizer; //StringTokenizer类,用于将字符串分解为更小的字符串标记(Token),默认情况下以空格作为分隔符
private String currentToken; //当前字符串标记
public Context(String text) {
tokenizer = new StringTokenizer(text); //通过传入的指令字符串创建StringTokenizer对象
nextToken();
@liuhuajin
liuhuajin / metatable.lua
Created July 8, 2014 02:40
metatable 操作 lua 13.1
Set = {}
function Set.new(t)
local set = {}
setmetatable(set, Set.mt)
for _, l in ipairs(t) do set[l] = true end
return set
end
function Set.union(a, b)
@liuhuajin
liuhuajin / testpro
Created July 7, 2014 06:43
lua leaning
--defines a factorial function
function fact(n)
if n == 0 then
return 1
else
return n*fact(n-1)
end
end
@liuhuajin
liuhuajin / first_test.cpp
Created July 7, 2014 03:36
my first test for gist
#include<iostream>
using namespace std;
int main()
{
cout << "this is the first use of gist." << endl;
}