---
title: "erlang入门系列(1) Hello World! "
author: "nid007"
date: "2010-10-09T09:44:25Z"
tags: []
categories: ["编程语言"]
slug: "erlang-1-hello-world"
draft: false
lastmod: "2010-10-09T15:05:18Z"
id: 779188
url: "https://nid007.iteye.com/blog/779188"
---

```erlang

-module(hello).
-export([start/0]).
start() -> 
	io:format("hello word~n").

```

把上面的代码保存为hello.erl，文件名必须跟module名一致，这点跟JAVA是类似的

然后编译：erlc hello.erl
然后运行：erl -noshell -s hello start -s init stop

好的，这样erlang的Hello World总算是完成了。

以下是引申部分：
如果我想给这个start方法传个参数，那怎么办？小改一下

```erlang

-module(hello).
-export([start/1]).
start(Args) -> 
	io:format("hello ~s, ~s ~n",Args).

```

再次编译：erlc hello.erl
然后运行：erl -noshell -s hello start nid "I am Nid呵呵" -s init stop
这时控制台会输出：
hello nid, I am Nid呵呵

如果你想学习更多
请参考：

Programming Erlang 第6章 《Compiling and Running Your Program》
http://www.erlang.org/doc/man/io.html#format-2  这里是官方关于io:format的详细文档