From: Darmac
Subject: Function execution
Date: 
Message-ID: <1113571276.651385.300810@z14g2000cwz.googlegroups.com>
Hi, can I execute a function that is inside a string?
For example:

> (setq sum "+")
> (funcall sum 1 2)

Obviously this not work, but that's the idea...

Thanks in advance.

Darío Macchi

From: Sam Steingold
Subject: Re: Function execution
Date: 
Message-ID: <u8y3kmaqf.fsf@gnu.org>
> * Darmac <········@tznvy.pbz> [2005-04-15 06:21:16 -0700]:
>
> Hi, can I execute a function that is inside a string?
> For example:
>
>> (setq sum "+")
>> (funcall sum 1 2)

(funcall (or (find-symbol sym) (error "no such symbol: ~S" sum))
         1 2)

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://pmw.org.il/> <http://www.iris.org.il> <http://www.dhimmi.com/>
<http://www.palestinefacts.org/> <http://www.openvotingconsortium.org/>
Never underestimate the power of stupid people in large groups.
From: Pascal Costanza
Subject: Re: Function execution
Date: 
Message-ID: <3c9u0hF6l2ptpU1@individual.net>
Darmac wrote:
> Hi, can I execute a function that is inside a string?
> For example:
> 
>>(setq sum "+")
>>(funcall sum 1 2)

You can use find-symbol to find the symbol that a function is associated 
with it. funcall takes either a function or a symbol as its first 
argument (or setf function name).

> Obviously this not work, but that's the idea...

What you want seems very strange and looks like you're trying to solve a 
problem with the wrong means. What is the more general problem you are 
trying to solve?


Pascal

-- 
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
From: Darmac
Subject: Re: Function execution
Date: 
Message-ID: <1113573314.491713.227980@f14g2000cwb.googlegroups.com>
Thanks for your answers...
PascaI, I'm doing a little programming languaje for common tasks based
on xml. For that reason I need to read the xml (string) and then when
the parser found a function it have to execute it.

I think that with this material I will complete this.

Thanks again.
From: Pascal Costanza
Subject: Re: Function execution
Date: 
Message-ID: <3ca06oF6mbdpgU1@individual.net>
Darmac wrote:
> Thanks for your answers...
> PascaI, I'm doing a little programming languaje for common tasks based
> on xml. For that reason I need to read the xml (string) and then when
> the parser found a function it have to execute it.
> 
> I think that with this material I will complete this.

OK. This sounds like you are writing an interpreter for that xml 
language. You may also want to consider writing a transformer from that 
language to s-expressions and then feed the Lisp compiler with the 
resulting expression. This may be simpler code and may give you better 
efficiency. (But that's pure speculation, of course.)


Pascal

-- 
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
From: Darmac
Subject: Re: Function execution
Date: 
Message-ID: <1113574441.020585.6610@o13g2000cwo.googlegroups.com>
Can you show me an example of this?

Maybe it help me...
(I'm always taking care of the efficiency)

Thanks.
From: Pascal Costanza
Subject: Re: Function execution
Date: 
Message-ID: <3ccfn9F6nsii3U1@individual.net>
Darmac wrote:
> Can you show me an example of this?
> 
> Maybe it help me...
> (I'm always taking care of the efficiency)

You are asking for help with regard to reading XML and interpreting it 
as a program. I have suggested to consider converting XML to 
s-expressions and then compiling them. (Just to make the context clear. 
Please cite parts of previous postings, so that it's easier for readers 
to understand what we are talking about.)

Check out the function COMPILE, for example in the HyperSpec. One way to 
use it is to pass nil as the first and a lambda expression as the second 
parameter. That lambda expression can be a quoted one, for example:

(compile nil '(lambda () (print "Hello, World!")))

This means that the second parameter can be an s-expression that is 
determined at runtime, including for example the result of a 
transformation from XML.


Pascal

-- 
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
From: Darmac
Subject: Re: Function execution
Date: 
Message-ID: <1113574475.689847.158230@f14g2000cwb.googlegroups.com>
Can you show me an example of this?

Maybe it help me...
(I'm always taking care of the efficiency)

Thanks.
From: Kent M Pitman
Subject: Re: Function execution
Date: 
Message-ID: <uoecf7ou9.fsf@nhplace.com>
Pascal Costanza <··@p-cos.net> writes:

> Darmac wrote:
> > Thanks for your answers...
> > PascaI, I'm doing a little programming languaje for common tasks based
> > on xml. For that reason I need to read the xml (string) and then when
> > the parser found a function it have to execute it.
> > I think that with this material I will complete this.
> 
> OK. This sounds like you are writing an interpreter for that xml
> language. You may also want to consider writing a transformer from
> that language to s-expressions and then feed the Lisp compiler with
> the resulting expression. This may be simpler code and may give you
> better efficiency. (But that's pure speculation, of course.)

You should also definitely consider the case of proper namespacing,
since you want to both not find accidental symbols in Lisp that should
not be exposed to XML and also not look in the wrong place for
namespace-marked stuff in XML.  foo:x is not managed properly by doing
(find-symbol "foo:x") but rather something more akin to (find-symbol
"foo" (package-for-xml-namespace "foo")) where you have to define what
package-for-xml-namespace does, since there are various options.
From: Barry Margolin
Subject: Re: Function execution
Date: 
Message-ID: <barmar-D89A4F.20142115042005@comcast.dca.giganews.com>
In article <························@f14g2000cwb.googlegroups.com>,
 "Darmac" <········@gmail.com> wrote:

> Thanks for your answers...
> PascaI, I'm doing a little programming languaje for common tasks based
> on xml. For that reason I need to read the xml (string) and then when
> the parser found a function it have to execute it.
> 
> I think that with this material I will complete this.
> 
> Thanks again.

I would recommend a hash table that maps from the strings to the 
corresponding functions.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***