From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-200160.simplelogin.co (mail-200160.simplelogin.co [176.119.200.160]) by sourceware.org (Postfix) with ESMTPS id 36D3A3858D32 for ; Mon, 8 May 2023 15:28:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36D3A3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=simplelogin.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simplelogin.com Date: Mon, 08 May 2023 15:28:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=simplelogin.com; s=dkim; t=1683559727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LpBOKoFUiQI6Si9F2uXlUdfXdM5LhDupwhyzh2+EwA8=; b=t1uY5S2LnDgc+LkKt+cG3JMgQX/DRYNPw41aUms2Xp8G5zQFobcMXd4e8n8L6Fpl0PMAu/ C3nsOOJAGgnx1t9J1zPzq2DHbatc3kbvzynzMsAXo3j9oLtncQZW4ymuzrHmL6zXwHejN+ bxvegjjh6U2rFmv52QtL5gCxT7xQMo8= Subject: `begin-for-syntax` and `define-for-syntax` violate hygiene when used inside macro templates MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha512; boundary="------ed4ddfe949fecfe9f2d5ec2e186759ec59a6f3265323018adc918f2dfe1ba0e3"; charset=utf-8 Content-Transfer-Encoding: 7bit From: alexvong.90frf@simplelogin.com To: kawa@sourceware.org Message-ID: <168355972739.7.1921650802292105194.127745684@simplelogin.com> X-SimpleLogin-Type: Reply X-SimpleLogin-EmailLog-ID: 127745684 X-SimpleLogin-Want-Signing: yes X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------ed4ddfe949fecfe9f2d5ec2e186759ec59a6f3265323018adc918f2dfe1ba0e3 Content-Type: multipart/mixed;boundary=---------------------5e026affbb8e8ec2a6f1c21fdd905740 -----------------------5e026affbb8e8ec2a6f1c21fdd905740 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain;charset=utf-8 Hi! I think the current implementation of `begin-for-syntax` and `define-for-s= yntax` violate hygiene when used inside macro templates. For examples, if we run: ``` (begin-for-syntax (define (foo) 42)) (begin-for-syntax (display (foo)) (newline)) ``` Both kawa and racket display 42 correctly. But if we modify the program to= place `begin-for-syntax` inside a macro templates: ``` (define-syntax install-foo! (syntax-rules () ((_) (begin-for-syntax (define (foo) 42))))) (install-foo!) (begin-for-syntax (display (foo)) (newline)) ``` Racket signals the following error: ``` foo: undefined; cannot reference an identifier before its definition in module: top-level context...: top-level: [running body] ``` but kawa displays 42, violating hygiene. Similar results are obtained if we replace `begin-for-syntax` by `define-f= or-syntax` or use guile instead of racket. In the case of guile, we need t= o use `(eval-when (expand load eval) ...)` rather than `begin-for-syntax`. Currently, we can workaround this issue by using `generate-temporaries` an= d `with-syntax`: ``` (define-syntax install-foo! (lambda (stx) (syntax-case stx () ((_) (with-syntax (((foo) (generate-temporaries #'(foo)))) #'(begin-for-syntax (define (foo) 42))))))) ``` We can even generate an uninterned symbol and then convert it to an syntax= object for extra safety if we wish to do so. -- Alex My PGP public key: https://salsa.debian.org/alexvong243f/pgp-key/-/raw/mas= ter/A5FCA28E0FF8E4C57F75555CDD66FE5CB79F5A5E.asc -----------------------5e026affbb8e8ec2a6f1c21fdd905740-- --------ed4ddfe949fecfe9f2d5ec2e186759ec59a6f3265323018adc918f2dfe1ba0e3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: ProtonMail wsFzBAEBCgAnBYJkWRUNCZAxvMk8e+NC0hYhBLUlPl0s98aXuuU/pDG8yTx7 40LSAAAR4w/7By+cq1oUo0iSiwKLqNxYy77hLV25cimss4cDTO/b21okct6P KBvX7S8Xrx2bUv7RV0wONlFjb+UOqaK2CTw/mfP9Zx/LJfGsNsBIw6AOxyGs gzMdP8gH8ooNlVmqWXEzgco0AX1IS2BbAoSfyOaB1mH6ff0ogfqF/TQD0UMi ZqzIwhIguOGyPY4pWbrM0nSIr2vl8JCnarckoVuMmxHbfDzD2JvSmT6wEBbX UNPMRS0LG9vt+1Z/0MVgLGWJ5DlY6YrFo+5MlOvXOr5u0zVxNwpzj5Ccbyh8 vtYFOaBQ9MQMM8/oIHuh8KoGmmJzveMCcvEw3l2ISi7I2ydaJt9K7G1gEjaR sHRPX4A87UMMmxEOaIdFKUJGc2Nh+cYNYRofvw2/9ZQAeTJ4KbgMcGmhOXFK 1/OdKaXkWM7pon01DjvJrVMf4Bv3J/mP96QcJfi42hTnQ3kt55HZZW3xEnAo 7gs+FUAWKRGVdGhUWvfW5k2nCZRByDreVhrckrKvhy+rTwQQF8a/QDDFbk6t 6SP3XSXe3rp5tXbfBkJ9Y2Ek6PIBE2Zsc2w5cVpdzn40TDoydv/t0wOi1SN+ io7HL0r3rUMpgYTO2+FeZj6sc3iJXhkOd1Qrvi28BEk3QWBpQfpgeEr+khkd SAVU9hEmLBhnWNGoHlcwR7Ze/3fYXhpT1U0= =EiWC -----END PGP SIGNATURE----- --------ed4ddfe949fecfe9f2d5ec2e186759ec59a6f3265323018adc918f2dfe1ba0e3--