簡単に Jupyter で Coconut ( python ) を試す
Binder を使用して、pip または conda パッケージ ライブラリがプリインストールされた一時的な Jupyter Notebook サーバーをクラウドで起動できます。
ブラウザだけで、関数型プログラミング言語 Coconut を クラウドの Jupyter notebook で使える環境を作ります。
1. Github Gist
https://gist.github.com/ にアクセスします。
右上の New Gist をクリックします。
ファイル名として requirements.txt を入力します
(conda を使用する場合は environment.yaml を使用します)。
ノートブックで使用するライブラリを追加します。
requirements.txt の内容は、
coconut
coconut とだけ書きます。
Create Public Gist をクリックします。
この Gist のページの URL をコピーします。
2. Binder
https://mybinder.org/ にアクセスします。
ドロップダウンから Gist を選択します。
で用意した public gist の URL をペーストもしくは、 gist のユーザー名/gistid を入力します。
Launch をクリックします。
デプロイが始まります。
Coconut の Jupyter notebook カーネルが使用できる状態のサーバーが起動します。
Coconut カーネル ノートブック
余談としては、 Google colab を使ってもやや変則的に Coconut のコードの実行ができるようです。
その方法は、こちら。
example notebook
というリンクをクリックすると、Google colab のノートが開きます。
いったんドライブか、Gist に保存してから使うといいかもしれません。
!pip install coconut[jupyter]
の実行でインストールが始まりますが、cPyparsing のインストールになかなか時間がかかるようです。
もしインストールが完了せずに、セッションがクラッシュするようなら、
ランタイムを接続解除して削除 をしてから、
!pip install coconut
と変更してからセルを実行してみるといいかもしれません。
次のセル
%load_ext coconut
%%coconut
とセルの中の先頭行頭に書いて始まるコードは、Coconut のコードとして実行されるようです。
なお、2. で示した mybinder にデプロイされた普通の Jupyter notebook クラウドの方では %%coconut というマジックコマンドは必要ありません。
テストのコードは、見慣れない構文ですが、
%%coconut
sums = map( x -> x + 1, range(0, 10))
sums |> list |> print
だとシンプルに |> のパイプが効いていることが分かりやすいかもしれません。
このセルを実行すると、出力は
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
になりました。
元のノートをコピーして、変更を加えたファイルを参考までにあげておきます。
ipynb ファイル
この記事が気に入ったらサポートをしてみませんか?