Skip to content

Instantly share code, notes, and snippets.

@nattybear
Last active January 17, 2021 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nattybear/a41d57b40a08eb947fc5e678456d3003 to your computer and use it in GitHub Desktop.
Save nattybear/a41d57b40a08eb947fc5e678456d3003 to your computer and use it in GitHub Desktop.

이 글은 Canol Gokel님이 만든 Computer Programming using GNU Smalltalk를 읽고 정리한 것이다.

First Program

터미널에 gst라고 입력하면 아래와 같이 인터프리터가 실행된다.

$ gst
GNU Smalltalk ready

st>

아래와 같이 입력하고 <Enter>를 누르면

'Hello World!' printNl

아래와 같이 화면에 출력된다.

st> 'Hello World!' printNl
'Hello World!'
'Hello World!'

스몰토크에서는 모든 것을 객체로 다룬다.

작은 따옴표 안에 적은 문자열은 문자열 객체가 된다.

여기서 'Hello World!'는 문자열 객체이다.

이 객체를 화면에 출력하게 하고 싶을 때는 이 객체에게 메세지를 보내야 한다.

이때 사용하는 메세지는 printNl이다.

그런데 왜 같은 문자열이 한 번이 아니라 두 번 출력 됐을까?

첫번째 출력은 우리가 시켜서 나온 것이고

인터프리터 모드에서는 마지막에 평가한 표현식을 화면에 출력하기 때문에 두번째 출력이 나온 것이다.

이번에는 텍스트 파일에 소스 코드를 작성하고 인터프리터로 실행해보자.

"hello_world.st"
"A program to print 'Hello World!' to the terminal."

'Hello World!' printNl

hello_world.st라는 이름으로 저장하자.

큰 따옴표 안에 있는 문자열은 주석이다. comments

아래와 같이 소스 코드를 실행 할 수 있다.

$ gst hello_world.st
'Hello World!'

Computer Programming with GNU Smalltalk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment