ㄨPobre
ㄨPobre

Reputation: 27

How to use array in erlang with text editor

I want to create an array in erlang using text editor and run it. But I have no idea how. When I browse it, it's only demonstrated in terminal.

Upvotes: 0

Views: 71

Answers (1)

Stratus3D
Stratus3D

Reputation: 4916

Erlang does not have arrays. Erlang has linked lists, which can be used like arrays but they have there own performance characteristics that make it cheap to access the first item in the list and expensive to access the last item in a large list. You can read more about linked lists here: http://learnyousomeerlang.com/starting-out-for-real#lists

To create a list in a file that file will need to define a module with the same name as the file and export one or more functions. Here is what you might want:

-module(number_list).

-export([base_10/0]).

base_10() ->
  [0,1,2,3,4,5,6,7,8,9].

Then compile the file:

erlc number_list.erl

Then use it in the erl shell (assuming you run erl in the same directory as your number_list.beam file):

erl
> number_list:base_10().
[0,1,2,3,4,5,6,7,8,9].

Upvotes: 1

Related Questions