From: Venkat
Subject: Display all global variables.........
Date: 
Message-ID: <6f4d9f70.0404050508.41d81c83@posting.google.com>
Hi,

Is there any way to display all the global variables and their values.
Like if I loose track of how many variables I have what should I do?

Thanks
tvr1729

From: Matthieu Villeneuve
Subject: Re: Display all global variables.........
Date: 
Message-ID: <407160ef$0$12812$626a14ce@news.free.fr>
"Venkat" <·······@yahoo.com> wrote in message
·································@posting.google.com...
> Is there any way to display all the global variables and their values.

You may want to use DO-SYMBOLS:

  (do-symbols (s)
    (when (boundp s)
      (format t "~A => ~A~%" s (symbol-value s))))


--
Matthieu Villeneuve
From: Luke Gorrie
Subject: Re: Display all global variables.........
Date: 
Message-ID: <lh4qryb5cp.fsf@dodo.bluetail.com>
"Matthieu Villeneuve" <·····················@freeDOTfr> writes:

> "Venkat" <·······@yahoo.com> wrote in message
> ·································@posting.google.com...
>> Is there any way to display all the global variables and their values.
>
> You may want to use DO-SYMBOLS:
>
>   (do-symbols (s)
>     (when (boundp s)
>       (format t "~A => ~A~%" s (symbol-value s))))

You might want to exclude imported symbols:

  (defun my-variables (&optional (package *package*))
    "Print the values of all bound variables in a package (the current one by default.)"
    (do-symbols (sym package) 
      (when (and (boundp sym)
                 (eq (symbol-package sym) package))
        (format t "~&~S = ~S~%" sym (symbol-value sym)))))

  (my-variables)
From: Pascal Costanza
Subject: Re: Display all global variables.........
Date: 
Message-ID: <c4set6$6jf$1@newsreader2.netcologne.de>
Luke Gorrie wrote
:
> You might want to exclude imported symbols:
> 
>   (defun my-variables (&optional (package *package*))
>     "Print the values of all bound variables in a package (the current one by default.)"
>     (do-symbols (sym package) 
>       (when (and (boundp sym)
>                  (eq (symbol-package sym) package))
>         (format t "~&~S = ~S~%" sym (symbol-value sym)))))
> 
>   (my-variables)

You mean:

(loop for sym being the present-symbols of *package*
       when (boundp sym)
       do (format t "~&~S = ~S~%" sym (symbol-value sym)))

;)


Pascal

-- 
1st European Lisp and Scheme Workshop
June 13 - Oslo, Norway - co-located with ECOOP 2004
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
From: Thomas F. Burdick
Subject: Re: Display all global variables.........
Date: 
Message-ID: <xcvisgby351.fsf@famine.OCF.Berkeley.EDU>
Pascal Costanza <········@web.de> writes:

> Luke Gorrie wrote
> :
> > You might want to exclude imported symbols:
> > 
> >   (defun my-variables (&optional (package *package*))
> >     "Print the values of all bound variables in a package (the current one by default.)"
> >     (do-symbols (sym package) 
> >       (when (and (boundp sym)
> >                  (eq (symbol-package sym) package))
> >         (format t "~&~S = ~S~%" sym (symbol-value sym)))))
> > 
> >   (my-variables)
> 
> You mean:
> 
> (loop for sym being the present-symbols of *package*
>        when (boundp sym)
>        do (format t "~&~S = ~S~%" sym (symbol-value sym)))
> 
> ;)

For the sake of completeness, these only note your bound variables,
not any globally special variables you might have that are unbound.

  (defun specialp (symbol)
    (eval
     `(let ((thunk (let ((,symbol nil))
                     (lambda () ,symbol))))
        (let ((,symbol t))
          (funcall thunk)))))

  (loop for sym being the present-symbols of *package*
        if (boundp sym)
          do (format t "~&~S = ~S~%" sym (symbol-value sym))
        else if (specialp sym)
          do (format t "~&~S is an unbound special variable.~%" sym))

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Andrew Philpot
Subject: Re: Display all global variables.........
Date: 
Message-ID: <slrnc78qu0.hnv.philpot@blombos.isi.edu>
In article <···············@famine.OCF.Berkeley.EDU>, Thomas F. Burdick wrote:

> For the sake of completeness, these only note your bound variables,
> not any globally special variables you might have that are unbound.
> 
>   (defun specialp (symbol)
>     (eval
>      `(let ((thunk (let ((,symbol nil))
>                      (lambda () ,symbol))))
>         (let ((,symbol t))
>           (funcall thunk)))))
> 
>   (loop for sym being the present-symbols of *package*
>         if (boundp sym)
>           do (format t "~&~S = ~S~%" sym (symbol-value sym))
>         else if (specialp sym)
>           do (format t "~&~S is an unbound special variable.~%" sym))
> 

I like this trick but I did find an edge case:

CL-USER(38): (specialp '*macroexpand-hook*)
Error: Funcall of NIL which is a non-function.
  [condition type: SIMPLE-ERROR]

Restart actions (select using :continue):
 0: Return to Top Level (an "abort" restart).
 1: Abort entirely from this process.
[1] CL-USER(39): 

Andrew
From: Kalle Olavi Niemitalo
Subject: Re: Display all global variables.........
Date: 
Message-ID: <87zn9n3q2s.fsf@Astalo.kon.iki.fi>
Andrew Philpot <·······@isi.edu> writes:

> I like this trick but I did find an edge case:
>
> CL-USER(38): (specialp '*macroexpand-hook*)
> Error: Funcall of NIL which is a non-function.
>   [condition type: SIMPLE-ERROR]

Consider also (specialp 'nil), which you could handle with
CONSTANTP; or (specialp '*read-base*), where an implementation
could conceivably enforce that the value is indeed a radix.

Should I ever need to check whether a symbol has been proclaimed
as a special variable (independently of whether it is BOUNDP),
I think I'd prefer implementation-specific code over this trick.
It is in general not OK to bind a special variable if you don't
know how it's used.
From: Kalle Olavi Niemitalo
Subject: Re: Display all global variables.........
Date: 
Message-ID: <87wu4qgaw6.fsf@Astalo.kon.iki.fi>
Kalle Olavi Niemitalo <···@iki.fi> writes:

> Consider also (specialp 'nil), which you could handle with
> CONSTANTP; or (specialp '*read-base*), where an implementation
> could conceivably enforce that the value is indeed a radix.

On third thought, (specialp '*compile-file-pathname*) may be
a better example.  "The consequences are unspecified if an
attempt is made to assign or bind either of these variables."
From: Thomas F. Burdick
Subject: Re: Display all global variables.........
Date: 
Message-ID: <xcv4qrub4i6.fsf@famine.OCF.Berkeley.EDU>
Andrew Philpot <·······@isi.edu> writes:

> In article <···············@famine.OCF.Berkeley.EDU>, Thomas F. Burdick wrote:
> 
> > For the sake of completeness, these only note your bound variables,
> > not any globally special variables you might have that are unbound.
> > 
> >   (defun specialp (symbol)
> >     (eval
> >      `(let ((thunk (let ((,symbol nil))
> >                      (lambda () ,symbol))))
> >         (let ((,symbol t))
> >           (funcall thunk)))))
> > 
> >   (loop for sym being the present-symbols of *package*
> >         if (boundp sym)
> >           do (format t "~&~S = ~S~%" sym (symbol-value sym))
> >         else if (specialp sym)
> >           do (format t "~&~S is an unbound special variable.~%" sym))
> > 
> 
> I like this trick but I did find an edge case:
> 
> CL-USER(38): (specialp '*macroexpand-hook*)
> Error: Funcall of NIL which is a non-function.
>   [condition type: SIMPLE-ERROR]

Yeah, it's obviously not the kind of thing you can do on the
implementation itself.  Outside of implementation packages, it should
be fine (except on SBCL); it's definately a dirty trick, though.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'