unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to distinguish gobal and local variables in elisp?
@ 2006-09-21 18:09 jronald
  2006-09-21 18:54 ` Pascal Bourguignon
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jronald @ 2006-09-21 18:09 UTC (permalink / raw)


The question comes from setq.
Usually, setq appears in a file without in any parentheses.
Does it mean that it awlays set the global varaible then? Or what's a local 
variable in lisp?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to distinguish gobal and local variables in elisp?
  2006-09-21 18:09 How to distinguish gobal and local variables in elisp? jronald
@ 2006-09-21 18:54 ` Pascal Bourguignon
  2006-09-21 19:51 ` Kevin Rodgers
  2006-09-21 20:13 ` Xavier Maillard
  2 siblings, 0 replies; 4+ messages in thread
From: Pascal Bourguignon @ 2006-09-21 18:54 UTC (permalink / raw)


"jronald" <followait@163.com> writes:

> The question comes from setq.
> Usually, setq appears in a file without in any parentheses.

Still not.
Here is a short example:
$ grep setq .emacs|grep -v -e '^ *;'|head -20
(setq default-enable-multibyte-characters      t
(setq my-latin (if (assoc-ignore-case "Latin-9" language-info-alist) 9 1))
  ((= my-latin 1) (setq my-lenv     "Latin-1"
  ((= my-latin 9) (setq my-lenv     "Latin-9"
(setq sendmail-coding-system           my-encoding
(setq inhibit-default-init t)
            (setq file (concat site-lisp "/" file))
(setq load-path
(setq x-toolkit-scroll-bars nil)
   (setq *window-manager-y-offset* (+ 24 24))
   (setq mac-command-key-is-meta t
        (lambda (item) (setq *font-current-node* (cdr item))) t nil
        (lambda (item) (setq *font-current-node* (cdr item))) t nil
        (lambda (item) (setq *font-current-node* (cdr item))) t nil
        (lambda (item) (setq *font-current-node* (cdr item))) t nil
         (setq palette            pal-thalassa
         (setq palette            pal-larissa
         (setq palette            pal-naiad
         (setq palette            pal-naiad
         (setq palette            pal-lassel

See?  There are a lot of parentheses.  setq DOES NOT appears in a file
without any parentheses.

So, since you start from a false assumption, we don't know if we speak
the same language, even thought we're using the same words.  

Have you read more of the emacs lisp introduction I advised you to read?



> Does it mean that it awlays set the global varaible then? Or what's a local 
> variable in lisp?

In lisp, a local variable is one that is bound locally. 
For example:

(defvar *global-variable* 1)

(let ((local-variable 2))
   (print (list *global-variable* local-variable)))

*global-variable* is a global variable.
local-variable is a local variable.


Now, if what you want to know is how to distinguish buffer-local
variables in emacs lisp, that's something else.

But note the differences:

    lisp              <-->    emacs lisp
    local variable    <-->    buffer-local variables

Buffer-local variables are specific to emacs lisp. However, in emacs
lisp there are also local variables, like in any other lisp.




In emacs, apart from the user and programmer manuals accessible by info
    C-h i d m emacs RET
    C-h i d m emacs lisp intro RET
    C-h i d m elisp RET

you can find information about variables, functions etc using various
commands such as:
    C-h f                     describe-function
    C-h v                     describe-variable
    M-x apropos 

For example, M-x apropos RET local.*variable RET
will give you a list of functions and variables concerned by local variables.
The first result is:

buffer-local-variables
  Function: Return an alist of variables that are buffer-local in BUFFER.

So this gives you an easy way to find what you want, even not knowing
anything.

(mapcar (function car) (buffer-local-variables))

If you read more of the apropos results, you could encounter the
function local-variable-p  that will tell you if a symbol is the name
of a buffer local variable.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to distinguish gobal and local variables in elisp?
  2006-09-21 18:09 How to distinguish gobal and local variables in elisp? jronald
  2006-09-21 18:54 ` Pascal Bourguignon
@ 2006-09-21 19:51 ` Kevin Rodgers
  2006-09-21 20:13 ` Xavier Maillard
  2 siblings, 0 replies; 4+ messages in thread
From: Kevin Rodgers @ 2006-09-21 19:51 UTC (permalink / raw)


jronald wrote:
> The question comes from setq.
> Usually, setq appears in a file without in any parentheses.
> Does it mean that it awlays set the global varaible then? Or what's a local 
> variable in lisp?

Emacs Lisp is dynamically scoped (like most older Lisp dialects, and 
unlike most newer dialects).  That means that a variable may be
referenced outside the lexical scope that declares it.  For example:

(setq foo 0)

;; At this point, foo has only a global binding, to 0.

(defun bar ()
   (setq foo 2))

;; When bar is called, it will update foo's global binding, unless it is
;; shadowed by a local binding.

(let ((foo 1))
   ;; For the duration of the let form, foo also has a local binding.
   ;; At this point, its local value is 1.
   (bar)
   ;; Now foo's local value is 2, but its global value is still 0.
   )

;; And now only the global binding exists, so foo's value is 0.

-- 
Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to distinguish gobal and local variables in elisp?
  2006-09-21 18:09 How to distinguish gobal and local variables in elisp? jronald
  2006-09-21 18:54 ` Pascal Bourguignon
  2006-09-21 19:51 ` Kevin Rodgers
@ 2006-09-21 20:13 ` Xavier Maillard
  2 siblings, 0 replies; 4+ messages in thread
From: Xavier Maillard @ 2006-09-21 20:13 UTC (permalink / raw)
  Cc: help-gnu-emacs


  On Friday, 22 September 2006, jronald wrote:
> The question comes from setq.
> Usually, setq appears in a file without in any parentheses.
> Does it mean that it awlays set the global varaible then? Or what's a local 
> variable in lisp?

I think you should try to look into the elisp manual:

(info "(elisp)Variables")

Regards
-- 
Cheers Xavier

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-09-21 20:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-21 18:09 How to distinguish gobal and local variables in elisp? jronald
2006-09-21 18:54 ` Pascal Bourguignon
2006-09-21 19:51 ` Kevin Rodgers
2006-09-21 20:13 ` Xavier Maillard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).