Hopefully simple problem

chris.danx chris.danx@REDACTED
Fri Jan 16 21:30:20 CET 2004


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...

-export([bfunc/2, xfunc/2]).

bfunc (X, Y) ->

xfunc (X, Y) ->
     X + Y.



neuron(State, ActFunc, CombineFunc, ConnList) ->
     proc_lib:spawn (nnet, nloop, [{State, ActFunc, CombineFunc, 

% 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, []}) ->
	{nInput, Val} ->
	    X = CombineStateFunc (State, Val),
	    Y = ActFunc (X, []),
	    nloop ({Y, ActFunc, CombineStateFunc, []});
	{addConn, C} ->
	    nloop ({State, ActFunc, CombineStateFunc, [C]})	
nloop({State, ActFunc, CombineStateFunc, Conns}) when is_list (Conns) ->
	{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)})

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?


More information about the erlang-questions mailing list