[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

#1770: expand1: Expand macro-form only once

From: Chicken Trac
Subject: #1770: expand1: Expand macro-form only once
Date: Mon, 12 Jul 2021 06:38:21 -0000

#1770: expand1: Expand macro-form only once
            Reporter:  John Croisant  |       Type:  enhancement
              Status:  new            |   Priority:  not urgent at all
           Milestone:  someday        |  Component:  core libraries
             Version:  5.2.0          |   Keywords:
Estimated difficulty:                 |
 These patches add the `expand1` procedure to module (chicken syntax), and
 add the `,x1` toplevel command to csi. This has been a personal wish of
 mine for several years and I finally decided to implement it. :)

 `expand1` is like `expand` but it expands the form only once, instead of
 repeating until a non-macro form is produced. This is helpful when
 debugging macros because you can see the intermediate results of the

 `,x1` is like the `,x` command (expand and pretty-print the form) but it
 uses `expand1` instead of `expand`. This is not difficult for users to
 implement in their `.csirc` once `expand1` is available, so you can ignore
 the second patch if you don't think it is useful enough to build into csi.

 I tried adding the tests below to `tests/syntax-tests.scm`, but they only
 pass when using csi, not csc. Specifically, `(expand '(rec-macro 1))` and
 `(expand1 '(rec-macro 1))` both expand to `(rec-macro 1)`. I suspect this
 is because the `rec-macro` macro is not visible at run time in compiled
 code. The only solution I have found so far is to use `(eval '(begin
 (define-syntax rec-macro ...) (expand '(rec-macro 1))))`, which is messy
 because every test must repeat the macro definition. Maybe someone more
 knowledgeable than me can find a cleaner way to make the tests work.

 ;;; expand / expand1

 (define-syntax rec-macro
   (syntax-rules ()
     ((rec-macro 1) (rec-macro 2))
     ((rec-macro 2) "done") ) )

 ;; `expand` expands repeatedly until it finds a non-macro form.
 (t "done" (expand '(rec-macro 1)))

 ;; `expand1` expands only once.
 (t '(rec-macro 2) (strip-syntax (expand1 '(rec-macro 1))))
 (t "done" (expand1 (expand1 '(rec-macro 1))))

Ticket URL: <>
CHICKEN Scheme <>
CHICKEN Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]