Running Erlang

This page is organized as follows:

  1. Running Erlang on Your Own Machine
  2. Troubleshooting
  3. Advanced Topics

You should use the Erlang OTP system for this class.

Return to top

Running Erlang on Your Own Machine

The Erlang system is most convenient to use on your own computer.

Getting Erlang for your Own Machine

The Erlang system used for this course is available on many platforms, including Linux, Macintosh, and Windows. You can download it from erlang.org. Note that binaries for Mac OSX and Linux are available as described at the bottom of the page.

To use erl at the command line, you should put the full path to Erlang's bin directory in your PATH environment variable. (To set environment variables in Windows XP/Vista/7, start the control panel, then click on "System", then the "Advanced" tab, then click on "Environment Variables".)

If you find more details about a system that you had trouble with, see the course staff. If you fix such a problem yourself, please let us know how you fixed the problem.

Return to top

Troubleshooting

Case Problems

Erlang is case sensitive. Be sure to use names that start with an upper case letter (A-Z or _) for variable names and formal parameters. For example, if you write a function like:

square(n) 
             -> n*n.
    

Then this code does not work when called. Do you see why?

Bad Match Problems

Erlang does not have an assignment statement. The unification operator in Erlang (=) looks like the assignment operator in C/C++/Java, but does matching or unification. It only lets you bind a value to a variable once. Consider the following interaction with the Erlang shell.

    1> C=4020.
    4020
    2> C=C+1.
    ** exception error: no match of right hand side value 4021
    

This error occurs because the value of C is 4020 and the value of C+1 is 4021, but 4020 cannot be unified with 4021, hence the error. As you can see, you cannot "reassign" a variable. Instead you can unify an expression with a fresh variable name, as in the following.

NewC=C+1.

Execution Hangs (Suspends) Problems

If your code seems to wait forever, the problem may not be an infinite loop, but a receive expression that is waiting for a message that has not been sent. This could be caused by a number of problems: the process that should be sending the message has terminated (e.g., because a server's loop is not looping), the message was sent but its format is wrong (so it does not match the receive expression's pattern), or the message is not being sent (because the code that should send it does not).

Other Problems

If you are having a problem not described above, or if the solutions listed above are not working for you, you can look at the webcourses discussions, where we often post answers to other people's questions. If none of that help then please don't hesitate to contact the course staff.

Return to top

Advanced Topics

There are a variety of programming environments for Erlang that are described below.

Erlang Eclipse Plugin

There is an Erlang plugin for Eclipse. See https://erlide.org for details.

Running Erlang from Within Emacs

To run Erlang from within Emacs, see http://erlang.org/doc/man/erlang.el.html under the heading "Shell". This is what Gary uses in class.

Windows Keystrokes in Emacs

If you like to use the standard Windows keystrokes for cut, paste, and copy, customize Emacs to use CUA-mode by default. (This assumes that you have Emacs version 22 or later. Use the menu "Options", select "Customize Emacs", and from there the select "Top Level Customizations". then select the "Convenience" group by clicking on the "go to group" link, and then go to the Cua group, and click on the "Value Menu" for enabling this customization.

If the above doesn't work, or if you have a version of Emacs previous to 22, put the following in your emacs initialization file, ~/.emacs.el. (The lines that start with a semicolon are comments, and can be omitted.)

(if (< emacs-major-version 22)
  (progn
    ;; Make emacs more like standard windows applications in terms of
    ;; mouse selections (this is similar to pc-select).
    ;; One advantage is this is that it makes Dragon Dictate work with Emacs.
    (require 'cua)
    ;; Make the behavior of emacs on C-c, C-v, C-x, and C-z to be
    ;; just like that of be as in standard window apps, so you can use
    ;; these keys to copy, paste, and select when there is a selection
    ;; active, then uncomment the following.
    (CUA-mode t)
    ;; Make C-c leave the region active, which is what happens under Windows.
    (setq CUA-mode-keep-region-after-copy t)
  )
  ;; The same for emacs version 22 (and hopefully higher...)
  ;; but not for aquamacs, which already has it.
  (if (not (featurep 'aquamacs))
      (progn (cua-mode)
             (setq cua-enable-cua-keys t)
             (setq cua-mode-keep-region-after-copy t)
      )
  )
)

Alternatively, you can use Gary Leavens's .emacs.el file which includes the above lines and several other things. It should be saved into .emacs.el in your home directory. (On Windows you may not have a home directory yet, so pick one. You also have to set HOME in the environment; this is automatic in Unix and hence on Mac OS X, but needs to be done by hand in Windows.)

For Vi Users

If you are a vi user, you may want to use viper-mode in emacs to get the vi keystrokes and still use all the wonderful Emacs features. To do this, put the following in your .emacs.el file:

(viper-mode)

Return to top

Last modified Wednesday, November 20, 2019.

This web page is for COP 4020 at the University of Central Florida. The details of this course are subject to change as experience dictates. You will be informed of any changes. Please direct any comments or questions to Gary T. Leavens at Leavens@ucf.edu. Some of the policies and web pages for this course are quoted or adapted from other courses I have taught, in partciular, Com S 342.