From: Josef Eschgfaeller
Subject: strings
Date: 
Message-ID: <373F3125.7E64CF43@felix.unife.it>
Is there no way, after

(def sum (x y) (+ x y)),

to give sense to something like

(eval-with-strings ("sum" 3 5)) ?

Thanks

Josef Eschgfaeller

From: Kent M Pitman
Subject: Re: strings
Date: 
Message-ID: <sfw7lq8wxq0.fsf@world.std.com>
Josef Eschgfaeller <···@felix.unife.it> writes:

> Is there no way, after
> 
> (def sum (x y) (+ x y)),

If you're asking about Common Lisp, you DEFUN, not DEF, as in:

(defun sum (x y) (+ x y))

If you're asking about some other dialect, like Autolisp, I don't know
the answer and this probably isn't the right forum to ask.
 
> to give sense to something like
> 
> (eval-with-strings ("sum" 3 5)) ?

In Common Lisp, at least, the next thing to notice is that ("sum" 3 5)
is data, not a function call, so you need to quote it.  Like

 (eval-with-strings '("sum" 3 5))

Also, in Common Lisp, it's important to know that the reader upcases symbols
so that all of these denote the same symbol:
 sum Sum SUM
They all have the name "SUM".  The name "sum" is notated with
 |sum| 
and the name "Sum" would be
 |Sum|
The name "SUM" can be written with vertical bars, but it's redundant
 |SUM|
Letter case can also be quoted with backslashes before each char, as in:
 \s\u\m
denoting the symbol whose name is "sum".

So the first thing you have to do to make your eval-with-strings work
is upcase the name if you want to access the definition of SUM.

Having done that, you can apply either the symbol or its function value.
The coercion from symbol to function value would be done automatically,
as in:

 (apply (string-upcase "sum") '(3 5))

But probably to see what's really going on, you'll want to do the coercion
yourself, as in:

 (apply (symbol-function (string-upcase "sum")) '(3 5))

I hope this helps.
From: Kent M Pitman
Subject: Re: strings
Date: 
Message-ID: <sfwr9oga91a.fsf@world.std.com>
Kent M Pitman <······@world.std.com> writes:

>  (apply (string-upcase "sum") '(3 5))
 
Uh, I was just glancing at what I'd written here and noticed that as I
was going step-by-step I got so caught up in the detail of the
casification that I left out a step.  You have to turn the upcased
string into a symbol!

 (apply (intern (string-upcase "sum")) '(3 5))

And again here:

>  (apply (symbol-function (string-upcase "sum")) '(3 5))

 (apply (symbol-function (intern (string-upcase "sum"))) '(3 5))

Note, of course, this is quite dependent on what the prevailing package
is since INTERN uses *PACKAGE*, and you may want to make sure you are
interning "SUM" in the same package as you did the DEFUN in.
From: Marco Antoniotti
Subject: Re: strings
Date: 
Message-ID: <lw4slc2m5k.fsf@copernico.parades.rm.cnr.it>
Kent M Pitman <······@world.std.com> writes:

> Josef Eschgfaeller <···@felix.unife.it> writes:
> 
> > Is there no way, after
> > 
> > (def sum (x y) (+ x y)),
> 
> If you're asking about Common Lisp, you DEFUN, not DEF, as in:
> 
> (defun sum (x y) (+ x y))
> 
> If you're asking about some other dialect, like Autolisp, I don't know
> the answer and this probably isn't the right forum to ask.
>  
> > to give sense to something like
> > 
> > (eval-with-strings ("sum" 3 5)) ?
> 
> In Common Lisp, at least, the next thing to notice is that ("sum" 3 5)
> is data, not a function call, so you need to quote it.  Like
> 
>  (eval-with-strings '("sum" 3 5))
> 
> Also, in Common Lisp, it's important to know that the reader upcases symbols
> so that all of these denote the same symbol:
>  sum Sum SUM
> They all have the name "SUM".  The name "sum" is notated with
>  |sum| 

While this is obviously correct, I'd say that it is confusing to the
beginner. For the sake of an introduction, I would replace the term
'name' with the term 'string' in this explanation.

> and the name "Sum" would be
>  |Sum|
> The name "SUM" can be written with vertical bars, but it's redundant
>  |SUM|

Cheers

Marco

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Kent M Pitman
Subject: Re: strings
Date: 
Message-ID: <sfwyainooou.fsf@world.std.com>
Marco Antoniotti <·······@copernico.parades.rm.cnr.it> writes:

> > They all have the name "SUM".  The name "sum" is notated with
> >  |sum| 
> 
> While this is obviously correct, I'd say that it is confusing to the
> beginner. For the sake of an introduction, I would replace the term
> 'name' with the term 'string' in this explanation.

Yeah, I was pretty haphazard with the terminology.  One reason I don't
mind answering a lot of questions here is that I'm always practicing
the story to see what comes out right.... You're right to point out
my explanation was probably not as clear as it could be.  I felt pretty
much the same way after I'd sent it.. Not to mention the bug about INTERN.
Oh well....
From: Marco Antoniotti
Subject: Re: strings
Date: 
Message-ID: <lwzp3223p0.fsf@copernico.parades.rm.cnr.it>
Kent M Pitman <······@world.std.com> writes:

> Marco Antoniotti <·······@copernico.parades.rm.cnr.it> writes:
> 
> > > They all have the name "SUM".  The name "sum" is notated with
> > >  |sum| 
> > 
> > While this is obviously correct, I'd say that it is confusing to the
> > beginner. For the sake of an introduction, I would replace the term
> > 'name' with the term 'string' in this explanation.
> 
> Yeah, I was pretty haphazard with the terminology.  One reason I don't
> mind answering a lot of questions here is that I'm always practicing
> the story to see what comes out right.... You're right to point out
> my explanation was probably not as clear as it could be.  I felt pretty
> much the same way after I'd sent it.. Not to mention the bug about INTERN.
> Oh well....


Feedback for your "Common Lisp in an Nutshell" (in 8 tomes of course
:) ).

Frivolously speaking, what beast would you put on the cover of an
O'Reilly's book on Common Lisp?

A turtle, a sloth, an eagle, an E. Coli bacterium, a cat (my
favourite) :)  ?

Cheers


-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Juanma Barranquero
Subject: Re: strings
Date: 
Message-ID: <37452d7c.236921545@news.mad.ttd.net>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 18 May 1999 10:16:11 +0200, Marco Antoniotti
<·······@copernico.parades.rm.cnr.it> wrote:

>Frivolously speaking, what beast would you put on the cover of an
>O'Reilly's book on Common Lisp?

A tree, in fact. An oak, maybe, or an elm tree.

                                                       /L/e/k/t/u


-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.0.2i

iQA/AwUBN0EgLv4C0a0jUw5YEQLl8wCg1VvtTw7IPOiZJNsSEsp7QVqFwYIAninK
/KTEb7KMEW3/ExHILsQNWxpy
=Hzdi
-----END PGP SIGNATURE-----
From: Paolo Amoroso
Subject: Re: strings
Date: 
Message-ID: <3741818d.99787@news.mclink.it>
On 18 May 1999 10:16:11 +0200, Marco Antoniotti
<·······@copernico.parades.rm.cnr.it> wrote:

> Feedback for your "Common Lisp in an Nutshell" (in 8 tomes of course

"Common Lisp in a Conshell" may be more appropriate.


> Frivolously speaking, what beast would you put on the cover of an
> O'Reilly's book on Common Lisp?

Of course a chameleon. Do you remember the Sep. 1991 Lisp issue of CACM?
The introductory article by guest editor John Foderaro was titled "Lisp is
a chameleon".

The nutshell handbook "Writing GNU Emacs extensions - Editor Customizations
and Creations with Lisp", by the way, has a giraffe on the cover. But I
don't know whether the giraffe refers to Emacs or Lisp.


Paolo
-- 
Paolo Amoroso <·······@mclink.it>
From: Hrvoje Niksic
Subject: Re: strings
Date: 
Message-ID: <87lneowxin.fsf@pc-hrvoje.srce.hr>
Josef Eschgfaeller <···@felix.unife.it> writes:

> Is there no way, after
> 
> (def sum (x y) (+ x y)),
> 
> to give sense to something like
> 
> (eval-with-strings ("sum" 3 5)) ?

Why do you need this?  If you have the function as a string, you can
combine INTERN and FUNCALL, e.g.:

    (funcall (intern "sum") 3 5)

If the function takes a variable number of arguments, which you build
dynamically, you can use APPLY:

    (apply (intern "sum") '(3 5))

An eval-with-strings as you described it would have to be a macro that
searches through given forms and replaces strings with symbols.  I'm
afraid this cannot be done without destroying some valid strings in
the process.