The first simple example of building and creating an Erlang environment in Windows

Source: Internet
Author: User

1. Install Erlang,

Ii. Installation

To the http://www.erlang.org/download.html, I downloaded the R15B03-1 windows binary file (91.3 MB), just install it directly. This step is very important to set the path after installation!

Add the Bin (such as c: \ erl5.9.3.1 \ bin) to the path of the system variable (right-click my computer/properties/advanced/environment variables ).

Iii. Check whether Erlang is successfully installed

Open cmd, enter ERL, and press Enter. If the following information is displayed, the installation is successful.

 

4. Use eclipse

Requirements for Erlang development in eclipse

1. My eclipse is 3.7.2

2. JDK 1.6

3. erlide

OK, install JDK 1.6 first, run the decompressed eclipse (preferably with only the Java version), and then update with the http://erlide.org/update in help/install new software. Select

You can. Restart eclipse after installation. Done!

5. The first Erlang Hello world!

1. Open eclipse, new/project/Erlang Project

Enter the project name "helloworld" and click Finish.

Eclipse automatically creates three folders.

Where:

Ebin stores compiled binary files (with the extension beam)

Include stores the files referenced in the program

SRC stores source code files

2. Right-click SRC and select new module to create an Erlang file (the extension is ERL)

Enter "HW" in Module name ". Note: The name must be in lowercase English or underline. Click Finish

3. Compile the print function

Enter the following code

Printhelloworld ()->

IO: Format ("Hello world! ").

OK. Write printhelloworld to-export to export the function. For example,-Export ([printhelloworld/0]). Here 0 indicates no parameter.

Note: Here-Export ([printhelloworld/0]) should be placed above the function definition;

Note: The function name must be in lower case and in upper case, it must be a variable. The function format is

Method Name (parameter)->

Method body.(Note that the ending point here is the sentence of an English file)

3. Compile

Right-click HW. erl and select Run as/Erlang Application

This will appear in the console

The compilation command is C (file name ).

Enter C (HW). Then press enter to display:

(Helloworld@127.0.0.1) 1> C (HW ).
HW. erl: None: no such file or directory
Error

At this time, an error is prompted: there is no corresponding file.

The directory SRC where HW. erl is located is not identified. So we use the CD command to go to this directory.

(Helloworld@127.0.0.1) 3> Cd ("D:/workspace/helloworld/src ").
D:/workspace/helloworld/src
OK

Note: The Path slash is left to the right;

Then you can compile it.

(Helloworld@127.0.0.1) 4> C (HW ).
{OK, HW}

After compilation, the corresponding HW. Beam file will be generated in the Ebin directory. Run the following command:

HW: printhelloworld ().
Hello world!
OK

OK. The first helloworld program is complete.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.