Invisible escreveu:
>> Not so much that, but rather the deep nesting that gets to me..
You can break down in separate procedures/functions if you prefer. But
deep nesting with anonymous functions is a hallmark of functional
languages...
> This is why Haskell allows you to take
>
> foo1(foo2(foo3(foo4(foo5(foo6(x))))))
>
> and rewrite it as
>
> foo1 $ foo2 $ foo3 $ foo4 $ foo5 $ foo6 x
Haven't we gone through this before?
(define (compose f g . fs)
(if (null? fs) (lambda (x) (f (g x)))
(apply compose (lambda (x) (f (g x))) (car fs) (cdr fs))))
(define o compose)
(define (inc n) (+ 1 n))
(define (sqr n) (* n n))
(o inc sqr inc) ; returns a procedure, which you may store somewhere and
later reuse
((o inc sqr inc) 3) ; applies the procedure to argument 3
so, you're example would be:
((o foo1 foo2 foo3 foo4 foo5 foo6) x)
foo1 $ foo2 $ foo3 $ foo4 $ foo5 $ foo6 x
whoa! It's shorter! ;)
Post a reply to this message
|