Created
June 13, 2014 07:44
-
-
Save snipsnipsnip/ed63066a1312bd228b6c to your computer and use it in GitHub Desktop.
Amachang's prototype-based OOP example in J (http://d.hatena.ne.jp/amachang/20061019 via http://blog.livedoor.jp/dankogai/archives/50666398.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NB. Amachang's prototype-based OOP example in J | |
NB. http://d.hatena.ne.jp/amachang/20061019 via http://blog.livedoor.jp/dankogai/archives/50666398.html | |
animal =. conew 'z' | |
breath__animal =: verb define | |
echo 'すーはー' | |
) | |
NB. 鳥さんのプロトタイプ | |
bird =. conew >animal | |
fly__bird =: verb define | |
echo 'ばたばた' | |
) | |
NB. ペンギンさんのプロトタイプ | |
penguin =. conew >bird | |
fly__penguin =: verb define | |
echo '飛べない' | |
) | |
NB. ドンペン君 | |
donpen =. conew >penguin | |
sing__donpen =: verb define | |
echo 'どんどんどんどんきー♪ドンキーホーテー!' | |
) | |
breath__donpen '' NB. 動物だから呼吸できる | |
fly__donpen '' NB. ペンギンは飛べない | |
sing__donpen '' NB. ドンキホーテーの歌を歌う | |
NB. 実は鳥は歩ける | |
walk__bird =: verb define | |
echo 'てくてく' | |
) | |
walk__donpen '' NB. 鳥なので「てくてく」歩ける | |
NB. でも、ペンギンは「てくてく」じゃなく「ぴょこぴょこ」だ | |
walk__penguin =: verb define | |
echo 'ぴょこぴょこ' | |
) | |
walk__donpen '' NB. ぴょこぴょこ | |
exit 0 |
Author
snipsnipsnip
commented
Jun 13, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment