OTcl

위키백과, 우리 모두의 백과사전.

OTclTcl객체 지향 확장이다. 데이비드 웨더롤(David Wetherall)이 창안하였다.[1]. OTcl은 네트워크 시뮬레이터인 ns-2에서 쓰이고 있다. 유닉스 환경에서 동작한다.[2]

문법 소개[편집]

예약어 "Class"를 써서, 클래스를 선언한다. 클래스 내의 메소드들은 단어 "instproc"을 써서 선언한다.[2] 변수 "self"는 지금 현재 쓰이고 있는 객체에 대한 포인터이다. C++/Java에서의 "this"와 같은 역할을 한다. 키워드 "-instproc"은 계층(hierarchy)를 나타내기 위해 사용한다.[2] 예를 들면, "Class Duck -instproc Bird"라는 것은 클래스 Duck이 클래스 Bird를 상속한다는 말이 된다. 클래스에 대한 인스턴스를 새로 생성하려면, 프로그래머는 "set new_inst [new Son]"라고 적으면 된다. 다음은 코드 예제이다.

// Sample code in OTcl
Class HelloWorld
HelloWorld instproc hello {} {
	puts "Hello world"
}
set helloworld [new HelloWorld]
//to run
$helloworld hello

각주[편집]

  1. OTcl Project Page
  2. Sophie-Antipolis NS Simulator for beginners, Lecture notes, 2003-2004, Univ. de Los Andres, Merida, Venezuela and ESSI