LoginSignup
14
7

More than 5 years have passed since last update.

TrumpScriptが面白そうなので動かしてみた

Posted at

TrumpScript

概要

トランプ次期米大統領が誕生し世間が騒がしくなっているが、このタイミングでTrumpScriptたるものを見つけたので動かしてみる。

米ライス大学のハッカソンで同大学の学生が作ったらしい。素晴らしいノリ!

特徴

  • 浮動小数点型は使えず整数のみ。アメリカは中途半端なことはしない。
  • 数値は100万より大きくなくてはいけない。それより小さい数字は取るに足らない。
  • importは使えない。全てのコードはアメリカ製でなければならない。
  • True,Falseの代わりにfact,lieを使う。
  • 変数名に使えるのは最も一般的な英単語、トランプ氏の好きな単語、現在の政治家の名前のみ。
  • エラーメッセージはトランプ氏の言葉からの引用。
  • 全てのプログラムは"America is great"で終わる必要がある。
  • 45億は100億に自動的に修正される。
  • Windowsでは動かない。なぜならトランプ氏はPCを信じるような人ではないから。(PC:パソコンと- Politically Correct:政治的正しさ、のかけ)
  • 大文字と小文字は区別しない。
  • 中国やメキシコから実行してもコンパイルされない。アメリカの秘密事項を盗まれたくないからだ。
  • 共産主義のなりすまし(中国製のSSL証明書)がシステムにあると警告される。
  • root権限では動かない。アメリカに必要なのはトランプ氏だけである。

文法

  • +かplusで加算
  • -かminusで減算
  • *かtimesで乗算
  • /かoverで除算
  • <,less,fewer,smallerは全て同じ意味
  • >,more,greater,largerは全て同じ意味
  • ,と;で式をはさんで評価する
  • :と!でブロックをつくる
  • if,else if,else,not,and,orは文字通りに使える
  • 文字列は"で囲う
  • is,areは式が同じ値かどうかをチェックするキーワード。式を評価するには、最後に?を追加する
  • makeで変数に値を代入できる
  • 標準出力はtellかsay
  • whileループはas long as
  • 余計な単語は全て無視される ※ただしallowed_words.pyに入っていない単語を使用すると怒られる

やたらと面白いw

インストール方法

まずはここから samshadwell/TrumpScript

TrumScriptをcloneする

$ git clone https://github.com/samshadwell/TrumpScript

pathの追加 (path/toの部分はlocalのdirectoryと合わせる必要あり)

$ export PATH=$PATH:/path/to/TrumpScript/bin

ファイルの作成(拡張子はtxtでもtrでもOK)

$ touch trumpScriptTest.txt
$ touch trumpScriptTest.tr

これで準備完了

Hello World!を出力する

出力はtellsayとのこと。今回はtellでいく。

trumpScriptTest.txt
tell "Hello World!"
Exception: Mac? 'Boycott all Apple products  until such time as Apple gives cellphone info to authorities regarding radical Islamic terrorist couple from Cal'

TrumpScript boycotts OS X and all Apple products until such time as Apple gives cellphone info to authorities regarding radical Islamic terrorist couple from Cal.

ナンテコッタ。Apple製品がボイコットされるw このままだと進まないので、

utils.py
class Utils:

    中略

    @staticmethod
    def verify_system(wall) -> None:
        """
        Verifies that this system is Trump-approved, throwing
        a SystemException otherwise
        :return:
        """
        Utils.no_wimps()
        Utils.no_pc()
        # Utils.boycott_apple()
        Utils.no_commies_mexicans_or_kenyans(wall)
        Utils.no_commie_network()

Utils.boycott_apple()をコメントアウトして再度スタート

trumpScriptTest.txt
tell "Hello World!"
Exception: Trump will ensure that 'America is great'

ナンテコッタ。

All programs must end with America is great.

プログラムはAmerica is great.で終わらないといけないw

trumpScriptTest.txt
tell "Hello World!"
America is great.
hello world!

やっとできた! 大文字小文字を区別しない(細いことは気にしない)のもトランプ流

簡単なロジックの導入

超簡単に、budgetが100万以上あったらi am super rich!と出すプログラムを書いてみる

trumpScriptTest.txt
budget is 5000000
if, budget greater 1000000; :
  say "I am super rich!"
!
America is great.
i am super rich!

文法がやたらとややこしい
- 代入は is / are / make
- 比較演算は more / greater / largerなどなど
- ( ), ; で表現
- { }: ! で表現
その他もろもろだが、とりあえずこんなところで

その他の面白い特徴

トランプは細かいことは気にしない

浮動小数点型は使えず整数のみ。アメリカは中途半端なことはしない。
数値は100万より大きくなくてはいけない。それより小さい数字は取るに足らない。

ここらへんやってみましょう

trumpScriptTest.txt
make size 10
tell size
America is great.
What are you doing on line 1?
Exception: Part of the beauty of me is I'm very rich.

何やってるんだ?と怒られましたw 数値は100万より大きくないといけないので、

trumpScriptTest.txt
make size 100000000000
tell size
America is great.
100000000000

できました。

トランプの好きな言葉

変数名に使えるのは最も一般的な英単語、トランプ氏の好きな単語、現在の政治家の名前のみ。

allowed_words.pyに使える言葉が列挙されています

allowed_words.py
ALLOWED = {"a",
"abandoned",
"able",
"aborted",
"abortion",
"about",
"above",
"absolute",
"absolutely",
"abuse",
"abused",
"accept",
...

とりあえず日本語出力してみましょう

trumpScriptTest.txt
tell 'こんにちは、トランプさん'
America is great.
Exception: We have a country where to assimilate you have to speak English

律儀に挨拶したのにしっかり怒られましたw

終わりに

率直な感想、本人の特徴がルールに表現されていてめっちゃ面白いw 時間つぶしにしかならないがちょっと触って周りの人と盛り上がるのはありかも。

14
7
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
14
7