Ticket #1770: 0002-Add-x1-toplevel-command-to-csi.patch

File 0002-Add-x1-toplevel-command-to-csi.patch, 1.5 KB (added by John Croisant, 12 months ago)
  • csi.scm

    From 15ed1bab956e663e61e757c98e05bb42e00867a6 Mon Sep 17 00:00:00 2001
    From: John Croisant <john@croisant.net>
    Date: Sun, 11 Jul 2021 23:46:52 -0500
    Subject: [PATCH 2/2] Add `,x1` toplevel command to csi.
    
    Like `,x` but uses `expand1` instead of `expand`. The form is expanded
    only once, then pretty-printed.
    ---
     csi.scm                      | 9 +++++++++
     manual/Using the interpreter | 2 ++
     2 files changed, 11 insertions(+)
    
    diff --git a/csi.scm b/csi.scm
    index f22a42b9..5a81f523 100644
    a b EOF 
    428428              (printf "undefined module `~a'~%" name))))))
    429429 ",m MODULE         switch to module with name `MODULE'")
    430430
     431(toplevel-command
     432 'x1
     433 (let ((pretty-print pretty-print))
     434   (lambda ()
     435     (let ([expr (read)])
     436       (pretty-print (strip-syntax (expand1 expr)))
     437       (##sys#void))))
     438 ",x1 EXP           Pretty print expand1-ed expression EXP")
     439
    431440
    432441;;; Parse options from string:
    433442
  • manual/Using

    diff --git a/manual/Using the interpreter b/manual/Using the interpreter
    index d70fdf23..98be24a1 100644
    a b The toplevel loop understands a number of special commands: 
    133133
    134134; ,x EXP : Pretty-print macroexpanded expression {{EXP}} (the expression is not evaluated).
    135135
     136; ,x1 EXP : Like {{,x}} but {{EXP}} is expanded only one step, using {{expand1}}.
     137
    136138You can define your own toplevel commands using the {{toplevel-command}}
    137139procedure (see [[Module (chicken csi)]]).
    138140