main(){
  print('Hello, dart!'); // function을 사용하는 것
  myPrint('Hello, dart!'); // function을 만들어서 사용하는 것
  myPrint('sdsdsdhsjkd');
}
// main() : function, method
// function의 이름이 main
// main의 parameter로 중괄호 안의 body로 전달
// 시작점이 main() function
// Dart_LoadScriptFromKernel: The binary program does not contain 'main'.

myPrint(String txt){ // function을 만드는 것
  print(txt);
}
// A function declaration
int timesTwo(int x){ // 반환값
  return x*2; // 리턴값
}

// Arrow syntax is shorthand for '{ return expr; }'.
// 위의 함수는 아래 축약 함수와 똑같다.
// int timesTwo(int x) => x*2;

int timesFour(int x) => timesTwo(timesTwo(x));
// int timesFour(int x){
//   return timesTwo(timesTwo(x));
// }

// Functions are object
// function 자체를 객체로 쓸 수 있다.
int runTwice(int x, Function f){ // int와 function을 받아온다.
  for(var i = 0; i<2; i++){
    x=f(x);
  }
  return x;
}

main(){
  int num =16;
  print("4 times two is ${timesTwo(4)}"); // function 사용법
  print("4 times four is ${timesFour(4)}"); // function 사용법
  print("4 times four is $num"); // function 사용법
  print("2 x 2 x 2 is ${runTwice(2, timesTwo)}"); // 파라미터 없이 던져줌 function name만
  // "" 스트링 리터럴 안에 값을 출력할 때는, ${}안에 해야한다.
  // 간단한 변수면 $var 로 해도된다.
}

함수를 일반적인 방법으로 timesTwo()처럼 정의할 수 있다.

만약 함수의 body가 1줄이라면 =>으로 축약하여 정의할 수 있다.

timesTwo()함수는 int timesTwo(int x) ⇒ x*2; 이렇게 축약하여 정의할 수 있다.

Dart에서 모든 function은 객체로 본다. 그래서 function을 파라미터로 전달하는 것도 가능하다.

"" String 리터럴 안에 값을 출력하고 싶을 때는, ${} 을 쓰면 된다. 만약 변수하나를 출력한다면, $ 만 붙여주면 된다.