2016년 11월 9일 수요일

[C#] Currying

method ( par1, par2, par3) => return result



Currymethod(par1, curmethod2(par2 , method3(par3))) => return result

이렇게 input 파라미터를 1개만 받도록 나누는 것이다.

이러면 각각의 함수 method1,method2,method3 의 재사용이 가능해진다.

[c#] Closure Example2

static void Closures( ) {
Console.WriteLine(GetClosureFunction( )(30));
}

static Func GetClosureFunction( ) {
  int val = 10;
  Func internalAdd = x = > x + val;
    return internalAdd;
}


-------------

Console.WriteLine(GetClosureFunction( )(30)); 이부분을 보자.

GetClosureFunction( )(30)은

GetClosureFunction( )로 메소드는 끝이 나고,

Func internalAdd = x = > x + val; 을 리턴한다.

이때 이 internalAdd  는 메소드 안의 val 을 참조하기 때문에, 메소드가 끝났는데도, 이 메소드 안 val 가 살아 있는것이다.

Advantage of Closure

변수를 보호 할 수 있다.

즉, 클래스의 필드 멤버가 클래스의 함수에 쓰인다고 하자.

이 필드 멤버는 함수가 실행되기 전부터 초기화되고, 값이 지정된다.

그렇기 때문에, 중간에 이 값이 바뀌거나 했을경우 추적하기가 힘들어 진다.

즉, 디버깅이 복잡해 지게 된다.

어디서 이 필드멤버가 바뀌었는지 등등 고려해야될게 많아 진단 말이다.

따라서, 함수가 실행되고, 이 함수가 완전히 끝날떄까지만 지속되는 변수라면,

디버깅시, 이 함수에서 쓰이는 어던 수 (아까 예의 필드 멤버)는 함수 안에 로컬 변수로 있기 때문에, 디버깅이 매우 쉬워 진다.

이 테크닉을 클로저 라고 한다.

[C#] Closer Example

List list = new List();
            for ( int i = 0 ; i < 10 ; i++ )
            {
                list.Add( () => Console.WriteLine( i ) );
            }

list.ForEach(p=> p());


2016년 11월 7일 월요일

[Git] Basic step2

add file or edit file and..


1. git status : show what is changed in your repository

2. git add filename

3. git commit -m "message"

3. git push


[Git] Git basic - step1

1. install git

2.run gitbash

3. write down these

=> git config --global user.name ""


=> git config --global user.email ""

2016년 10월 17일 월요일

python list[:-1] mean

http://stackoverflow.com/questions/509211/explain-pythons-slice-notation