POV-Ray : Newsgroups : povray.off-topic : GIMP hotkeys/ scripts/ user-defined functions? : Re: GIMP hotkeys/ scripts/ user-defined functions? Server Time
6 Sep 2024 21:23:18 EDT (-0400)
  Re: GIMP hotkeys/ scripts/ user-defined functions?  
From: nemesis
Date: 10 Dec 2008 11:18:48
Message: <493febe8@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.