Eric Bavier <ericbav...@openmailbox.org> skribis:

> From: Eric Bavier <bav...@member.fsf.org>
>
> * guix/utils.scm (substitute-keyword-arguments): Allow default value
> declarations.
> * tests/utils.scm (substitute-keyword-arguments): New test.

Good idea!


[...]

> +replaced by EXP.  EXP is evaluated in a context where VAR is bound to the
> +previous value of the keyword argument, or DFLT if given."
> +    (syntax-case x ()
> +      ((_ original-args ((kw var dflt ...) exp) ...)
> +       #`(let loop ((args (default-keyword-arguments
> +                            original-args
> +                            (list #,@(append-map (match-lambda
> +                                                   ((k) '())
> +                                                   (x x))
> +                                                 #'((kw dflt ...) ...)))))
> +                    (before '()))

I would prefer to stick to ‘syntax-rules’ when matching the clauses,
with a helper macro:

  (define-syntax expand-default-args
    (syntax-rules ()
      ((_ original args ((kw var) expr) rest ...)
       ...)
      ((_ original args ((kw var default) expr) rest ...)
       ...)))

  …

    (syntax-rules ()
      ((_ original-args ((clause exp) ...)
       (let loop ((args (expand-default-args original-args clause ...)))
         …))))

But this would be a bonus; the patch LGTM.

Thanks!

Ludo’.

Reply via email to