1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Squeak Smalltalkでズンドコキヨシ

Last updated at Posted at 2016-03-17
| zundoko last5 set |
zundoko := #(ズン ズン ズン ズン ドコ) asOrderedCollection.
last5 := zundoko copy.
set := zundoko asSet.
Transcript countOpenTranscripts isZero ifTrue: [Transcript open] ifFalse: [Transcript clear].
[Transcript show: (last5 removeFirst; add: set atRandom); space. last5 = zundoko] whileFalse.
Transcript show: 'キ・ヨ・シ!'


日本語Squeakなど、日本語表示が可能な Squeak Smalltalk 環境でワークスペースなどに貼り付けて do it すると動かせます。以下、各行でやっていることを簡単に解説。


| zundoko last5 set |

テンポラリ変数(zundoko、last5、set)の宣言。


zundoko := #(ズン ズン ズン ズン ドコ) asOrderedCollection.

#(ズン ズン ズン ズン ドコ) 配列(#ズン 4つと #ドコを要素に持つ)を asOrderedCollection で可変長配列へ変換して zundoko に代入。


last5 := zundoko copy.

zundoko をコピーして last5 に代入。


set := zundoko asSet.

zundoko をセット(重複を許さない順不同集合)に変換して set に代入。


Transcript countOpenTranscripts isZero ifTrue: [Transcript open] ifFalse: [Transcript clear].

トランスクリプト(標準出力もどき)のウインドウがひとつもなければ新たに開いて、あれば中身を消去。


[Transcript show: (last5 removeFirst; add: set atRandom); space. last5 = zundoko] whileFalse.

last5 の最初の要素を除いてから、set(#ズン と #ドコ を要素に持つ)のどちらか(atRandom)を追加。追加した要素(#ズン か #ドコ)が返値になるので、それをトランスクリプトに出力(show:)。続けてスペースを出力準備。last5 が zundoko に一致するまで繰り返し。


Transcript show: 'キ・ヨ・シ!'

「キ・ヨ・シ!」を出力して終了。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?