2

I got this answer https://stackoverflow.com/a/70318991 about writing a simple macro that records the time at macro expansion time, and then always returns that time.

#lang racket

(begin-for-syntax
  (define the-time (current-seconds)))

(define-syntax (macro-expansion-seconds stx)
  (datum->syntax stx the-time))

(macro-expansion-seconds)
(macro-expansion-seconds)
(macro-expansion-seconds)

It works great, but now is there an easy way to see an expanded version of (macro-expansion-seconds) without evaluating it? (for debugging more complicated ones)

Alex028502
  • 3,486
  • 2
  • 23
  • 50

1 Answers1

4

You can use

(expand #'(macro-expansion-seconds))

in the DrRacket repl.

It will show you the graphical representation of a syntax object - remember to click the little arrow! In Mythical Macros I have written a little syntax objects.

https://soegaard.github.io/mythical-macros/

An alternative is to use the "Macro Stepper". Click the button in upper right corner of DrRacket: the icon is a combination of consists of a # and a play symbol.

soegaard
  • 30,661
  • 4
  • 57
  • 106
  • 1
    Sorry - the second of your two answers should have been obvious, except, I was using emacs. Thanks a lot. And thanks - I'll read your book. That might be what I was really looking for! – Alex028502 Dec 12 '21 at 20:02