From: Damien Kick
Subject: Tracing local functions (or 'labels 'flet) with CMUCL
Date: 
Message-ID: <ovu17si225.fsf@email.mot.com>
Is there a CMUCL equivalent of the ACL extention to allow one to trace
"local functions"?  For example:

    (defun outer ()
      (labels ((inner () nil))
        (inner)))
    (trace ((labels outer inner)))

Would someone be able to give an example of doing something useful
with the :FUNCTION option to CMUCL's TRACE?  I'm suspecting that the
:FUNCTION option might be as close as one can get in CMUCL but I can
not think of... well, of a good way to use it.

From: Eric Marsden
Subject: Re: Tracing local functions (or 'labels 'flet) with CMUCL
Date: 
Message-ID: <wzifzj7y6zo.fsf@melbourne.laas.fr>
>>>>> "dk" == Damien Kick <······@email.mot.com> writes:

  dk> Is there a CMUCL equivalent of the ACL extention to allow one to trace
  dk> "local functions"?

no, CMUCL doesn't currently support this.

It's worth noting that you won't pay a performance penalty if you
change your code to move your local functions to the top-level (and
you'll then be able to trace them). Once you've finished debugging,
you can use CMUCL's block compilation facility to allow the compiler
to use the same optimizations as those enabled by local functions.

  dk> Would someone be able to give an example of doing something useful
  dk> with the :FUNCTION option to CMUCL's TRACE?  

TRACE is a macro; the argument to the :FUNCTION option is evaluated.

-- 
Eric Marsden                          <URL:http://www.laas.fr/~emarsden/>
From: Rob Warnock
Subject: Re: Tracing local functions (or 'labels 'flet) with CMUCL
Date: 
Message-ID: <202dnVPo-8YJ98GiXTWc-w@speakeasy.net>
Eric Marsden  <········@laas.fr> wrote:
+---------------
| Damien Kick <······@email.mot.com> writes:
| dk> Would someone be able to give an example of doing something useful
| dk> with the :FUNCTION option to CMUCL's TRACE?  
| 
| TRACE is a macro; the argument to the :FUNCTION option is evaluated.
+---------------

Hmmm... One learns something every day. Let's see here...

	appsrv> (third *http-servers*)

	#S(HTTP-SERVER :SCHEME "http" :HOST "fast.rpw3.org"
	               :PORT 80 :DOC-ROOT "/usr/local/www/data")
	appsrv> (uri-handler-function
		  (find-uri-handler "/foo.lhp" (third *http-servers*)))

	#<Closure Over ORG.RPW3.CGI.LHP::CACHED-LHP-PAGE-FUNC {4853FB51}>

[Note: This is an anonymous function created earlier when the
"foo.lhp" page was demand-loaded.]

	appsrv> (trace :function *)

	(#<Closure Over ORG.RPW3.CGI.LHP::CACHED-LHP-PAGE-FUNC {4853FB51}>)
	appsrv> 

And at this point, hit the "Reload" button on the browser, and...

	; Sep  8 03:25:42.56 cgi-sock[14]: GET "/"
	  0: (ORG.RPW3.CGI.LHP::CACHED-LHP-PAGE-FUNC
	      #S(HTTP-REQUEST
		   :KIND :CGI-SOCK
		   :STREAM #<Stream for descriptor 15>
		   :CGI-ENV (# # # # # ...)
		   :BINDINGS NIL
		   :SELF "/foo.lhp"
		   ...))
	  0: #<Closure Over Function ORG.RPW3.CGI.LHP::CACHED-LHP-PAGE-FUNC
	       {4853FB51}> returned

Wow, neat! Didn't know you could do that. Thanks, Eric!


-Rob

-----
Rob Warnock, PP-ASEL-IA		<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Duane Rettig
Subject: Re: Tracing local functions (or 'labels 'flet) with CMUCL
Date: 
Message-ID: <4llszxrc8.fsf@beta.franz.com>
····@rpw3.org (Rob Warnock) writes:

> Eric Marsden  <········@laas.fr> wrote:
> +---------------
> | Damien Kick <······@email.mot.com> writes:
> | dk> Would someone be able to give an example of doing something useful
> | dk> with the :FUNCTION option to CMUCL's TRACE?  
> | 
> | TRACE is a macro; the argument to the :FUNCTION option is evaluated.
> +---------------
> 
> Hmmm... One learns something every day. Let's see here...

 [ ... ]

> 	appsrv> (trace :function *)
> 
> 	(#<Closure Over ORG.RPW3.CGI.LHP::CACHED-LHP-PAGE-FUNC {4853FB51}>)
> 	appsrv> 
> 
> And at this point, hit the "Reload" button on the browser, and...
> 
> 	; Sep  8 03:25:42.56 cgi-sock[14]: GET "/"
> 	  0: (ORG.RPW3.CGI.LHP::CACHED-LHP-PAGE-FUNC
> 	      #S(HTTP-REQUEST
> 		   :KIND :CGI-SOCK
> 		   :STREAM #<Stream for descriptor 15>
> 		   :CGI-ENV (# # # # # ...)
> 		   :BINDINGS NIL
> 		   :SELF "/foo.lhp"
> 		   ...))
> 	  0: #<Closure Over Function ORG.RPW3.CGI.LHP::CACHED-LHP-PAGE-FUNC
> 	       {4853FB51}> returned
> 
> Wow, neat! Didn't know you could do that. Thanks, Eric!

This is apparently similar to the functional version of trace we
provide, called ftrace:


CL-USER(1): (compile
              (defun get-adder (n)
                (named-function adder
                  (lambda (x) (+ x n)))))
GET-ADDER
NIL
NIL
CL-USER(2): (defvar *a10* (get-adder 10))
*A10*
CL-USER(3): *a10*
#<Closure ADDER @ #x7163010a>
CL-USER(4): (funcall *a10* 15)
25
CL-USER(5): (ftrace *a10* :break-before t)
#<Closure ADDER @ #x7163010a>
CL-USER(6): ::fun
(FUNCALL *A10* 15)
 0[1]: (ADDER 15)
Break: traced call to ADDER

Restart actions (select using :continue):
 0: return from break.
 1: Return to Top Level (an "abort" restart).
 2: Abort entirely from this process.
[1c] CL-USER(7): 


-- 
Duane Rettig    ·····@franz.com    Franz Inc.  http://www.franz.com/
555 12th St., Suite 1450               http://www.555citycenter.com/
Oakland, Ca. 94607        Phone: (510) 452-2000; Fax: (510) 452-0182