From 65fc5cedc586c571b41decb5fb6013089f6031c5 Mon Sep 17 00:00:00 2001
From: John Croisant <john@croisant.net>
Date: Sun, 11 Jul 2021 23:15:01 -0500
Subject: [PATCH 1/2] Add `expand1` procedure in module (chicken syntax).

Like `expand` but 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.
---
 chicken.syntax.import.scm      | 1 +
 expand.scm                     | 4 ++++
 manual/Module (chicken syntax) | 8 ++++++++
 3 files changed, 13 insertions(+)

diff --git a/chicken.syntax.import.scm b/chicken.syntax.import.scm
index 13983816..da39de12 100644
--- a/chicken.syntax.import.scm
+++ b/chicken.syntax.import.scm
@@ -31,6 +31,7 @@
  'chicken.syntax
  'expand
  '((expand . chicken.syntax#expand)
+   (expand1 . chicken.syntax#expand1)
    (get-line-number . chicken.syntax#get-line-number)
    (strip-syntax . chicken.syntax#strip-syntax)
    (syntax-error . chicken.syntax#syntax-error)
diff --git a/expand.scm b/expand.scm
index e815a2b9..e6dd57c4 100644
--- a/expand.scm
+++ b/expand.scm
@@ -36,6 +36,7 @@
 
 (module chicken.syntax
   (expand
+   expand1
    get-line-number
    strip-syntax
    syntax-error
@@ -305,6 +306,9 @@
 	  (loop exp2)
 	  exp2) ) ) )
 
+(define (expand1 exp #!optional (se (##sys#current-environment)) cs?)
+  (nth-value 0 (##sys#expand-0 exp se cs?)) )
+
 
 ;;; Extended (DSSSL-style) lambda lists
 ;
diff --git a/manual/Module (chicken syntax) b/manual/Module (chicken syntax)
index eaa7dbd1..ab169c9b 100644
--- a/manual/Module (chicken syntax)	
+++ b/manual/Module (chicken syntax)	
@@ -301,6 +301,14 @@ comparison {{(compare sym 'abc)}} should be written as {{(compare sym
 If {{X}} is a macro-form, expand the macro (and repeat expansion
 until expression is a non-macro form).  Returns the resulting expression.
 
+==== expand1
+
+<procedure>(expand1 X)</procedure>
+
+If {{X}} is a macro-form, expand the macro only once.  Unlike
+{{expand}}, does not repeat expansion when the resulting expression is
+itself a macro-form.  Returns the resulting expression.
+
 === Macro helper procedures
 
 ==== begin-for-syntax
-- 
2.25.1

