Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added trace-define, trace-let, trace-lambda #525

Closed
wants to merge 10 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

wilbowma commented Dec 18, 2013

Someone asked me about Chez-like trace macros in Racket, even pointing me to this post on the mailing list: http://lists.racket-lang.org/users/archive/2013-October/059735.html

But it looks like they never made it in. So I hacked them up.

@samth samth and 1 other commented on an outdated diff Dec 18, 2013

racket/collects/racket/trace.rkt
@@ -291,3 +292,25 @@
#'(begin (when (traced-proc? id)
(set! id (traced-proc-ref id 1)))
...)]))
+
+(define-syntax trace-define
+ (syntax-rules ()
+ [(_ (name . args) body ...)
@samth

samth Dec 18, 2013

Owner

This will error bizarrely on (define ((f x) y) (+ x y)).

@wilbowma

wilbowma Dec 18, 2013

Contributor

Oh right; I forgot Racket has fancy curry syntax.

@samth

samth Dec 18, 2013

Owner

You probably want to use normalize-definition if you want to handle everything, or just check that it's an identifier if not.

@samth samth and 2 others commented on an outdated diff Dec 18, 2013

racket/collects/racket/trace.rkt
+ (define (name . args) body ...)
+ (trace name))]
+ [(_ name body)
+ (begin
+ (define name body)
+ (trace name))]))
+
+(define-syntax trace-let
+ (syntax-rules ()
+ [(_ name ([x* e*] ...) body ...)
+ ((letrec ([name (lambda (x* ...) body ...)]) (trace name) name)
+ e* ...)]))
+
+(define-syntax trace-lambda
+ (syntax-rules ()
+ [(_ name args body ...)
@samth

samth Dec 18, 2013

Owner

Is there really supposed to be name in the input syntax?

@stamourv

stamourv Dec 18, 2013

Contributor

You could use syntax-local-infer-name instead.

@wilbowma

wilbowma Jan 14, 2014

Contributor

@stamourv Instead of passing a name to lambda?

@stamourv

stamourv Jan 14, 2014

Contributor

Yes.

Contributor

wilbowma commented Jan 14, 2014

This version causes bizareness when a traced function is called inside (with-output-to-file ...). I'm not sure what the correct behavior should be.

Contributor

stamourv commented Jan 14, 2014

Is the function defined at the module level, or in some inner scope?

Contributor

wilbowma commented Jan 14, 2014

Module level.

On Tue, Jan 14, 2014 at 10:59:51AM -0800, Vincent St-Amour wrote:

Is the function defined at the module level, or in some inner scope?


Reply to this email directly or view it on GitHub:
plt#525 (comment)

Owner

samth commented Apr 30, 2014

@bluephoenix47 I think the trace output should go to the file. What else would happen?

Contributor

wilbowma commented May 20, 2014

I was being stupid before.

I wanted to specify that the traced output should go to one port, while my program IO goes to another port. It looks like I can do that via current-trace-notify, as done here: https://gist.github.com/bluephoenix47/cb037265e7aa054d29bb

Owner

samth commented May 20, 2014

Ok, great.

Contributor

wilbowma commented May 21, 2014

Okay, I made the name for trace-lambda optional and added some little tests.

Contributor

wilbowma commented Jun 23, 2014

Performed git pull --rebase upstream and fixed some merge conflicts.

Owner

samth commented Jun 23, 2014

This all looks good to me. We just need to add some documentation.

Are there any tests for trace currently?

Contributor

wilbowma commented Jun 23, 2014

I couldn't find any tests.

When I tried to add some for my macros, Travis got errors when about rackunit not found (despite the (module+ test ...) starting with (require rackunit)).

I removed the tests in a recentish commit. The Travis job number is 2151.1, line 848, https://travis-ci.org/plt/racket/jobs/25679987. If you can make any sense of it, I'll revert that commit.

I'll get around to some documentation, but maybe not until after POPL.

Owner

samth commented Jun 23, 2014

You can't depend on rackunit in this file, which is inside the core.

It looks to me like tests are here: https://github.com/plt/racket/blob/master/pkgs/racket-pkgs/racket-test/tests/racket/trace.rktl

Contributor

wilbowma commented Jun 23, 2014

Ah I see. Does trace.rkt belong in core? ... Maybe a thought for another place.

I'll add some tests to there.

On Mon, Jun 23, 2014 at 10:21:09AM -0700, Sam Tobin-Hochstadt wrote:

You can't depend on rackunit in this file, which is inside the core.

It looks to me like tests are here: https://github.com/plt/racket/blob/master/pkgs/racket-pkgs/racket-test/tests/racket/trace.rktl


Reply to this email directly or view it on GitHub:
plt#525 (comment)

Owner

samth commented Jun 23, 2014

Probably it doesn't, but I don't think changing it now is the right choice.

Contributor

wilbowma commented Jul 8, 2014

I just pushed some tests and documentation.

I am not sure how to test trace-define-syntax. I also don't know what version numbers to use with @history.

@samth samth commented on an outdated diff Sep 6, 2014

racket/collects/racket/trace.rkt
+
+ (define-syntax (trace-define stx)
+ (syntax-case stx ()
+ [(_ e ...)
+ (let-values ([(name def) (normalize-definition stx #'lambda)])
+ #`(begin (define #,name #,def) (trace #,name)))]))
+
+ (define-syntax trace-let
+ (syntax-rules ()
+ [(_ name ([x* e*] ...) body ...)
+ ((letrec ([name (lambda (x* ...) body ...)]) (trace name) name)
+ e* ...)]))
+
+ (define-syntax (trace-lambda stx)
+ (syntax-parse stx
+ [(_ (~optional (~seq #:name name:id) #:defaults ([name #`#,(syntax-local-infer-name stx)])) args body:expr ...)
@samth

samth Sep 6, 2014

Owner

Need to handle the case when no name is provided and syntax-local-infer-name fails. I think we should just error then.

@samth samth commented on an outdated diff Sep 6, 2014

...ket-pkgs/racket-doc/scribblings/reference/trace.scrbl
@@ -49,6 +49,78 @@ The result of a @racket[trace] expression is @|void-const|.
}
+@defform*[((trace-define id expr)
+ (trace-define (head args) body ...+))]{
+
+The @racket[trace-define] form supports all @racket[define] forms. This
+form is equivalent to:
+
+@racketblock[
@samth

samth Sep 6, 2014

Owner

I think examples are better than these pseudo-rewrite rules.

Owner

samth commented Sep 6, 2014

Other than those issues, this is nice and should be merged.

Owner

samth commented Sep 8, 2014

Looks good.

@wilbowma wilbowma closed this Sep 8, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment