Hopefully simple problem
chris.danx
chris.danx@REDACTED
Fri Jan 16 21:30:20 CET 2004
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
More information about the erlang-questions
mailing list