From: Yang, Hon-Jang
Subject: How to get symbol-value from symbol-name
Date: 
Message-ID: <39A0A5A4.69ACD4AB@math.ntu.edu.tw>
1. I need a function with
       input st :           where st is a symbol-name of some symbol
       output:              symbol-value of the symbol with symbol-name
st
2. Suppose f is an lisp function written by lisp scouce, how to get the
lisp source code of f?

Thanks.

HJY

From: David Bakhash
Subject: Re: How to get symbol-value from symbol-name
Date: 
Message-ID: <m3itsvch54.fsf@cadet.dsl.speakeasy.net>
"Yang, Hon-Jang" <······@math.ntu.edu.tw> writes:

> 1. I need a function with
>        input st :           where st is a symbol-name of some symbol
>        output:              symbol-value of the symbol with symbol-name
> st

There is a function called SYMBOL-VALUE, but it's not necessarily what 
you want.  Consult the Common Lisp HyperSpec, which you can link to
from:

http://www.xanalys.com

> 2. Suppose f is an lisp function written by lisp scouce, how to get the
> lisp source code of f?

Well, there's a function that will sometimes give you what you want,
called FUNCTION-LAMBDA-EXPRESSION.  You invoke it like this:

[example in clisp]

USER(1): (defun f (x) (* x x))
F
USER(2): (function-lambda-expression #'f)

(LAMBDA (X) (BLOCK F (* X X)))
NIL
F
USER(3):

dave
From: Erik Naggum
Subject: Re: How to get symbol-value from symbol-name
Date: 
Message-ID: <3175845640611549@naggum.net>
* "Yang, Hon-Jang" <······@math.ntu.edu.tw>
| 1. I need a function with
|        input st :           where st is a symbol-name of some symbol
|        output:              symbol-value of the symbol with symbol-name st

  The symbol with a given name is returned by find-symbol.  (Remember
  to get the package and case conversions right.)

| 2. Suppose f is an lisp function written by lisp scouce, how to get the
| lisp source code of f?

  You cannot easily go from function to function name.  If you have
  the name, use the source code system in your Lisp system to direct
  the editor to locate the source code for that function.

#:Erik
-- 
  If this is not what you expected, please alter your expectations.
From: Will Mengarini
Subject: Re: How to get symbol-value from symbol-name
Date: 
Message-ID: <8nrf0j$m0d$1@eskinews.eskimo.com>
"Yang, Hon-Jang" <······@math.ntu.edu.tw> writes:

>1. I need a function with
>   input st[ring]:   where st[ring] is a symbol-name of some symbol
>   output:           symbol-value of [that symbol]

(defun value-of-symbol-named (name)
  (symbol-value (read-from-string name)))

Note (intern name) would often fail unless
(eq (readtable-case *readtable*) :preserve).

I assume you're not messing with packages.  If the symbol might be
in some other package than the current package, and you know
which one, surround the function body with a let-binding of *package*.
If you don't know which one, you'll need to use #'find-all-symbols,
which will require messing with #'readtable-case as well (and of course
you'll need to have some strategy for dealing with occurrences of the
same name in multiple packages).  Example of #'readtable-case usage:

(defun value-of-symbol-named (name)
  (symbol-value (find-symbol (funcall (ecase (readtable-case *readtable*)
                                        (:upcase   #'string-upcase)
                                        (:downcase #'string-downcase)
                                        (:preserve #'identity))
                                      name))))

                 Will Mengarini  <······@eskimo.com>
         Free software: the Source will be with you, always.
From: Yang, Hon-Jang
Subject: Re: How to get symbol-value from symbol-name
Date: 
Message-ID: <39A1FD20.E0A1F15E@math.ntu.edu.tw>
I have got the answers:

problem 1.

> (def a 72)
A
>(symbol-value(read-from-string "A"))
72


problem 2.

> (defun f (x) (^ x 2))
F
> (function-lambda-expression #'f)
(LAMBDA (X) (^ X 2))
NIL
F

Thanks to David Bakhash <·····@alum.mit.edu>,
       Erik Naggum <····@naggum.net>,
       ······@eskimo.com (Will Mengarini)


HJY