[erlang-questions] help with message-passing syntax
not norwegian swede
notnorwegian@REDACTED
Thu Jul 3 11:04:01 CEST 2008
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
__________________________________________________________
Går det långsamt? Skaffa dig en snabbare bredbandsuppkoppling.
Sök och jämför priser hos Kelkoo.
http://www.kelkoo.se/c-100015813-bredband.html?partnerId=96914325
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080703/f7d5e715/attachment.htm>
More information about the erlang-questions
mailing list