<Smerdyakov>
So? You are calling entr_elem on the accumulator, too, and no one but you can have any idea what result that will produce.
<hsfb>
oh, i see.. i'm doing entr_elem "as i go"
<hsfb>
not on each element first, then summing
<Smerdyakov>
I'm not sure what you mean, but it sounds like your code is doing something more complicated than you want.
<Smerdyakov>
Also, the parentheses around the operands of +. are superfluous.
<hsfb>
ok...
<hsfb>
yeah, this solves the problem.. let entropy l = sum (List.map entr_elem l);; but it seems that i _should_ be able to use fold to solve it in just one pass
<hsfb>
tks anyway
<Smerdyakov>
Of course you can.
<Smerdyakov>
Just try evaluating your old definition on short lists manually, and you'll see the problem.
<Smerdyakov>
(You should do this in general whenever you get stuck, before asking for help.)
<hsfb>
Ok, i'll do that... are you brazilian or portuguese speaking ?
<Smerdyakov>
No.
foucault has joined #ocaml
pantsd has joined #ocaml
<hsfb>
Smerdyakov: let entropy l = List.fold_right (fun x y -> (entr_elem x) +. y) l 0.0;;
<hsfb>
<xavierbot>
Characters 5-12:
<xavierbot>
Smerdyakov: let entropy l = List.fold_right (fun x y -> (entr_elem x) +. y) l 0.0;;
<xavierbot>
^^^^^^^
<xavierbot>
Unbound value entropy
<xavierbot>
Characters 11-12:
<xavierbot>
Parse error: illegal begin of top_phrase
<pango>
xavierbox, sleep
<hsfb>
is there a shortcut for writing this type of definition ? its probably a common pattern
<pango>
xavierbot, sleep
<xavierbot>
xavierbot goes to sleep (do 'xavierbot wake' to wake)
<hsfb>
pango: tks, that was my next question
<Smerdyakov>
hsfb, try to write your own "shortcut" as an exercise. :)
<hsfb>
you mean camlp4?
bluestorm_ has quit [Remote closed the connection]
<Smerdyakov>
hsfb, no, I mean by writing your own higher-order function.
<Smerdyakov>
hsfb, and, don't forget, you are still using extraneous parentheses around the first +, operand there....
<hsfb>
i'll watch that.. too much elisp is bad for your camel
<hsfb>
Tks again!
foucault has quit [Remote closed the connection]
<pango>
hsfb: have you a special reason for using fold_right? Only fold_left implementation is tail recursive...
<hsfb>
swapping
<hsfb>
i remember one of you is the author from m3ga blog