« Return to Thread: help with message-passing syntax

Re: help with message-passing syntax

by David Mercer-4 :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.

You don’t send messages to functions, you send them to processes.  Also, you’re missing periods after the squarer and squarer2 functions (after the ends), which accounts for two of the compiler errors.

 


From: erlang-questions-bounces@... [mailto:erlang-questions-bounces@...] On Behalf Of not norwegian swede
Sent: Thursday, July 03, 2008 04:04
To: erlang-questions@...
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 och jämför lån hos Kelkoo.


_______________________________________________
erlang-questions mailing list
erlang-questions@...
http://www.erlang.org/mailman/listinfo/erlang-questions

 « Return to Thread: help with message-passing syntax