[Top][All Lists]

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

Re: question on elisp best practive

From: Barry Margolin
Subject: Re: question on elisp best practive
Date: Wed, 10 Oct 2007 02:22:38 -0400
User-agent: MT-NewsWatcher/3.5.2 (PPC Mac OS X)

In article <address@hidden>,
 Aemon <address@hidden> wrote:

> Hi all,
> I've got a lot of code that traverses trees and does something at
> every node. I'd like to abstract the traversal part of the code, and
> just pass in the bit that does the action. Something like:
> (defun visit-each (tree func depth)
>   (funcall func tree depth)
>   (dolist (ea (tree-children tree))
>     (visit-each ea (+ 1 depth))))
> This seems to work pretty well, called like so:
> (visit-each my-tree
>           (lambda (subtree depth)
>             (message "%s %s" subtree depth)))
> However, as it's not a closure I'm passing in, I would get into
> trouble if I tried:
> (visit-each my-tree
>           (let ((depth "my depth"))
>             (lambda (subtree)
>               (message "%s %s" subtree depth))))
> Elisp's dynamic scope would cause my local binding of 'depth' -> "my
> depth" to always be shadowed.

Does it work if you use lexical-let instead of let?

Barry Margolin, address@hidden
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

reply via email to

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