From: Pascal J. Bourguignon on
fortunatus <daniel.eliason(a)excite.com> writes:

> On Jun 14, 10:28�am, Pascal Costanza <p...(a)p-cos.net> wrote:
>> (coerce ... 'function) converts a quoted lambda expression to an actual
>> function.
>
> It seems to me that one main use of that would be "auto-programming"
> kind of code: some program that writes a function as a list structure,
> then wants to load it into the system.

Of course! What else?
Lisp is the #=(programmable . #1#) programming language.


--
__Pascal Bourguignon__ http://www.informatimago.com/
From: Mirko on
On Jun 16, 9:07 pm, p...(a)informatimago.com (Pascal J. Bourguignon)
wrote:
> fortunatus <daniel.elia...(a)excite.com> writes:
> > On Jun 14, 10:28 am, Pascal Costanza <p...(a)p-cos.net> wrote:
> >> (coerce ... 'function) converts a quoted lambda expression to an actual
> >> function.
>
> > It seems to me that one main use of that would be "auto-programming"
> > kind of code: some program that writes a function as a list structure,
> > then wants to load it into the system.
>
> Of course!  What else?
> Lisp is the  #=(programmable . #1#) programming language.
>
> --
> __Pascal Bourguignon__                    http://www.informatimago.com/

True, that is what I am aiming for. And I got it to work, except for
a case like this:

(labels ((foo (x)
(* x 2)))
(funcall
(coerce '(lambda (x)
(foo x))
'function)
3))

The function foo is invisible. I believe this is because function
produced by coerce is in the null environment.

Now, if I first (defun foo ...) then the following will work:

(funcall
(coerce '(lambda (x)
(foo x))
'function)
3)

Is there some way to handle cases for non-null lexical environements?

Thanks,

Mirko
From: Captain Obvious on
??>> It seems to me that one main use of that would be "auto-programming"
??>> kind of code: some program that writes a function as a list structure,
??>> then wants to load it into the system.

PJB> Of course! What else?
PJB> Lisp is the #=(programmable . #1#) programming language.

I'd say that "programmable programming language" is more related to
macros/read macros/read time evaluation.

(coerce ... 'function) is related to adding code in run-time. I'd say it
doesn't add a lot to programmability of a language but rather makes it more
dynamic.

I think this is an important distinction because a lot of newcomer
programmers get confused.

The question is whether code (not data) is known before run-time (e.g.
during compilation). If it is known, then one most likely doesn't need any
of (coerce ... 'function), EVAL or (compile...).
If it known only in runtime, then he might need it. (Other alternative being
interpretation of some sort.)

From: Rob Warnock on
Mirko <mirko.vukovic(a)gmail.com> wrote:
+---------------
| p...(a)informatimago.com (Pascal J. Bourguignon) wrote:
| > Of course! What else?
| > Lisp is the #=(programmable . #1#) programming language.
|
| True, that is what I am aiming for. And I got it to work, except for
| a case like this:
|
| (labels ((foo (x)
| (* x 2)))
| (funcall
| (coerce '(lambda (x)
| (foo x))
| 'function)
| 3))
|
| The function foo is invisible. I believe this is because function
| produced by coerce is in the null environment.
....
| Is there some way to handle cases for non-null lexical environements?
+---------------

You mean like this?

> (labels ((foo (x)
(* x 2)))
(funcall
(coerce `(lambda (x) (funcall ,#'foo x))
'function)
3))

6
>

Or, without using backquote:

> (labels ((foo (x)
(* x 2)))
(funcall
(coerce (list 'lambda '(x) (list 'funcall #'foo 'x))
'function)
3))

6
>

Note that the inner FUNCALL is necessary because the CAR of a
prodecure application form can *only* be a symbol or a LAMBDA
expression, *not* an actual function object. That is, this
won't work:

`(lambda (x) (,#'foo x))


-Rob

-----
Rob Warnock <rpw3(a)rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

From: Pascal J. Bourguignon on
"Captain Obvious" <udodenko(a)users.sourceforge.net> writes:

> ??>> It seems to me that one main use of that would be "auto-programming"
> ??>> kind of code: some program that writes a function as a list structure,
> ??>> then wants to load it into the system.
>
> PJB> Of course! What else?
> PJB> Lisp is the #=(programmable . #1#) programming language.
>
> I'd say that "programmable programming language" is more related to
> macros/read macros/read time evaluation.
>
> (coerce ... 'function) is related to adding code in run-time. I'd say
> it doesn't add a lot to programmability of a language but rather makes
> it more dynamic.
>
> I think this is an important distinction because a lot of newcomer
> programmers get confused.
>
> The question is whether code (not data) is known before run-time
> (e.g. during compilation). If it is known, then one most likely
> doesn't need any of (coerce ... 'function), EVAL or (compile...).
> If it known only in runtime, then he might need it. (Other alternative
> being interpretation of some sort.)

This is correct, but where both notions rejoin is at the REPL. If the
"application" provides a lisp REPL then (coerce ... 'function) may
very well be what defun and defmacro do, under the hood.


--
__Pascal Bourguignon__
http://www.informatimago.com