unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de>
Cc: guile-devel@gnu.org, guile-user@gnu.org
Subject: Re: macros, procedure->macro
Date: Wed, 17 Jul 2002 00:00:09 +0200 (CEST)	[thread overview]
Message-ID: <Pine.GSO.4.05.10207162245220.28642-100000@sallust.ida.ing.tu-bs.de> (raw)
In-Reply-To: <m3znws4nr2.fsf@laruns.ossau.uklinux.net>

On 15 Jul 2002, Neil Jerram wrote:

> >>>>> "Dirk" == Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
> 
>     Dirk> Macro expansion is neither performed like reading, nor like evaluation.
>     Dirk> Macro expansion is blocked by quoting _and_ macro definitions.  It is not
>     Dirk> blocked by lambda or other special forms.  Since macro expansion is
>     Dirk> blocked by macro definitions, recursive macro definitions are possible.
> 
> This sounds good.  But, given that the code for a macro definition
> gets wrapped in a lambda, perhaps it would be simpler to say that all
> lambdas block macroexpansion, and that macroexpansion of the code
> inside the lambda happens when the lambda is first used.  This seems
> well defined and easy to understand to me.

Well, I have to correct myself (actually, Marius has already done so):  I
confused define-macro and its mechanisms with define-syntax. Certainly,
the following will not work:

>     Dirk>   (define (foo) (bar))
>     Dirk>   (define-macro (bar) #f)
>     Dirk>   (foo)

And _neither_ will

>     Dirk>   (define-macro (foo x) `(list ,(bar x) ,x))
>     Dirk>   (define-macro (bar x) `(* ,x ,x))

Sorry for the confusion (oh boy).  However, the following will work
(hopefully I am getting it right this time...):

      (use-syntax (ice-9 syncase))
      (define-syntax foo (syntax-rules () ((foo) (bar))))
      (define-syntax bar (syntax-rules () ((bar) (write "bar"))))
      (foo)

and here applys what I wanted to express, namely that the use of bar in
the line where foo is defined is not expanded at that moment.

> If we follow the all lambdas idea, then the `define' example would
> work as well.  Is there any reason why this would be a _bad_ thing?

First, it is confusing.  In the _current_ system, the following works,
since currently lambda blocks macro expansion:
   (define-macro (foo x) `(list ,(bar x) ,x))
   (define-macro (bar x) `(* ,x ,x))
   (foo)
Thus, we can define the following:
   (define-macro (foo) `'first)
   (define (bar) (foo))
   (define (yuck expand?) (if expand? (bar) #f))
   (yuck <some-input-data>)
   (define-macro (foo) `'second)
   (yuck #t) 
Now, what does the last expression deliver?  It depends on what the value
of <some-input-data> was.  This is not what I expect from a macro system.

Second, you can't optimize the execution phase by writing out expanded
code and read it in later:  Only code that has been executed once is
expanded.  How could you write out the expanded version of bar in the
above example? You can't since it depends on your value of
<some-input-data> what bar becomes.  Thus, you also can not provide a
pre-compiled version of bar.  A lot of compiler optimization techniques
are impossible to use, like function inlining etc.

Third, it complicates the execution phase, since you always have to be
aware of still unexpanded functions in the executor.

>     Dirk> However, it may be that different macro implementations with different
>     Dirk> behaviours can co-exist.  For example, I don't see why you shouldn't be
>     Dirk> able to mix calls to procedure->memoizing-macro with calls to
>     Dirk> define-macro.  Then, for each of the different macro systems the behaviour
>     Dirk> would have to be defined separately.  Not all possible systems will comply
>     Dirk> with the demand for a system that supports compilation and efficient
>     Dirk> execution, though.
> 
> In general, yes.  I don't understand your specific example, though, as
> define-macro is implemented using procedure->memoizing-macro, so they
> are the same implementation.

Well, in that paragraph above replace 'define-macro' with 'define-syntax'
and I hope things become clearer.

Best regards,
Dirk Herrmann


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  reply	other threads:[~2002-07-16 22:00 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <m3lm8e5o69.fsf@laruns.ossau.uklinux.net>
2002-07-14 21:35 ` macros, procedure->macro Dirk Herrmann
2002-07-15 20:48   ` Marius Vollmer
2002-07-15 22:42   ` Neil Jerram
2002-07-16 22:00     ` Dirk Herrmann [this message]
     [not found] <87n0t376c9.fsf@zagadka.ping.de>
2002-07-08 20:23 ` Dirk Herrmann
2002-07-09 18:13   ` Marius Vollmer
2002-07-10 21:54 ` Dirk Herrmann
2002-07-13  9:53   ` Dirk Herrmann
2002-07-13 18:38     ` Marius Vollmer
     [not found] <200207012220.PAA08054@onyx.he.net>
2002-07-03 20:08 ` Dirk Herrmann
2002-07-04 20:16   ` Dirk Herrmann
2002-07-07 18:15     ` Marius Vollmer
2002-07-01 19:56 Dirk Herrmann
2002-07-01 21:30 ` Rob Browning
2002-07-03 20:24   ` Dirk Herrmann
2002-07-01 22:14 ` Marius Vollmer
2002-07-03 20:11   ` Dirk Herrmann
2002-07-07 17:54     ` Marius Vollmer
2002-07-08 20:31       ` Dirk Herrmann
2002-07-09 18:22         ` Marius Vollmer
2002-07-10  5:21           ` Dirk Herrmann
2002-07-10 19:31             ` Marius Vollmer
2002-07-10 19:57               ` Dirk Herrmann
2002-07-10 20:08                 ` Marius Vollmer
2002-07-01 22:17 ` Gary Houston
2002-07-09 21:16 ` Neil Jerram
2002-07-10  5:46   ` Dirk Herrmann
2002-07-10 10:15     ` Neil Jerram
2002-07-10 20:03       ` Dirk Herrmann
2002-07-13  0:09         ` Neil Jerram
2002-07-13  2:36           ` Clinton Ebadi
2002-07-14 15:23             ` Neil Jerram
2002-07-14 16:26               ` Marius Vollmer
2002-07-15  6:03                 ` Rob Browning
2002-07-13  6:53           ` Dirk Herrmann
2002-07-14 15:23             ` Neil Jerram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.05.10207162245220.28642-100000@sallust.ida.ing.tu-bs.de \
    --to=dirk@sallust.ida.ing.tu-bs.de \
    --cc=guile-devel@gnu.org \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).