Author Topic: Print the name of a variable  (Read 2184 times)

0 Members and 1 Guest are viewing this topic.

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Print the name of a variable
« on: March 13, 2009, 10:00:50 AM »
I'm trying to write myself a little variable tester routine

The idea is to have something like
<CODE(DEFUN returnvars ( var / )
   (SETQ varname (EVAL var));'var)
   (PRINC "\nvar name:")
   (PRINC varname)
   (PRINC "\nvar value:")
   (PRINC var)
   (PRINC)
)
</CODE>

so that I can stick a
<CODE>(RETURNVARS start)</CODE>

in my code, to have to be equivilent to:
<CODE>(PRINC "\nstart:")(PRINC start)</CODE>

Not really important, but it would make my life a wee bit easier!

===
dJE
===
dJE

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Print the name of a variable
« Reply #1 on: March 14, 2009, 01:30:44 AM »
Code: [Select]
(DEFUN returnvars ( var / )
  (alert (strcat
           "var name: " (vl-princ-to-string var)
           "\nvar value: " (vl-princ-to-string (eval var))
           "\nvar Type: " (vl-princ-to-string  (type (eval var))))
         )
  )

;;TEST
(vl-load-com)
(setq start 32.4)
(returnvars 'start)
« Last Edit: March 14, 2009, 01:34:22 AM by Andrea »
Keep smile...

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Re: Print the name of a variable
« Reply #2 on: March 18, 2009, 09:58:30 AM »
Sorry I've taken so long to get back to you on this, Andrea, but that's spot on, thankyou.

dJE
===
dJE