From: upperclass
Subject: function from string
Date: 
Message-ID: <1177610768.968679.46730@o40g2000prh.googlegroups.com>
Hi,

How do I get the value of the function from a string of the function
name.
For example,

if I load my-fun from a file, then, I have access to the string "my-
fun".
How do I convert this to #'my-fun so that I can use it as an argument
to another function.
The thing is, in general, I do not know the name of the function to be
used. However, this name can be obtained by reading a file.

Thank you.

From: Ken Tilton
Subject: Re: function from string
Date: 
Message-ID: <s26Yh.456$fG7.175@newsfe12.lga>
upperclass wrote:
> Hi,
> 
> How do I get the value of the function from a string of the function
> name.
> For example,
> 
> if I load my-fun from a file, then, I have access to the string "my-
> fun".
> How do I convert this to #'my-fun so that I can use it as an argument
> to another function.
> The thing is, in general, I do not know the name of the function to be
> used. However, this name can be obtained by reading a file.
> 
> Thank you.
> 

e.g.: (funcall (intern "GET-INTERNAL-REAL-TIME"))

hth, kt

-- 
http://www.theoryyalgebra.com/

"Algebra is the metaphysics of arithmetic." - John Ray

"As long as algebra is taught in school,
there will be prayer in school." - Cokie Roberts

"Stand firm in your refusal to remain conscious during algebra."
    - Fran Lebowitz

"I'm an algebra liar. I figure two good lies make a positive."
    - Tim Allen
From: Frank Buss
Subject: Re: function from string
Date: 
Message-ID: <b6fcc8uhaysi.ev7ykwhevdlp$.dlg@40tude.net>
upperclass wrote:

> How do I get the value of the function from a string of the function
> name.

(symbol-function (intern (string-upcase "my-fun")))

-- 
Frank Buss, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Thomas A. Russ
Subject: Re: function from string
Date: 
Message-ID: <ymiwszxxrfe.fsf@sevak.isi.edu>
upperclass <··········@gmail.com> writes:

> Hi,
> 
> How do I get the value of the function from a string of the function
> name.
> For example,
> 
> if I load my-fun from a file, then, I have access to the string "my-
> fun".

Well, if you do it right, you won't use a string, but you will already
have a symbol.

> How do I convert this to #'my-fun so that I can use it as an argument
> to another function.

You might not need to convert it at all.  Passing the symbol itself may
be sufficient:

(funcall #'+ 3 5)                     =>  8
(funcall '+  3 5)                     =>  8
(funcall (intern "+") 3 5)            =>  8
(funcall (read-from-string "+") 3 5)  => 35   (just kidding, it's 8)


> The thing is, in general, I do not know the name of the function to be
> used. However, this name can be obtained by reading a file.

If you are reading the file, then read the name as a symbol using
something like READ instead of as a string with READ-LINE.  In general,
if you want to send configuration information into your lisp program, it
is easier to do it using lisp data structures like symbols and
s-expressions so that you can have the lisp reader parse things for
you.

Since you presumably have control over the file you read to get the name
this should be easy to do.

> 
> Thank you.
> 


-- 
Thomas A. Russ,  USC/Information Sciences Institute