William James
11/28/2015 10:32:00 PM
WJ wrote:
> Kenny Tilton wrote:
>
> > (defun sum-g-adic-l (g lst)
> > (float (loop for a_i in lst
> > for g^i = 1 then (* g g^i)
> > summing (/ a_i g^i))))
> >
> > It's not any more functional under the hood, but it looks more
> > functional, and as Andre Agassi said, image is everything.
> >
> > This works, too:
> >
> > (defun sum-g-adic (g lst &optional (g^i 1)(accum 0.0))
> > (if lst
> > (sum-g-adic g (rest lst) (* g g^i) (+ accum (/ (car lst) g^i)))
> > accum))
>
> Gauche Scheme:
>
> (use gauche.collection :only (fold2))
>
> (define (sum-g-adic-l g lst)
> (fold2
> (^(a_i sum g_i) (values (+ sum (/ a_i g_i)) (* g_i g)))
> 0.0 1.0
> lst))
>
>
> (sum-g-adic-l 3.3 '(2 4 5 9 88))
> ===>
> 4.663735611394014
> 391.35392999999993
Ocaml:
let sum_g_adic g lst =
let rec loop g_i accum = function
[] -> (accum, g_i)
| a_i::xs -> loop (g *. g_i) (accum +. (a_i /. g_i)) xs
in loop 1.0 0.0 lst ;;
sum_g_adic 3.3 [2.;4.;5.;9.;88.] ;;
(4.6637356113940136, 391.35392999999993)
--
Sahlin [stressed] that her compatriots must accept that the new Sweden is
multi-cultural.... "Like it or not, this is the new Sweden."
fjordman.blogspot.ca/2005/05/is-swedish-democracy-collapsing.html