unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: taylanbayirli@gmail.com (Taylan Ulrich B.)
To: KAction@gnu.org
Cc: wingo@pobox.com, ludo@gnu.org, guile-devel@gnu.org
Subject: Re: [PATCH] Replace define-macro with syntax-rules
Date: Sat, 28 Sep 2013 12:27:09 +0200	[thread overview]
Message-ID: <87mwmxgs1u.fsf@taylan.uni.cx> (raw)
In-Reply-To: <1380345956-1720-1-git-send-email-KAction@gnu.org> (KAction@gnu.org's message of "Sat, 28 Sep 2013 09:25:55 +0400")

KAction@gnu.org writes:

> From: Dmitry Bogatov <KAction@gnu.org>
>
> As I can see, definition with define-macro is hygienic and 
> move to syntax-rules adds two lines of code, but define-syntax 
> is considered preferable. 
>
> WDYT?
> Signed-off-by: Dmitry Bogatov <KAction@gnu.org>
> ---
>  module/rnrs/bytevectors.scm | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/module/rnrs/bytevectors.scm b/module/rnrs/bytevectors.scm
> index 9744359..856ad4a 100644
> --- a/module/rnrs/bytevectors.scm
> +++ b/module/rnrs/bytevectors.scm
> @@ -75,9 +75,12 @@
>  (load-extension (string-append "libguile-" (effective-version))
>                  "scm_init_bytevectors")
>  
> -(define-macro (endianness sym)
> -  (if (memq sym '(big little))
> -      `(quote ,sym)
> -      (error "unsupported endianness" sym)))
> +(define-syntax endianness
> +    (syntax-rules ()
> +        ((_ sym)
> +         (let ((qsym (quote sym)))
> +             (if (memq qsym '(big little))
> +                 qsym
> +                 (error "unsupported endianness" qsym))))))
>  
>  ;;; bytevector.scm ends here

(FYI, your mail ended up in my Gmail spam folder.  Don't know why.)

That definition is not equivalent, it moves the error to run-time.
Something like the following should be better:

(define-syntax endianness
  (syntax-rules ()
    ((_ big) 'big)
    ((_ little) 'little)))

This removes the "unsupported endianness" error and will instead raise a
generic syntax error ("source expression failed to match any pattern in
form ...").  This might just be enough, but if we want it a specific
error message could be achieved with `syntax-case', or a `syntax-error'
macro (used in an "else" clause of `syntax-rules').

Taylan



  reply	other threads:[~2013-09-28 10:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-28  5:25 [PATCH] Replace define-macro with syntax-rules KAction
2013-09-28 10:27 ` Taylan Ulrich B. [this message]
2013-09-29 20:38   ` Ian Price
2013-09-30 19:24     ` Taylan Ulrich B.

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=87mwmxgs1u.fsf@taylan.uni.cx \
    --to=taylanbayirli@gmail.com \
    --cc=KAction@gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=ludo@gnu.org \
    --cc=wingo@pobox.com \
    /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).