Hopefully simple problem
Corrado Santoro
csanto@REDACTED
Fri Jan 16 22:15:09 CET 2004
Hi Chris,
you cannot pass a function using module:func.
Pass instead the module name and the function name as two different atoms and
then use the BIF "apply(ModuleName, FuncName, ParamerList)" to call the
function, e.g.
-module (x).
-export ([y/2]).
y(A,B) -> A + B.
You may call "y(10,20)" as:
apply (x, y, [10,20]).
Bye,
-Corrado
Quoting "chris.danx" <chris.danx@REDACTED>:
> Hi,
>
> I am relatively new to erlang and am having some trouble.
>
> I entered
>
> X = nnet:neuron (0, nblah:bfunc, nblah:xfunc, []).
>
> at the shell, but get an Illegal Expression error back. Both modules
> are compiled. I want to pass two functions into the function so I get
> back a process that can perform those functions when called for. The
> modules are...
>
>
> -module(nblah).
> -export([bfunc/2, xfunc/2]).
>
> bfunc (X, Y) ->
> X.
>
> xfunc (X, Y) ->
> X + Y.
>
> and
>
>
> -module(nnet).
> -export([nloop/1,
> neuron/4]).
>
> neuron(State, ActFunc, CombineFunc, ConnList) ->
> proc_lib:spawn (nnet, nloop, [{State, ActFunc, CombineFunc,
> ConnList}]).
>
> % A neuron.
> %
> % Takes a state, activation function, State Combination function,
> % and list of connection processes.
> %
> % State: The state of the neuron.
> % ActFunc: A function that takes the new state, propagates a
> % value to all connections and returns the new state
> % (the state after firing).
> % CombineStateFunc: Combines the input value with the state to produce
> % a new state.
> %
> nloop({State, ActFunc, CombineStateFunc, []}) ->
> receive
> {nInput, Val} ->
> X = CombineStateFunc (State, Val),
> Y = ActFunc (X, []),
> nloop ({Y, ActFunc, CombineStateFunc, []});
> {addConn, C} ->
> nloop ({State, ActFunc, CombineStateFunc, [C]})
> end;
> nloop({State, ActFunc, CombineStateFunc, Conns}) when is_list (Conns) ->
> receive
> {nInput, Val} ->
> X = CombineStateFunc (State, Val),
> Y = ActFunc (X, Conns),
> nloop ({Y, ActFunc, CombineStateFunc, Conns});
> {addConn, C} ->
> nloop ({State, ActFunc, CombineStateFunc, lists:append ([C],
Conns)})
> end.
>
> I know it's not the most efficient code in the world, but I'll fix it
> later when able to actually create the process.
>
> Can anyone help?
>
>
> Cheers,
> Chris
>
--
======================================================
Eng. Corrado Santoro, Ph.D.
University of Catania - Engineering Faculty
Department of Computer Science and
Telecommunications Engineering
Viale A. Doria, 6 - 95125 CATANIA (ITALY)
Tel: +39 095 7382364 Fax: +39 095 338280
+39 095 7382365
+39 095 7382380
EMail: csanto@REDACTED
Personal Home Page:
http://www.diit.unict.it/users/csanto
NUXI Home Page:
http://nuxi.iit.unict.it
======================================================
-------------------------------------------------
This mail sent through IMP: http://www.cdc.unict.it/
More information about the erlang-questions
mailing list