Shakespeare Programming Language

FrontPage|FindPage|TitleIndex|RecentChanges| UserPreferences P RSS
소스 코드를 보다 보면 가끔 아름다움을 느낄 수 있는 경우가 있는데(파스칼로 만들어진 재귀적 계승 함수 등 Why Pascal, or modula family, of all languages? Could you show us with the code how it's beautiful? ), 아예 프로그램 소스 코드 자체가 문학 작품이 되게 하자는 생각으로 설계된 언어가 셰익스피어 프로그래밍 언어이다.

프로젝트 홈페이지: http://shakespearelang.sourceforge.net/

흔히 다른 프로그램 안에서 해석되는 프로그램을 스크립트라고 한다는 점에서도 흥미로운 언어이다 - 이 언어로 만들어진 프로그램은 그 자체가 스크립트인 셈이다.

다음은 피보나치 수열을 구하는 스크립트. 극도로 비효율적이지만 재미는 있다.

                         The Fibonacci drama.

 Hamlet, a beacon of truth in a world of dark confusion.
 Juliet, a poor girl starting at the bottom and working her way up.
 Romeo, a messenger between Hamlet and Juliet.
 Ophelia, a fine woman bringing our heroes to new levels.
 Macbeth, a poor insulted lady making but a small appearance.

                    Act I: The search for Fibonacci.

                    Scene I: The taunting of Macbeth.

 [Enter Hamlet and Macbeth]

 Macbeth:
  Thou art nothing. Open your heart!

 Hamlet:
  Thou art as rotten as a disgusting dusty evil fat-kidneyed fatherless foul
  hairy horrible infected lying pig.

 Macbeth:
  Thou art as vile as the difference between nothing and the sum of a
  snotty stinking half-witted hog and a small toad!
  Speak your mind!

 Hamlet:
  Thou art as half-witted as the cube of the difference between nothing and yourself.

 [Exit Macbeth]

 [Enter Ophelia]

 Hamlet:
  Thou art as noble as myself!

 [Exit Ophelia]

 [Enter Romeo]

 Hamlet:
  Thou art a hero! Open your heart.

 Romeo:
  Speak your mind.

                    Scene II: Tension is building.

 Romeo:
  Thou art as villainous as the sum of myself and Juliet.

  Is Macbeth worse than you? If so, we must proceed to Scene V.

  Open your heart!

 [Exit Hamlet]

                    Scene III: New levels of courage.

 [Enter Ophelia]

 Romeo:
  Speak your mind!

 [Exeunt]

                    Scene IV: Juliet has second thoughts.

 [Enter Juliet and Hamlet]

 Hamlet:
  Thou art as fine as Romeo!

 [Exit Hamlet]

 [Enter Romeo]

 Juliet:
  Thou art as cunning as Hamlet.

 [Exit Juliet]

 [Enter Hamlet]
 Hamlet:
  Let us return to scene II.

                    Scene V: Fin.
 [Exeunt]

다음은 PuzzletChung의 해석이 달린 스크립트.

                         The Fibonacci drama.

 Hamlet, a beacon of truth in a world of dark confusion.
 Juliet, a poor girl starting at the bottom and working her way up.
 Romeo, a messenger between Hamlet and Juliet.
 Ophelia, a fine woman bringing our heroes to new levels.
 Macbeth, a poor insulted lady making but a small appearance.

                    Act I: The search for Fibonacci.

                    Scene I: The taunting of Macbeth. (1막 1장: Macbeth의 비웃음)

 [Enter Hamlet and Macbeth]

 Macbeth:
  Thou art nothing. Open your heart!
  ("Thou art nothing." = "You are nothing.", 곧 "Hamlet = 0;"이다.)
  ("Open your heart!"는 Hamlet의 값을 숫자로 출력한다.)

 Hamlet:
  Thou art as rotten as a disgusting dusty evil fat-kidneyed fatherless foul
  hairy horrible infected lying pig.
  ("pig"는 -1이고, 앞의 형용사의 수 대로 2배를 한다. 곧 "Macbeth = -2^11;")

 Macbeth:
  Thou art as vile as the difference between nothing and the sum of a
  snotty stinking half-witted hog and a small toad!
  Speak your mind!
  ("the difference between A and B"는 뺄셈(A-B)을, "the sum of A and B"는 덧셈(A+B)를 수행한다.)
  (즉 "Hamlet = 0 - ((-2^3) + (-2^1));" -> "Hamlet = 10;")
  ("Speak your mind!"는 ASCII code로 Hamlet을 출력시킨다. 화면상에서 줄바꿈이 된다.)

 Hamlet:
  Thou art as half-witted as the cube of the difference between nothing and yourself.
  ("yourself"는 Macbeth 자신을 의미한다. 즉 "Macbeth = (0 - Macbeth)^3;" 결과 2^33.)

 [Exit Macbeth]

 [Enter Ophelia]

 (Macbeth가 퇴장하고 Ophelia가 등장하면서 "Thou"의 대상이 바뀐다는 점에 주의.)

 Hamlet:
  Thou art as noble as myself!
  ("Ophelia = Hamlet;"으로 처리된다.)

 [Exit Ophelia]

 [Enter Romeo]

 Hamlet:
  Thou art a hero! Open your heart.
  ("Romeo = 1;" Romeo 출력.)

 Romeo:
  Speak your mind.
  (Hamlet 출력.)

                    Scene II: Tension is building. (1막 2장: 긴장이 생긴다.)

 Romeo:
  Thou art as villainous as the sum of myself and Juliet.
  (Hamlet = Romeo + Juliet;)

  Is Macbeth worse than you? If so, we must proceed to Scene V.
  (Macbeth가 너(Hamlet)보다 못하는가? 그렇다면 우리는 1막 5장으로 가야만 한다.)
  (조건문이다. 못하다 낫다는 것은 크기가 작다 크다로 구분된다. 즉,)
  (if(Macbeth < Hamlet) goto Scene V.)

  Open your heart!

 [Exit Hamlet]

                    Scene III: New levels of courage. (1막 3장: 새로운 레벨의 용기(?).)

 [Enter Ophelia]

 Romeo:
  Speak your mind!

 [Exeunt]
 (Romeo와 Ophelia 둘 다 퇴장한다.)

                    Scene IV: Juliet has second thoughts. (1막 4장: Juliet에게 두번째 생각이 생기다.)

 [Enter Juliet and Hamlet]

 Hamlet:
  Thou art as fine as Romeo!
  (Juliet = Romeo;)

 [Exit Hamlet]

 [Enter Romeo]

 Juliet:
  Thou art as cunning as Hamlet.
  (Romeo = Hamlet;)

 [Exit Juliet]

 [Enter Hamlet]
 Hamlet:
  Let us return to scene II.
  (현재 무대 위에 등장한 인물은 Romeo와 Hamlet이다. Scene II로 가서도 그것이 변하지 않는다는 점에 주의.)
  (goto Scene II;)

                    Scene V: Fin.
 [Exeunt]

여기까지 모든 내용을 C로 직역한 내용을 옮겨 보면

scene_1:
    Hamlet = 0; Hamlet 출력;
    Macbeth = -2^11;
    Hamlet = 10; Hamlet 출력(줄바꿈);
    Macbeth = (-Macbeth)^3;
    Ophelia = Hamlet;
    Romeo = 1; Romeo 출력;
    Hamlet 출력(줄바꿈);
scene_2:
    Hamlet = Romeo + Juliet;
    if(Macbeth < Hamlet) goto scene_5;  //Macbeth는 MAX 역할을 해 준다.
scene_3:
    Ophelia 출력(줄바꿈);
scene_4:
    Juliet = Romeo;
    Romeo = Hamlet;
    goto scene_2;
scene_5:

여기에서 주목해야 할 부분은 Romeo = 1 같은 것을 할 때에도 "Thou art a hero!(당신은 영웅입니다!)" 같은 표현을 쓴다는 데에 있다.

What a fun!!! 조금 읽어보고고 너무 신기하고 웃겨서 야밤에 한번 푸하하! 라고 소리질렀어요 :D --친과학자


"; if (isset($options[timer])) print $menu.$banner."
".$options[timer]->Write()."
"; else print $menu.$banner."
".$timer; ?> # # ?>