tags:

views:

251

answers:

2

I'm playing with the distributed programming tutorial from the 5.4 documentation, and have run into a problem with node names.

My MacBook's default name (jamess-macbook) does not play well with Erlang's node-naming scheme, due to the dash:

(salt@jamess-macbook)4> {my_process, pepper@jamess-macbook} ! start
** exception error: bad argument in an arithmetic expression
     in operator  -/2
        called as pepper@jamess - macbook

I'm sure there's an easy way to get around this, short of renaming all the machines I want to run Erlang on, but I can't see it in the documentation.

Any suggestions?

+3  A: 

Start the Erlang interpreter with:

$ erl -sname node_name

where node_name is the name you want to use to refer to the machine.

You can even simulate a distributed system on a single machine by starting several instances of the interpreter, each with a different node name.

mipadi
Ah, I didn't know you could supply the full node name (name@machine) through sname!
Alabaster Codify
+9  A: 

You just need to quote the atom properly. 'pepper@jamess-macbook' (with the single quotes) is the name of the node.

An atom should be enclosed in single quotes (') if it does not begin with a lower-case letter or if it contains other characters than alphanumeric characters, underscore (_), or @. -- Erlang Reference Manual

Using short node names (-sname) has various other consequences (limited interoperability with long node name nodes, doesn't load dns information into inet_db and so on).

archaelus
Even better - I had tried double quotes, not single; in fact, I didn't realise they were semantically different!
Alabaster Codify