﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	difficulty
1770	expand1: Expand macro-form only once	John Croisant		"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 expansion.

`,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.

{{{
#!scheme
;;; 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))))
}}}"	enhancement	closed	not urgent at all	6.0.0	core libraries	5.2.0	fixed			
