生成器和普通函数有些区别,比如生成器不用return返回,而用yield来返回一系列元素
除非“召唤”生成器的next(),否则函数体里面不会执行任何代码块,上下文环境保存着。
虽然不需要明确定义__iter__()和next()方法,但是它本身包含这个方法。
当想要结束一个协程时,使用close()方法即可,close会在协程中引发GeneratorExit异常,这时候可以通过try/ex...
分类:
编程语言 时间:
2014-05-10 09:53:34
阅读次数:
317
1. 函数可以返回多个值 return a, b, c; 但是如果函数不是作为表达式的最后一个元素的话,仅返回第一个
如:
function f2() return "a", "b" end;
x, y = f2() -> x = "a", y = "b";
x, y = f2(), 1 -> x = "a", y = nil;
2. 可以将一个函数调用放入一对圆括...
分类:
其他好文 时间:
2014-05-10 09:21:56
阅读次数:
317
一个简单的迭代器示例
--迭代工厂函数
function value(t)
local i = 0;
return
function()
i = i+1;
return t[i];
end;
end;
t = {10,20,30};
iter = va...
分类:
其他好文 时间:
2014-05-10 08:36:53
阅读次数:
268
优先级操作符描述例子结合性1()[]->.::++--调节优先级的括号操作符数组下标访问操作符通过指向对象的指针访问成员的操作符通过对象本身访问成员的操作符作用域操作符后置自增操作符后置自减操作符(a
+ b) / 4;array[4] = 2;ptr->age = 34;obj.age = 34;...
分类:
编程语言 时间:
2014-05-07 09:45:56
阅读次数:
396
Action代码: public function index(){
$prod = I("get.prod_en");
$id = I("get.id", 0, "int");
if ($prod == ""){
$serviceProduct = array();//多重循环遍历的数组 //数据保存在两张表中,这里通过循环初始化$serviceProduct数组...
分类:
Web程序 时间:
2014-05-07 07:13:02
阅读次数:
440
function FactoryXMLHttpRequest() {
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
}else if(window.ActiveXObject) {
var msxmls = new Array(
'Msxml2.XM...
分类:
其他好文 时间:
2014-05-07 07:00:03
阅读次数:
382
#include
using namespace std;
//汉罗塔递归求解函数 从a移到c
void move(int m,char a,char c);
void hanoi(int n,char a,char b,char c)
{
if(1==n)
{
move(n,a,c);
return;
}
hanoi(n-1,a,c,b);
move(n,a,c);
hano...
分类:
其他好文 时间:
2014-05-07 03:24:14
阅读次数:
228
五一中间断了几天,开始继续。。。
1、
??
Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
Return a...
分类:
其他好文 时间:
2014-05-06 18:54:59
阅读次数:
386
【Question】
Given an array S of n integers, are there elements a, b, c in S such
that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
Note:
Elements in ...
分类:
其他好文 时间:
2014-05-06 14:57:29
阅读次数:
318
private ImageInfo CreateImageFile(string fileName)
{ if (!File.Exists(fileName)) return null; Image image =
Image.FromFile(fileName); MemoryStream ms....
分类:
Web程序 时间:
2014-05-06 10:01:43
阅读次数:
313