[Learn Note]2012-01-29

 

1 Emacs Lisp Date Time Formats

Elisp provides a very convenient function format-time-string for printing data time. For example, you can write a command to print date in the yyyy-mm-dd format using (insert (format-time-string "%Y-%m-%d")). Here's the full code:

(defun insert-date ()
  "Insert current date yyyy-mm-dd."
  (interactive)
  (when (region-active-p)
    (delete-region (region-beginning) (region-end) )
    )
  (insert (format-time-string "%Y-%m-%d"))
  )

2 C#与闭包

闭包其实就是使用的变量已经脱离其作用域,却由于和作用域存在上下文关系,从而可以在当前环境中继续使用其上文环境中所定义的一种函数对象.

public class TCloser
    {
        public Func<int> T1()
        {
            var n = 999;
            return () =>
            {
                Console.WriteLine(n);
                return n;
            };
        }
    }
    
    class Program{
        static void Main(){
            var a =new TCloser();
            var b = a.T1();
            Console.WriteLine(b());
        }
    }

从上面的代码我们不难看到,变量n实际上是属于函数T1的局部变量,它本来生命周期应该是伴随着函数T1的调用结束而被释放掉的,但这里我们却在返回的委托b中仍然能调用它,这里正是闭包所展示出来的威力,因为T1调用返回的匿名委托的代码片段中我们用到了n,而在编译器看来,这些都是合法的,因为返回的委托b和函数T1存在上下文关系,也就是说匿名委托b是允许使用它所在的函数或者类里面的局部变量的,于是编译器通过一系列动作(具体动作我们后面再说)使b中调用的函数T1的局部变量自动闭合,从而使该局部变量满足新的作用范围。

因此如果你看到.net中的闭包,你就可以像js中那样理解它,由于返回的匿名函数对象是在函数T1中生成的,因此相当于它是属于T1的一个属性。如果你把T1的对象级别往上提升一个层次就很好理解了,这里就相当于T1是一个类,而返回的匿名对象则是T1的一个属性,对属性而言,它可以调用它所寄存的对象T1的任何其他属性或者方法,包括T1 寄存的对象TCloser内部的其他属性。如果这个匿名函数会被返回给其他对象调用,那么编译器会自动将匿名函数所用到的方法T1中的局部变量的生命周转期自动提升并与匿名函数的生命周期相同,这样就称之为闭合。

详见原文处IL代码。

3 Bootstrapping

http://en.wikipedia.org/wiki/Bootstrapping

a self-sustaining process that proceeds without external help.

引导程序,辅助程序.

4 emacs searching

  • Increament searching
    C-S C-Shift-W
  • Searching Using TAGS
    • Using ETAGS to creat the etags files
    • Using M-. to search for a definition
    • Using visit-tags-table to refresh the TAGs file
    • sams-cm-rotate and sams-cm-save-point
  • grep-find
    • How to setup grep within the windows
      Copy grep.exe and find.exe from git to the bin directionary of the emacs Add the bin of the emacs to the path like below: set path=<path of bin>;%path%

Author: Jalen Wang <[email protected]>

Date: 2012-01-30 21:44:46

HTML generated by org-mode 6.33x in emacs 23

转载于:https://www.cnblogs.com/jalenwang/archive/2012/01/30/2332444.html

猜你喜欢

转载自blog.csdn.net/weixin_34240657/article/details/93512522