Erlang/OTP Forums

Author Message

<  Erlang  ~  problem with spawn

klm
Posted: Sun May 24, 2009 9:01 pm Reply with quote
User Joined: 11 May 2009 Posts: 18
hey !

I'm trying to launch a function in another files with the function spawn

I don't know why it did'nt works

maybe because it's not the same module

Gui_pid = spawn(?Gui, gui:start, [Self,Name,Position]),

How can I use the function spawn ?

thanks
View user's profile Send private message
ates
Posted: Sun May 24, 2009 11:23 pm Reply with quote
Joined: 23 May 2009 Posts: 3
May be follows will help:

$ cat x.erl
-module(x).

-export([start/1]).

start(Msg) ->
io:format("Hello from x module: ~p~n", [Msg]).

$ cat y.erl
-module(y).

-export([start/0]).

start() ->
spawn(x, start, ["Hello"]).
$ erl
Erlang R13B (erts-5.7.1) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

Eshell V5.7.1 (abort with ^G)
1> y:start().
Hello from x module: "Hello"
<0.35.0>
View user's profile Send private message
klm
Posted: Mon May 25, 2009 10:45 am Reply with quote
User Joined: 11 May 2009 Posts: 18
yes it works !

it was easy in fact.

I begin in this language and I've some problems sometimes which are not really big problems finally.
View user's profile Send private message
Mazen
Posted: Thu May 28, 2009 6:41 pm Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
klm; the real error is that you are using module:function it should be module,function..

so instead of:
Gui_pid = spawn(?Gui, gui:start, [Self,Name,Position]),

use:
Gui_pid = spawn(?Gui, gui, start, [Self,Name,Position]),

see this link for more info:

http://www.erlang.org/doc/man/proc_lib.html
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum