unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* definitions in macros?
@ 2020-03-22 19:07 Han-Wen Nienhuys
  2020-03-22 19:16 ` Matt Wette
  2020-03-22 21:09 ` David Kastrup
  0 siblings, 2 replies; 4+ messages in thread
From: Han-Wen Nienhuys @ 2020-03-22 19:07 UTC (permalink / raw)
  To: Guile Devel; +Cc: lilypond-devel

Hi there,

in my quest to get lilypond working with GUILE 2+, I've hit another
stumbling block.

In order to make compilation with GUILE 2+ working, we have to move
away from runtime symbol definition (ie. module-define! calls).

In the code below, it looks like only one of the two definitions in
the body of my-macro-new takes effect. Is this expected, and if so,
why?

(defmacro-public my-macro-old (command-and-args . definition)
  (module-define! (current-module) 'x1 "I am X1\n")
  (module-define! (current-module) 'x2 "I am X2\n"))

(defmacro-public my-macro-new (command-and-args . definition)
    `(define p "i am P\n")
    `(define q "i am Q\n"))


(my-macro-old 1 2)
(my-macro-new 1 2)
(display x1)
(display x2)
(display q)
(display p)


thanks,

-- 
Han-Wen Nienhuys - hanwenn@gmail.com - http://www.xs4all.nl/~hanwen



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

* Re: definitions in macros?
  2020-03-22 19:07 definitions in macros? Han-Wen Nienhuys
@ 2020-03-22 19:16 ` Matt Wette
  2020-03-22 21:09 ` David Kastrup
  1 sibling, 0 replies; 4+ messages in thread
From: Matt Wette @ 2020-03-22 19:16 UTC (permalink / raw)
  To: guile-devel

On 3/22/20 12:07 PM, Han-Wen Nienhuys wrote:
> Hi there,
>
> in my quest to get lilypond working with GUILE 2+, I've hit another
> stumbling block.
>
> In order to make compilation with GUILE 2+ working, we have to move
> away from runtime symbol definition (ie. module-define! calls).
>
> In the code below, it looks like only one of the two definitions in
> the body of my-macro-new takes effect. Is this expected, and if so,
> why?
>
> (defmacro-public my-macro-old (command-and-args . definition)
>    (module-define! (current-module) 'x1 "I am X1\n")
>    (module-define! (current-module) 'x2 "I am X2\n"))
>
> (defmacro-public my-macro-new (command-and-args . definition)
>      `(define p "i am P\n")
>      `(define q "i am Q\n"))
>
>
> (my-macro-old 1 2)
> (my-macro-new 1 2)
> (display x1)
> (display x2)
> (display q)
> (display p)
>
>
> thanks,
>

Try the following.  Not sure about defmacro but define-syntax must 
return a single form.

(defmacro-public my-macro-new (command-and-args . definition)
     `(begin
       (define p "i am P\n")
       (define q "i am Q\n")))

  






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

* Re: definitions in macros?
  2020-03-22 19:07 definitions in macros? Han-Wen Nienhuys
  2020-03-22 19:16 ` Matt Wette
@ 2020-03-22 21:09 ` David Kastrup
  2020-03-23  7:21   ` Han-Wen Nienhuys
  1 sibling, 1 reply; 4+ messages in thread
From: David Kastrup @ 2020-03-22 21:09 UTC (permalink / raw)
  To: Han-Wen Nienhuys; +Cc: lilypond-devel, Guile Devel

Han-Wen Nienhuys <hanwenn@gmail.com> writes:

> Hi there,
>
> in my quest to get lilypond working with GUILE 2+, I've hit another
> stumbling block.
>
> In order to make compilation with GUILE 2+ working, we have to move
> away from runtime symbol definition (ie. module-define! calls).
>
> In the code below, it looks like only one of the two definitions in
> the body of my-macro-new takes effect. Is this expected, and if so,
> why?
>
> (defmacro-public my-macro-old (command-and-args . definition)
>   (module-define! (current-module) 'x1 "I am X1\n")
>   (module-define! (current-module) 'x2 "I am X2\n"))
>
> (defmacro-public my-macro-new (command-and-args . definition)
>     `(define p "i am P\n")
>     `(define q "i am Q\n"))

This is very much expected.  The macro body contains two side-effect
free expressions (namely quoted lists) and returns the last one which is

(define q "i am Q\n")

This then gets evaluated at run time, defining q .

You probably wanted something like
  `(begin (define p ...) (define q ...))

as your body (and return expression) instead.

> (my-macro-old 1 2)
> (my-macro-new 1 2)
> (display x1)
> (display x2)
> (display q)
> (display p)
>
>
> thanks,

-- 
David Kastrup



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

* Re: definitions in macros?
  2020-03-22 21:09 ` David Kastrup
@ 2020-03-23  7:21   ` Han-Wen Nienhuys
  0 siblings, 0 replies; 4+ messages in thread
From: Han-Wen Nienhuys @ 2020-03-23  7:21 UTC (permalink / raw)
  To: David Kastrup; +Cc: lilypond-devel, Guile Devel

On Sun, Mar 22, 2020 at 10:09 PM David Kastrup <dak@gnu.org> wrote:
> > In the code below, it looks like only one of the two definitions in
> > the body of my-macro-new takes effect. Is this expected, and if so,
> > why?
> >
> > (defmacro-public my-macro-old (command-and-args . definition)
> >   (module-define! (current-module) 'x1 "I am X1\n")
> >   (module-define! (current-module) 'x2 "I am X2\n"))
> >
> > (defmacro-public my-macro-new (command-and-args . definition)
> >     `(define p "i am P\n")
> >     `(define q "i am Q\n"))
>
> This is very much expected.  The macro body contains two side-effect
> free expressions (namely quoted lists) and returns the last one which is
..
> You probably wanted something like
>   `(begin (define p ...) (define q ...))

d'oh! I am an idiot.

Thanks,

-- 
Han-Wen Nienhuys - hanwenn@gmail.com - http://www.xs4all.nl/~hanwen



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

end of thread, other threads:[~2020-03-23  7:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-22 19:07 definitions in macros? Han-Wen Nienhuys
2020-03-22 19:16 ` Matt Wette
2020-03-22 21:09 ` David Kastrup
2020-03-23  7:21   ` Han-Wen Nienhuys

unofficial mirror of guile-devel@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guile-devel/0 guile-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guile-devel guile-devel/ https://yhetil.org/guile-devel \
		guile-devel@gnu.org
	public-inbox-index guile-devel

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.lisp.guile.devel
	nntp://news.gmane.io/gmane.lisp.guile.devel


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git