Fun, fun, Funs?
Robert Virding
rv@REDACTED
Thu Sep 28 11:18:16 CEST 2000
Andy with Recycled Electrons <aba3600@REDACTED> writes:
>Hi...
>
>I'm trying to write a procedure to map a fun down a list...
>
>Can anyone tell me how this differs from the book?
>
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>215: f(Num, Mean) -> (Num - Mean)*(Num - Mean).
>216:
>217: Sub = fun f/1.
>218: %
>219:
>220: getVariance(List)
>221: %
>222: %
>223: ->
>224: sumList( lists:map(Sub, List) ).
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>I get errors:
>./poedt.erl:217: syntax error before: Sub
>./poedt.erl:224: variable 'Sub' is unbound
>./poedt.erl:224: function sumList/1 undefined
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The problem is that in code modules variables cannot exist outside of
functions, you can only define functions. Also the function f takes
two arguments so f/1 does not exist. This means you cannot apply it
every element of the list as it stands. The best would be to fold the
map and sumList into a fold.
Robert
--
Robert Virding Tel: +46 (0)8 545 55 017
Bluetail AB Email: rv@REDACTED
S:t Eriksgatan 44 WWW: http://www.bluetail.com/~rv
SE-112 32 Stockholm, SWEDEN
"Folk säger att jag inte bryr mig om någonting, men det skiter jag i".
More information about the erlang-questions
mailing list