guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Replace define-macro with syntax-rules


From: Taylan Ulrich B.
Subject: Re: [PATCH] Replace define-macro with syntax-rules
Date: Sat, 28 Sep 2013 12:27:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix)

address@hidden writes:

> From: Dmitry Bogatov <address@hidden>
>
> 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 <address@hidden>
> ---
>  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 via email to

[Prev in Thread] Current Thread [Next in Thread]