define-macro Marc Nieper-Wißkirchen (17 Oct 2019 08:52 UTC)
Referentially transparent implementation for Guile Lassi Kortela (17 Oct 2019 09:37 UTC)

define-macro Marc Nieper-Wißkirchen 17 Oct 2019 08:51 UTC

Hi Lassi,

several implementations that you provide in the git repository are
based on `define-macro' (or similar constructs).

The problem with `define-macro' is that it does not preserve
referential transparency so the implementations are somewhat broken.

For example, the Guile implementation breaks if `lambda*' is being
rebound by a user of the `keyword-lambda' macro.

A (hopefully) correct implementation of `keyword-lambda' for Guile,
for example, would be:

(define-syntax keyword-lambda
  (lambda (stx)
    (syntax-case stx ()
      ((_ (formals ... (keyword-symbols ...)) . body)
       #'(lambda* (formals ... #:key keyword-symbols ...) . body)))))

(One may even rewrite this into a `syntax-rules' macro, which,
however, isn't possible for the `keyword-call' macro in the Guile
implementation; this has to be implemented in terms of `syntax-case'.)

Cheers,

Marc