From: Thaddeus L Olczyk
Subject: Any easy way of doing this.
Date: 
Message-ID: <3c68da1d.122487859@nntp.interaccess.com>
Wrapping a function with a set of prints.
What I want to do is this:

(defun foo(x)
  (let ((retval nil)
....
  retval))

I want	to implement something like:

(setf indent "")

(defun foo(x)
(let ((oldindent indent)
        (indent (concatenate 'string indent " "))
      (print indent)
      (princ "in foo::")
       (print-x)
      (let ((retval nil)
       ....
       retval))
      (print indent)
      (princ "exiting foo")
      (terpri)
)
)
So that I see output like:
in foo ::x
    in foo::y
        in foo::z
        exiting foo
   exiting foo
exiting foo

For obvious reaons I want to do this with minimal  diruption to the
actual code to the initial foo. 

Suggestions?

From: Christian Nyb�
Subject: Re: Any easy way of doing this.
Date: 
Message-ID: <87d6zc6njj.fsf@nybo.no>
······@interaccess.com (Thaddeus L Olczyk) writes:

> Wrapping a function with a set of prints.
> What I want to do is this:

[...]

> in foo ::x
>     in foo::y
>         in foo::z
>         exiting foo
>    exiting foo
> exiting foo

Are you aware of the ``trace'' macro?
-- 
chr
From: Barry Margolin
Subject: Re: Any easy way of doing this.
Date: 
Message-ID: <AuU98.13$g01.133702@burlma1-snr2>
In article <··················@nntp.interaccess.com>,
Thaddeus L Olczyk <······@interaccess.com> wrote:
>Wrapping a function with a set of prints.
>What I want to do is this:
>
>(defun foo(x)
>  (let ((retval nil)
>....
>  retval))
>
>I want	to implement something like:
>
>(setf indent "")
>
>(defun foo(x)
>(let ((oldindent indent)
>        (indent (concatenate 'string indent " "))
>      (print indent)
>      (princ "in foo::")
>       (print-x)
>      (let ((retval nil)
>       ....
>       retval))
>      (print indent)
>      (princ "exiting foo")
>      (terpri)
>)
>)
>So that I see output like:
>in foo ::x
>    in foo::y
>        in foo::z
>        exiting foo
>   exiting foo
>exiting foo
>
>For obvious reaons I want to do this with minimal  diruption to the
>actual code to the initial foo. 
>
>Suggestions?

Use a special variable:

(defvar *indent* "")

(defun foo (x)
  (let ((*indent* (concatenace 'string *indent* " ")))
    ...))
   
-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Thaddeus L Olczyk
Subject: Re: Any easy way of doing this.
Date: 
Message-ID: <3c6a1c3c.139414171@nntp.interaccess.com>
On Mon, 11 Feb 2002 18:57:36 GMT, Barry Margolin <······@genuity.net>
wrote:

>In article <··················@nntp.interaccess.com>,
>Thaddeus L Olczyk <······@interaccess.com> wrote:
>>Wrapping a function with a set of prints.
>>What I want to do is this:
>>
>>(defun foo(x)
>>  (let ((retval nil)
>>....
>>  retval))
>>
>>I want	to implement something like:
>>
>>(setf indent "")
>>
>>(defun foo(x)
>>(let ((oldindent indent)
>>        (indent (concatenate 'string indent " "))
>>      (print indent)
>>      (princ "in foo::")
>>       (print-x)
>>      (let ((retval nil)
>>       ....
>>       retval))
>>      (print indent)
>>      (princ "exiting foo")
>>      (terpri)
>>)
>>)
>>So that I see output like:
>>in foo ::x
>>    in foo::y
>>        in foo::z
>>        exiting foo
>>   exiting foo
>>exiting foo
>>
>>For obvious reaons I want to do this with minimal  diruption to the
>>actual code to the initial foo. 
>>
>>Suggestions?
>
>Use a special variable:
>
>(defvar *indent* "")
>
>(defun foo (x)
>  (let ((*indent* (concatenace 'string *indent* " ")))
>    ...))
>   
1) Thanks.
2) You missed half the problem. Wrapping code around the original
code, to return the same value, but print the exit line. Avoiding
modifying the original code as much as possible.
From: Tim Bradshaw
Subject: Re: Any easy way of doing this.
Date: 
Message-ID: <ey3ofivg4ph.fsf@tfeb.org>
* Thaddeus L Olczyk wrote:

> 2) You missed half the problem. Wrapping code around the original
> code, to return the same value, but print the exit line. Avoiding
> modifying the original code as much as possible.

Isn't this what TRACE does, can't you just use that?  If you want some
special-magic version of trace then you probably need to either (best)
use the implementation's advice facility if it has one, or (less good)
do something like this:

    (defun wrap (function-name function)
      ;; Wrap FUNCTION-NAME in FUNCTION.  FUNCTION is called with two arguments:
      ;; (1) the complete list of args to FUNCTION, and (2) a function  which will
      ;; call the original function.  If you give it no args it will call it with
      ;; the original arglist, if you give it an argument, this is the arglist.
      ;; This is kind of rudimentaty not-properly-working advice.
      (unless (symbolp function-name)
        (error "Won't work"))
      (let ((f (symbol-function function-name)))
        (push f (get function-name 'wrappers))
        (setf (symbol-function function-name)
              #'(lambda (&rest args)
                  (declare (dynamic-extent args)) ;maybe...
                  (funcall function args #'(lambda (&optional (a args))
                                             (apply f a)))))))

    (defun unwrap (function-name)
      (unless (symbolp function-name)
        (error "Won't work"))
      (setf (symbol-function function-name)
            (pop (get function-name 'wrappers))))

This is not meant to be a good way (or even perhaps a correct way)
of doing this