Ubuntu下nim language环境配置
Ubuntu下nim language环境配置
卜库塔 发表于3年前
Ubuntu下nim language环境配置
  • 发表于 3年前
  • 阅读 99
  • 收藏 0
  • 点赞 0
  • 评论 0
摘要: ubuntu 14.04下Nimrod language环境配置

Getting Started

Nim is a powerful statically typed language that allows the programmer expressiveness without compromising run-time performance. As a general purpose programming language, it gives the same sort of power and performance as C++, but in a nicer package and with even more powerful tools!

Note: The Nim compiler requires a C compiler to compile software. GCC is recommended on Linux and Clang on Mac.

Downloading from Git

To install Nim from git, ensure that you have gcc installed on Windows, Linux, and BSDs and clang on Mac. Afterwards, run the following series of commands to download and bootstrap Nim:

 $ git clone -b master git://github.com/Araq/Nimrod.git
 $ cd Nimrod
 $ git clone --depth 1 git://github.com/nimrod-code/csources
 $ cd csources
 $ sh build.sh
 $ cd ..
 $ bin/nim c koch
 $ ./koch boot -d:release

Once compiled, you may want to add the bin directory to your path for easy access.

Nimble

Nimble is a beta-grade package manager for the Nim programming language.

On Unix operating systems Nimble can be compiled and installed with two simple commands. After successfully grabbing the latest Nim compiler simply execute the following commands to clone nimble, compile it and then install it.

$ git clone https://github.com/nim-lang/nimble.git
$ cd nimble
$ nim c -r src/nimble install

After these steps nimble should be compiled and installed. You should then add ~/.nimble/bin to your$PATH. Updating nimble can then be done by executing 

$ nimble install nimble

.

Aporia

Aporia is an IDE for the Nim programming language. Aporia uses GTK as the default toolkit, and the gtksourceview for the text editor component.

Dependencies

  • GTK

  • GtkSourceView (libgtksourceview-2.0.so)

  • PCRE

Use your linux package manager to install the dependencies.

Compiling

To compile Aporia you need the latest version of the nim compiler, preferably the unstable release from github. Aporia sometimes relies on bug fixes which have not yet made it to a stable release.

You can build it by running :

$ nim c aporia

 or by using nimble :

$ nimble build

You can also quickly install it using nimble without the need to clone this repo yourself, just execute:

$ nimble install aporia@#head

Example

The code for a simple program is as follows:

import tables, strutils

var wordFrequencies = initCountTable[string]()

for line in stdin.lines:
  for word in line.split(", "):
    wordFrequencies.inc(word)

echo "The most frequent word is '", wordFrequencies.largest, "'"

Save this text as frequentword.nim. To compile and execute the program, the following command should be run with some input words :

$ nim c -r --verbosity:0 frequentword.nim
大黄, 小白, 大黄, 小白, 小白, 小白, 大黄
The most frequent word is '(key: 小白, val: 4)'

The command has several elements:

  • c is an alias for compile, which compiles the Nim sources into C and then invokes the C compiler on them

  • -r is an alias for --run, which runs the program

  • --verbosity:0 makes the compiler only output essential messages, since by default it also outputs some debugging messages. From now on, we assume that --verbosity:0 is set

  • ./frequentword.nim is the path to the source you want to compile


标签: nim nimrod nimble aporia
共有 人打赏支持
粉丝 22
博文 2
码字总数 528
×
卜库塔
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: