COP 4020 Lecture -*- Outline -*- * Installing and Running Erlang ** motivation ------------------------------------------ MOTIVATION FOR ERLANG Erlang designed for: - reliable distributed systems (telephony) Language Design: - mix of functional and logic programming influences - actor model for concurrency and distribution ------------------------------------------ Q: Why this kind of design? - immutable data allows concurrency without locking - distribution allows for scalable systems, avoids single point failures This is a very successful model of distribution and parallelism - copied in other languages (e.g., Scala) ** installation ------------------------------------------ INSTALLING ERLANG Download erlang from: https://www.erlang.org/downloads 1. Double click on the download 2. Add the install directory to your PATH On a Mac: - For Homebrew on OS X: brew install erlang - For MacPorts on OS X: port install erlang For Linux: - For Ubuntu and Debian: apt-get install erlang - For Fedora: yum install erlang ------------------------------------------ Q: Why this kind of design? - immutable data allows concurrency without locking - distribution allows for scalable systems, avoids single point failures ** Running code *** shell ------------------------------------------ RUNNING THE ERLANG SHELL $ erl Eshell V10.5 (abort with ^G) 1> 2+7. 9 2> halt(). ------------------------------------------ You can also type ^C to halt the system *** modules and files ------------------------------------------ CODE GOES IN MODULES module names start with a lowercase letter hello goes in a file with .erl suffix: hello.erl ------------------------------------------ See hello.erl % MODULE hello -module(hello). -export([main/0]). main() -> 'Hello, world!'. notice the syntax has periods and parentheses and square brackets. ------------------------------------------ RUNNING CODE 1. Compile the module $ erl Eshell V10.5 (abort with ^G) 1> 2. Run the code 2> ------------------------------------------ ... c(hello). % compile it {ok,hello} % response ... hello:main(). % note the module name and period! 'Hello, world!' % result