[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

On procedures within procedures

From: Mike Gran
Subject: On procedures within procedures
Date: Wed, 3 Apr 2013 07:04:43 -0700 (PDT)

I've been looking over one of the solutions to a Guile 100 problem
(a basic version of the `ls' command) at the link below.  It is
interesting stylistically because it works very hard at minimizing the
scope of procedures.  It uses a lot of procedures within procedures,
like, for example, within a `let*' block.

For example
(define (outer-function x)
(lambda (b . M)
(let ((m (fold logior 0 M)))
(eq? m (logand b m)))))

Personally, I only define a procedure within a procedure if the
inner procedure is not a pure function, e.g. if its result
depends on information other than its parameters, and that
information only exists within the scope of the outer procedure.
I tend to keep most pure functions at the module level. But,
I'm not a very Schemey guy.

One could look at using lots of procedures within procedures as good
defensive programming style: hiding unnecessary functions.

Or one could look at it as being less clear because you end up with
longer "paragraphs" to read.

Do you have a personal philosophy on how much you try to minimize
the scope of procedures?  If you were writing a tutorial,
what would you say?

-Mike Gran

reply via email to

[Prev in Thread] Current Thread [Next in Thread]