[erlang-questions] help with message-passing syntax
David Mercer
dmercer@REDACTED
Thu Jul 3 17:04:22 CEST 2008
You dont send messages to functions, you send them to processes. Also,
youre missing periods after the squarer and squarer2 functions (after the
ends), which accounts for two of the compiler errors.
_____
From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of not norwegian
swede
Sent: Thursday, July 03, 2008 04:04
To: erlang-questions@REDACTED
Subject: [erlang-questions] help with message-passing syntax
im using:
http://www.erlang.org/doc/reference_manual/part_frame.html
but cant really figure it out. i didnt expect this to work but compiled
anyway:
2> c("c:/Program Files/erl5.6.2/usr/serec", [{outdir, "c:/Program
Files/erl5.6.2/usr/"}]).
c:/Program Files/erl5.6.2/usr/serec.erl:2: function squarer/1 undefined
c:/Program Files/erl5.6.2/usr/serec.erl:2: function squarer2/1 undefined
c:/Program Files/erl5.6.2/usr/serec.erl:23: premature end
error
3>
obv this is just a toy program but say I have a function that squares the
integers of a list from 1 to the send parameter.
so i want to send a message to that function.
-module(serec).
-export([seq/2,squarer/1,squarer2/1]).
seq(Start, End) -> seq(Start, End, []).
seq(Start, End, Acc) when Start =< End ->
seq(Start, End-1, [End|Acc]);
seq(_, _, Acc) ->
Acc.
squarer(X) ->
receive
Pattern [when Pattern > 7] ->
[X*X || X <- [seq(1, 7]];
end
squarer2(X) ->
receive
when X > 7 -> [X*X || X <- [seq(1, 7]];
end
squarer(X) ! 2+6
_____
Låna pengar utan säkerhet.
Sök
<http://www.kelkoo.se/c-100390123-lan-utan-sakerhet.html?partnerId=96915014>
och jämför lån hos Kelkoo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080703/e6b4494d/attachment.htm>
More information about the erlang-questions
mailing list