LoginSignup
10
8

More than 5 years have passed since last update.

Jupyterでnimを使おう

Posted at

nimを使おう

nim速いみたいだし、Pythonに似ているらしいので、試してみましょう。
Jupyterのカーネルは、、、ない。
dockerで作りました

実行方法

dockerのインストールは、Install Docker Engineを見てください。

下記を実行すると、Jupyterが起動します。

bash
docker run -it --rm -p 8888:8888 tsutomu7/nim

ブラウザで「dockerホストのIPアドレス:8888」を開いてください。
右上の”New"から"nim"を選んでください。

説明

セルにnimのプログラムを書いて、Shift+Enterで実行できます。

nim
echo "Hello world!"
>>>
Hello world!

「?」でコマンド一覧が出ます。

nim
?
>>>
?
!command
%run file
%time ...
%def ...
%inc ...
%web

「!」で始めるとシェルのコマンドを実行できます。

nim
!echo 'echo "OK"' >> test.nim

「%run [オプション] ファイル名」でファイルを実行できます。

nim
%run test
>>>
OK
nim
%run --opt:size test
>>>
OK

「%time [オプション]」で実行時間を計測できます。

nim
%time
echo "OK?"
>>>
OK?
real    0m 0.00s
user    0m 0.00s
sys     0m 0.00s

「%def 名称」でプログラムファイルを作成できます。

nim
%def hello
proc Hello(): string = "Hello!"
>>>
Created hello.nim
nim
%def world
proc World(): string = "World!"
>>>
Created world.nim

「%inc 名称1 名称2 …」でファイルを取り込んで実行できます。

nim
%inc hello world
echo Hello() & World()
>>>
Hello!World!

「%web」でドキュメントのURLを表示します。

nim
%web
>>>
http://nim-lang.org/documentation.html

参考

以上

10
8
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
10
8