unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Expansion of a macro
@ 2015-04-20 15:33 A0
  2015-04-20 19:16 ` tomas
  2015-04-21  1:32 ` Mark H Weaver
  0 siblings, 2 replies; 6+ messages in thread
From: A0 @ 2015-04-20 15:33 UTC (permalink / raw)
  To: guile-user

Hi all,

How can one find out what a macro expands to?
Error reports are useful when it expands to nonsense, but how
to do this in general?




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Expansion of a macro
  2015-04-20 15:33 Expansion of a macro A0
@ 2015-04-20 19:16 ` tomas
  2015-04-21  1:32 ` Mark H Weaver
  1 sibling, 0 replies; 6+ messages in thread
From: tomas @ 2015-04-20 19:16 UTC (permalink / raw)
  To: A0; +Cc: guile-user

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Apr 20, 2015 at 04:33:07PM +0100, A0 wrote:
> Hi all,
> 
> How can one find out what a macro expands to?
> Error reports are useful when it expands to nonsense, but how
> to do this in general?

There's macroexpand, but perhaps it'll expand more than you'd
like.

If your editor is Emacs, I'd recommend geiser[1]: it has an
"expand region" functionality.

HTH
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlU1UIQACgkQBcgs9XrR2kapGgCfbhWPSY5x96V043+M+NDVVa41
GvAAn01a4UmorTqswAi/Vx+JDjwhza36
=eDY5
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Expansion of a macro
  2015-04-20 15:33 Expansion of a macro A0
  2015-04-20 19:16 ` tomas
@ 2015-04-21  1:32 ` Mark H Weaver
  2015-04-21  6:13   ` Panicz Maciej Godek
  2015-04-21  6:22   ` tomas
  1 sibling, 2 replies; 6+ messages in thread
From: Mark H Weaver @ 2015-04-21  1:32 UTC (permalink / raw)
  To: A0; +Cc: guile-user

A0 <cape.wrath@openmailbox.org> writes:
> How can one find out what a macro expands to?

You can use the ,expand REPL command, e.g.:

scheme@(guile-user)> ,expand (do ((n 10 (- n 1))) ((zero? n) n))
$1 = (let loop ((n 10))
  (if (zero? n)
    (begin (if #f #f) n)
    (loop (- n 1))))

      Mark



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Expansion of a macro
  2015-04-21  1:32 ` Mark H Weaver
@ 2015-04-21  6:13   ` Panicz Maciej Godek
  2015-04-21  6:22   ` tomas
  1 sibling, 0 replies; 6+ messages in thread
From: Panicz Maciej Godek @ 2015-04-21  6:13 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user@gnu.org

[-- Attachment #1: Type: text/plain, Size: 683 bytes --]

Or you can (use-modules (system base compile) (srfi srfi-11))

and then

(define* (expand-form e #:key (opts '()))
  (let-values (((exp env) (decompile
                           (compile e #:from 'scheme
                                    #:to 'tree-il
                                    #:env (current-module))
                           #:from 'tree-il
                           #:to 'scheme
                           #:opts opts)))
    exp))

(define-syntax-rule (expand expression)
  (expand-form 'expression))

-- at least in guile 2.0

Sometimes it is also instructive to use the macro stepper shipped with
Racket:
http://docs.racket-lang.org/macro-debugger/index.html?q=

[-- Attachment #2: Type: text/html, Size: 1566 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Expansion of a macro
  2015-04-21  1:32 ` Mark H Weaver
  2015-04-21  6:13   ` Panicz Maciej Godek
@ 2015-04-21  6:22   ` tomas
  2015-04-21  8:55     ` A0
  1 sibling, 1 reply; 6+ messages in thread
From: tomas @ 2015-04-21  6:22 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Apr 20, 2015 at 09:32:48PM -0400, Mark H Weaver wrote:
> A0 <cape.wrath@openmailbox.org> writes:
> > How can one find out what a macro expands to?
> 
> You can use the ,expand REPL command, e.g.:

Not the OP, but... thanks for this one!

- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlU17I4ACgkQBcgs9XrR2kYtLACeMiMfwfxYatyGt0+xlkz1FtS0
gNEAn3GxQ8QMwKMCiqHbH0pIqGN/CpGh
=pOQ7
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Expansion of a macro
  2015-04-21  6:22   ` tomas
@ 2015-04-21  8:55     ` A0
  0 siblings, 0 replies; 6+ messages in thread
From: A0 @ 2015-04-21  8:55 UTC (permalink / raw)
  To: tomas, Mark H Weaver; +Cc: guile-user

On 21/04/15 07:22, tomas@tuxteam.de wrote:
> On Mon, Apr 20, 2015 at 09:32:48PM -0400, Mark H Weaver wrote:
>> A0 <cape.wrath@openmailbox.org> writes:
>>> How can one find out what a macro expands to?
> 
>> You can use the ,expand REPL command, e.g.:
> 
> Not the OP, but... thanks for this one!
> 
> -- t
> 

I second!

Thank you all, you truly have Guile ;)




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-04-21  8:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-20 15:33 Expansion of a macro A0
2015-04-20 19:16 ` tomas
2015-04-21  1:32 ` Mark H Weaver
2015-04-21  6:13   ` Panicz Maciej Godek
2015-04-21  6:22   ` tomas
2015-04-21  8:55     ` A0

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).