From: John Clonts
Subject: How to display source of interpreted function
Date: 
Message-ID: <3A0B9F3C.69D933C5@mastnet.net>
If I define a function e.g.
==> (defun john (x) (* x x))

Is there any function I can call to display the source, such as

==> (display-source 'john)
(defun john (x)
   (* x x))
==>


Thanks,
John

P.S. using acl6_trial

From: Kent M Pitman
Subject: Re: How to display source of interpreted function
Date: 
Message-ID: <sfw66lwoxnj.fsf@world.std.com>
John Clonts <·······@mastnet.net> writes:

> If I define a function e.g.
> ==> (defun john (x) (* x x))
> 
> Is there any function I can call to display the source, such as
> 
> ==> (display-source 'john)
> (defun john (x)
>    (* x x))

The portable answer is that FUNCTION-LAMBDA-EXPRESSION might get you the
associated lambda for a function, but the conditions under which it does
vary between implementations.  It's redundant to save the lambda expression
in general, since it's not used even for interpretation in most 
implementations and is especially not needed after compilation.  

Note, of course, that FUNCTION-LAMBDA-EXPRESSION doesn't return a DEFUN
but it's pretty easy to reassemble one from what it does return.  See CLHS
for more details on that.

The common wisdom is that if you *really* want this to work for all
functions, you're going to lose.  For example, you can't get it for 
things like CAR and CDR, since odds are they are defined specially (maybe
even in C or some other low-level substrate) in many implementations and
actually have no definition, or have a confusing-looking bootstrap 
definition that would be meaningless to you, like car's definition might
have been (lambda (x) (car x)) because the compiler will know to compile
that specially and not infinitely recurse.  But if you want it to work for
a special subset, you should do something to record the expression yourself
like:

 (DEFMACRO DEFUN* (&WHOLE MY-DEFINITION NAME BVL &BODY DECLS-DOC-FORMS)
   `(PROGN (SETF (GET ',NAME 'SAVED-DEFINITION) ',MY-DEFINITION)
           (DEFUN ,NAME ,BVL ,@DECLS-DOC-FORMS)))

and then use DEFUN* instead of DEFUN.

> P.S. using acl6_trial

(Sorry I missed this in your last one.)

There may be implementation-defined additional help Franz can give you.
From: Erik Naggum
Subject: Re: How to display source of interpreted function
Date: 
Message-ID: <3182855750336241@naggum.net>
* Kent M Pitman <······@world.std.com>
| There may be implementation-defined additional help Franz can give you.

  In addition to function-lambda-expression, Franz Inc has a sometimes
  helpful uncompile operator that reverses the effect of compile if
  *save-function-lambda-expression* was true when compile was run.
  (This does not work for compile-file, as the source form is not stored
  in the fasl file.)

#:Erik
-- 
  ALGORITHM: a procedure for solving a mathematical problem in a finite
  number of steps that frequently involves repetition of an operation.
  ALGOREISM: a procedure for solving an electoral problem in a finite
  number of steps that frequently involves repetition of an operation.
From: Erik Naggum
Subject: Re: How to display source of interpreted function
Date: 
Message-ID: <3182847091422316@naggum.net>
* John Clonts <·······@mastnet.net>
| Is there any function I can call to display the source, such as

  This is pretty simple if you know what to expect, since you can't
  quite back the source, which exist before macroexpansion of defun.
  defun store a function definition in the function slot of the symbol,
  possibly after transforming the function body.
        
(9322) cl-user
(defun john (x) (* x x))
=> john
(9323) cl-user
(function-lambda-expression #'john)
=> (lambda (x) (block john (* x x)))
=> nil
=> john

  The preferred way to display the source is to write your Common Lisp
  code in the editor and compile (or evaluate) it from there, or compile
  and/or load the file itself.  The Emacs/Lisp interface from Franz Inc
  or ILISP from other sources or even Emacs' built-in inferior lisp mode
  may all help in connecting with the running Lisp system to do this.

#:Erik
-- 
 Al-Gore-ism: a procedure for solving an electoral problem in a finite
 number of steps that frequently involves repetition of an operation.
 See also algorithm.
From: John Clonts
Subject: Re: How to display source of interpreted function
Date: 
Message-ID: <3A0C1C8F.416DFCC5@mastnet.net>
Erik Naggum wrote:
> 
> * John Clonts <·······@mastnet.net>
> | Is there any function I can call to display the source, such as
> 
>   This is pretty simple if you know what to expect, since you can't
>   quite back the source, which exist before macroexpansion of defun.
>   defun store a function definition in the function slot of the symbol,
>   possibly after transforming the function body.
> 
> (9322) cl-user
> (defun john (x) (* x x))
> => john
> (9323) cl-user
> (function-lambda-expression #'john)
> => (lambda (x) (block john (* x x)))
> => nil
> => john
> 
>   The preferred way to display the source is to write your Common Lisp
>   code in the editor and compile (or evaluate) it from there, or compile
>   and/or load the file itself.  The Emacs/Lisp interface from Franz Inc
>   or ILISP from other sources or even Emacs' built-in inferior lisp mode
>   may all help in connecting with the running Lisp system to do this.
> 
> #:Erik

Thank you Erik and Kent.

The function-lambda-expression is what I was looking for.

And, I "almost-sort-of" have the acl/xemacs connection working.

Cheers,
John

--
[:o|]
From: glauber
Subject: Re: How to display source of interpreted function
Date: 
Message-ID: <8uh056$v8f$1@nnrp1.deja.com>
In article <·················@mastnet.net>,
  John Clonts <·······@mastnet.net> wrote:
> If I define a function e.g.
> ==> (defun john (x) (* x x))
>
> Is there any function I can call to display the source, such as
>
> ==> (display-source 'john)
> (defun john (x)
>    (* x x))


How about (ed 'john) ?
This is implementation-specific, but it's in the standard.


--
Glauber Ribeiro
··········@my-deja.com    http://www.myvehiclehistoryreport.com
"Opinions stated are my own and not representative of Experian"


Sent via Deja.com http://www.deja.com/
Before you buy.