On 2009-02-27 06:02 (-0800), Tom wrote:

> I suppose you're referring to the standard let form in lisp? Something
> like:
>
>     (let ((foo 1))
>       (+ foo 2))
>
> The point is though that emacs with its dynamic scoping embraces the
> possibility that users adapt libraries to their likings and nothing is
> hidden from them.

Not being a native English speaker I have to admit that I don't quite
understand what you mean by your last sentence, but yes, Emacs Lisp has
dynamic scoping.

    (defun my-function ()
      foo) ;return the value of "foo"

    (let ((foo 123))
      (my-function))

    => 123

"my-function" is called inside the "let" form. The function will see
variable "foo" and its value "123", and it returns it. If "my-function"
had its own "let" form to bind variable "foo" then it would create its
own local "foo" and it won't affect any other "foo" variables that might
exist. Functions' parameters are similar to "let" bindings.

    (defun my-function (&optional foo)
      ;; "foo" has local binding here
      foo) ;return the value of "foo"

    (let ((foo 123))
      (my-function))

    => nil

I don't know how widely dynamic scoping is actually utilized in Emacs
code. But there is one good example in Emacs Lisp manual. Variable
"case-fold-search" is similar to Vim's 'ignorecase' in meaning.
Searching commands refer to it. It has a global value but obviously can
be bound buffer-locally or function-locally or "let"-locally. Like this:

    (let ((case-fold-search t))
      ;; We ignore case inside this form.
      ;; The global value is untouched.
      (re-search-forward "regexp"))

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to