From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: Macro for replacing a placeholder in an expression Date: Thu, 28 Jul 2022 10:23:48 +0000 Message-ID: References: <80083c86-19b0-7537-be70-f763bd5b390f@posteo.de> <1ede5481-9d46-84e9-2530-d64ac835568b@telenet.be> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19591"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Maxime Devos Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Jul 28 12:24:38 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oH0h4-0004wA-Ee for guile-user@m.gmane-mx.org; Thu, 28 Jul 2022 12:24:38 +0200 Original-Received: from localhost ([::1]:37192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oH0h3-0002Cd-Bp for guile-user@m.gmane-mx.org; Thu, 28 Jul 2022 06:24:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oH0gO-0002Bd-Dh for guile-user@gnu.org; Thu, 28 Jul 2022 06:23:57 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:39731) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oH0gM-0003qo-8F for guile-user@gnu.org; Thu, 28 Jul 2022 06:23:56 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id EC748240107 for ; Thu, 28 Jul 2022 12:23:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1659003832; bh=4X2W+PQuyv0bWlFRo/v/kUf0YGpdKTydW+L4QmbPBCw=; h=Date:Subject:To:From:Cc:From; b=oJxN42XcmVCRz8eRqlFVQKE/zPqbFv1g96oWSZ+jhORBEjKoRWRZ7zkx5JPjuBlQ7 MpiD9phoDJrRQgSP2NXC+6yu43hUBrCQlu/mLBCI9A02b5FhX3B5dJE2ucN0lB5KQx f09hC5Ye37KPH06x8edHkIUB36JlBLlcKYDXPnvCwhegQb10aEN/2Sf0Osxqf6Emgn qhqmh2v6lI2z6V0GknEvEm8LLxztWrAroBSmVTw/wTjIT5EjwTSSmZNzhrL07bfMUQ lldC4hIeJojoipvBXnmk/H8QSY/0G0DvzlKjrA6i/apSvhJ1bhMivTMEetz/nPkFlN ZkM4Rucv6Hlpg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Ltmvm5MNbz6tmb; Thu, 28 Jul 2022 12:23:48 +0200 (CEST) Content-Language: en-US In-Reply-To: <1ede5481-9d46-84e9-2530-d64ac835568b@telenet.be> Received-SPF: pass client-ip=185.67.36.66; envelope-from=zelphirkaltstahl@posteo.de; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18459 Archived-At: Hello Maxime! On 7/28/22 02:55, Maxime Devos wrote: > > These macros all sound more complicated than necessary -- on the first one, > I've sent you a message with sneek: > > ;; By: Maxime Devos > > ;; This does not recurse into #(...). > ;; Also, such a construct does not nest well, you can't put a replace-result-placeholder inside a replace-result-placeholder meaningfully, > ;; so I'm wondering why you're doing this, maybe your goal can be accomplished more robustly with a different method. > (eval-when (expand load eval) > (define (replace-placeholder new code) ; <--- recursively transforms code to replace '' by new > (syntax-case code () > ( new) > ((x . y) > #`(#,(replace-placeholder new #'x) . #,(replace-placeholder new #'y))) > (rest #'rest)))) > > (define-syntax replace-result-placeholder > (lambda (s) > (syntax-case s () ; : placeholder > ((_ new code) (replace-placeholder #'new #'code))))) > > (display (replace-result-placeholder > quote > ( bar))) ; -> bar > > (I think thinking in terms of 'operations' and special-casing lambda etc would > make things harder here) > > As a bonus, this supports things like `((x . ) (z . w)) which aren't > supported by the original macro as that macro assumed lists. > > Greetings, > Maxime. > I'll need to look at this and learn about eval-when. I also did not think about vectors yet. Thank you! Best regards, Zelphir -- repositories:https://notabug.org/ZelphirKaltstahl