好消息:Phobos 进 dsource 啦!
oldrev
2007-11-26
看来 Walter 决定完全采用开放的方式开发 Phobos 了,有了整个社区的支持, Phobos 应该会进步很快。
|
|
oldrev
2007-11-26
Phobos 里的单链表: http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/slist.d 好像数据结构/算法方面就这一个,有点莫名奇妙 |
|
oldrev
2007-11-26
117 /** 118 * Returns the first element in the list. Precondition: $(D_PARAM 119 * !isEmpty(lst)). 120 */ 121 Ref!(T) front(T)(ref SList!(T) lst) 122 in 123 { 124 enforce(lst.root, "Attempting to fetch the front of an empty list"); 125 } 126 body 127 { 128 return lst.root.value; 129 } 130 莫非2.x 已经有外部方法啦? |
|
Colorful
2007-11-26
tango是不是有点危险了?
|
|
qiezi
2007-11-26
oldrev 写道 117 /** 118 * Returns the first element in the list. Precondition: $(D_PARAM 119 * !isEmpty(lst)). 120 */ 121 Ref!(T) front(T)(ref SList!(T) lst) 122 in 123 { 124 enforce(lst.root, "Attempting to fetch the front of an empty list"); 125 } 126 body 127 { 128 return lst.root.value; 129 } 130 莫非2.x 已经有外部方法啦? 这个还不能证明吧 |
|
oldrev
2007-11-27
又看见一个东西:
http://www.dsource.org/projects/phobos/browser/candidate/phobos/std/algorithm.d 里面有个搞笑的 sort 算法: 329 /** 330 Sorts a random-access range according to predicate $(D_PARAM comp), 331 expressed as a string. The string can use the names "a" and "b" for 332 the two elements being compared. 333 334 Example: 335 336 ---- 337 int[] array = ([ 1, 2, 3, 4 ]).dup; 338 sort!("a > b")(array); 339 assert(array == [ 4, 3, 2, 1 ]); 340 ---- 341 */ 342 343 template sort(string comp) 344 { 345 void sort(Range)(Range r) 346 { 347 alias typeof(*begin(r)) ElementType; 348 static ElementType a, b; 349 alias typeof(mixin(comp)) ResultType; 350 static ResultType compFn(ElementType a, ElementType b) 351 { 352 return mixin(comp); 353 } 354 .sort!(compFn)(r); 355 } 356 } 如此仿造 lambda,呵呵 |
|
qiezi
2007-11-27
还是要有AST macro才好看啊..
|
|
oldrev
2007-11-28
其实现在就可以在 D 里使用 C宏,反正D的语法跟C宏并不冲突,只不过编译的时候多产生一个临时文件罢了
|