6
5

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.

Nimで標準入出力

Last updated at Posted at 2015-03-01

##はじめに
Nim(Nimrod)という言語の標準入出力の覚書。

##実行環境

  • Nim version 0.10.3
  • OSX Yosemite 10.10.2

##標準入出力

from strutils import split, parseInt
from math import sum

let
  inputStr = readLine(stdin)  # 一行入力(string)
  inputStrSeq = readLine(stdin).split(':')  # ':'でsplit(seq[string])
  inputIntSeq = readLine(stdin).split().map(parseInt)  # 空白でsplitしてintに変換(seq[int])

echo("inputStr : ", inputStr)  # 引数を連結して出力
echo("inputStrSeq : ", inputStrSeq)
echo("sum of inputIntSeq : ", sum(inputIntSeq))

##動作確認

sample.txt
hoge fuga
foo:bar:baz
1 1 2 3 5 8
$ cat sample.txt | nim c -r stdio.nim
inputStr : hoge fuga
inputStrSeq : @[foo, bar, baz]
sum of inputIntSeq : 20

##備考

  • readLineやechoはビルトイン関数(Module systemのprocedure)
  • 公式のチュートリアルではechoに渡す引数(intなど)を明示的に$でstringに変換しているが、勝手に処理されるので必要ない
  • seq[type]とはSequence型(可変長配列)で@[a1,…,an]という様に表記できる

##参考

6
5
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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?