public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Expansion of a renamed macro seems to break hygiene
@ 2022-01-04 23:21 Panicz Maciej Godek
  0 siblings, 0 replies; only message in thread
From: Panicz Maciej Godek @ 2022-01-04 23:21 UTC (permalink / raw)
  To: kawa

Since I've recently been spending a bit more time in Kawa, I started to
transplant my "idiocyncracies" from other Schemes that I've been using.

One of them is the definition of optional and keyword arguments to
functions. Similarly to Guile, Kawa uses a DSSSL or Common Lisp style of
providing keyword and optional arguments, which isn't something that I like
for two reasons:

- first, it makes functions definitions look very differently from usages
of those functions
- second, it introduces many (i.e. three) special symbols, for
distinguishing optional, keyword and rest arguments

Therefore, I prefer to write, say

(define (copy! from: source to: destination size: size := (default-size))
 ...)

This introduces only one special symbol, namely :=.

 I wrote similar extensions for Guile and for Racket, which was easy,
because I could shadow the core bindings of the lambda and define forms
which expanded to those core forms. Guile allowed me to rename the bindings
(say, lambda/kw and define/kw) in the module's export spec.

I tried doing the same for Kawa. I wrote this module today:

https://github.com/panicz/grasp-android/blob/master/stages/retreat/GRASP/src/keyword-arguments.scm

When I ran a test:

(import (keyword-arguments))
(define/kw (f x := 5 y := 10 in: z := 15) (list x y z))
(f)

it worked as expected.

However, when I tried renaming the define/kw and lambda/kw forms to define
and lambda during import, i.e.

(import (rename (keyword-arguments) (define/kw define) (lambda/kw lambda)))

and then tried using the define form, as in, say

(define/kw (f x := 5 y := 10 in: z := 15) (list x y z))

it blew the stack. I suspect that the reason was that the define/kw macro
expanded not to the original Kawa's define form, but to the renamed
define/kw. I'm not sure how clear the standard is on this point, but I
think that it might be a wrong behavior.

I can easily find a workaround (because I saw that the Kawa's define form
expands to %define, and so I would do the same in my extension), but I
wonder if this behavior is intentional and whether it could possibly be
fixed.

Best regards,
Panicz

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-04 23:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-04 23:21 Expansion of a renamed macro seems to break hygiene Panicz Maciej Godek

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).