Skip to content

Instantly share code, notes, and snippets.

@nattybear
Last active January 22, 2021 13:28
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/2a440361c1d2a66539cdbe38f861124a to your computer and use it in GitHub Desktop.
Save nattybear/2a440361c1d2a66539cdbe38f861124a to your computer and use it in GitHub Desktop.

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

Review Questions

  1. Write a program which gets a number from user and displays its cube.
| x |
x := stdin nextLine.
x := x asNumber
(x * x * x * x) printNl
  1. Write a program which gets two numbers from the user separated by a space and displays their arithmetic average. (Hint: You will get an input like 3 4 from the user which is a String holding two numbers. Use tokenize: aString message on this string to separate the numbers from each other. tokenize: message separates a string into pieces, which are called tokens, wherever it finds its argument inside the receiver and returns an Array which consists of all the tokens.)
| line x y tokens average |
line := stdin nextLine.
tokens := line tokenize: ' '.
x := (tokens at: 1) asNumber.
y := (tokens at: 2) asNumber.
average := (x + y) / 2.
average printNl.
  1. Write a program which holds definitions of some concepts we saw in Chapter 1 in a Dictionary object. The program should ask the user to enter a word then display the corresponding definition.
aDictionary := Dictionary new.
aDictionary at: 'apple' put: 'I like it!'; at: 'banana' put: 'yummy!'.
userInput := stdin nextLine.
(aDictionary at: userInput) printNl

Computer Programming with GNU Smalltalk

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