Tuesday, September 29, 2015

Helllo World In #Erlang on Mac

Store

-module(hello).
-export([hello_world/0]).
hello_world() -> io:fwrite("hello, world\n").

in a hello.erl file. You can use Sublime as an editor.
[hello_world/0] means function hello_world with zero argument.




Compile the file


erl -compile hello




Open the Erlang Terminal
erl

You can also compile the program in terminal by
c(hello) compiles the file hello.erl




Run the program

hello:hello_world().


Output:
hello, world
ok



To shut a system down cleanly, use init:stop().
Some quick ways are evaluating halt(). or control+\.
control+C a give you access to menus.








Installing #Erlang on mac

brew install erlang

==> Installing dependencies for erlang: openssl, unixodbc, jpeg, libpng, 
==> Installing erlang dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2d_1.yosemite.b
######################################################################## 100.0%
==> Pouring openssl-1.0.2d_1.yosemite.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2d_1: 464 files, 18M
==> Installing erlang dependency: unixodbc
==> Downloading https://homebrew.bintray.com/bottles/unixodbc-2.3.2_1.yosemite.b
######################################################################## 100.0%
==> Pouring unixodbc-2.3.2_1.yosemite.bottle.1.tar.gz
🍺  /usr/local/Cellar/unixodbc/2.3.2_1: 31 files, 1.0M
==> Installing erlang dependency: jpeg
==> Downloading https://homebrew.bintray.com/bottles/jpeg-8d.yosemite.bottle.2.t
######################################################################## 100.0%
==> Pouring jpeg-8d.yosemite.bottle.2.tar.gz
🍺  /usr/local/Cellar/jpeg/8d: 18 files, 776K
==> Installing erlang dependency: libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.18.yosemite.bott
######################################################################## 100.0%
==> Pouring libpng-1.6.18.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/libpng/1.6.18: 17 files, 1.2M
==> Installing erlang dependency: libtiff
==> Downloading https://homebrew.bintray.com/bottles/libtiff-4.0.6.yosemite.bott
######################################################################## 100.0%
==> Pouring libtiff-4.0.6.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/libtiff/4.0.6: 259 files, 3.9M
==> Installing erlang dependency: wxmac
==> Downloading https://homebrew.bintray.com/bottles/wxmac-3.0.2.yosemite.bottle
######################################################################## 100.0%
==> Pouring wxmac-3.0.2.yosemite.bottle.11.tar.gz
🍺  /usr/local/Cellar/wxmac/3.0.2: 777 files, 41M
==> Installing erlang
==> Downloading https://homebrew.bintray.com/bottles/erlang-18.1.yosemite.bottle
######################################################################## 100.0%
==> Pouring erlang-18.1.yosemite.bottle.tar.gz
==> Caveats
Man pages can be found in:
  /usr/local/opt/erlang/lib/erlang/man

Access them with `erl -man`, or add this directory to MANPATH.
==> Summary

🍺  /usr/local/Cellar/erlang/18.1: 7465 files, 287M