From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Taylan Kammer Newsgroups: gmane.lisp.guile.devel Subject: Re: Lexically bound macro, with lexically bound transformer Date: Thu, 25 Jul 2024 11:50:59 +0200 Message-ID: <26582976-7f8b-4297-b7ec-15a87c83955c@gmail.com> References: <543f985e-eeeb-44a2-d376-af1576710070@purge.sh> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2398"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: spacecadet , guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Thu Jul 25 11:51:38 2024 Return-path: Envelope-to: guile-devel@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 1sWv8L-0000Un-Vn for guile-devel@m.gmane-mx.org; Thu, 25 Jul 2024 11:51:37 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWv7w-0000oA-DD; Thu, 25 Jul 2024 05:51:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWv7t-0000aI-PV for guile-devel@gnu.org; Thu, 25 Jul 2024 05:51:10 -0400 Original-Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWv7o-0008JA-OR for guile-devel@gnu.org; Thu, 25 Jul 2024 05:51:09 -0400 Original-Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a7a843bef98so33756366b.2 for ; Thu, 25 Jul 2024 02:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721901063; x=1722505863; darn=gnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=+6FyK5S4/0H+YQ79Q8lWqyNSV9H9Hpf4eL5MsiG3338=; b=iBVy12h0rQCEdY/pgj/5fcJMk11v7894gMxCNyjZrkK0IdrpNk6/evifFM1zB8cWtz pXxOxy6eHMjqGRDjBfOH08ZhrdcNY24BcvSp5GHKzPRpLPk3UpTTz/jO9h5JmNxvBdLY 0rlS7wxa2+a/S1DuR0fechfWL/L6lLMtOfkQuwYpDW+mBVDtpQXTdlKQvaC8aoP24ExO HWusUywKPCA5ojxstbbR0kZiJjGuyIThZLpCySLVlrgTNpM0hp/1Vz+yMwkC6yfwdMiq Z4Toqbex1xIqYkg9B2H8ffTUJT8aKtjCtRp5mrhRxt3IyKfICDU+RED/R2ShWI0K3UaM y6xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721901063; x=1722505863; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+6FyK5S4/0H+YQ79Q8lWqyNSV9H9Hpf4eL5MsiG3338=; b=ni8fUy1VquYMk9VmcCCxUioPdIkkTN8YWtJydz/DIQXD6DfxLKSUdweEU1AjTtGPoF HDGyCctNGcYMJzw7xQ3DUWXTrLAAmijxlKsQKb9b5pQXdPg7wnnVe1hfNEwPHQjEe5Pq GKTtbpd6tutAtyUSIu5Q+5KXZGaMaT6vsB8fLNsvycawHDMaQ3KlXNvkG+TxtlIkLcF/ p7sYpMQ8OuHx2NQoH+bXsUsoZRPl5N/JNXTGkerpmghTWIUiN6Qe0aqSdpqEQUEbF4dD 2nrRd0gq+bxUBio+6h/PDWOziPz02S7jnRIjnKBXfEc96rfu1T3Ry0LLuaOQ3AZe3sW6 OxlQ== X-Forwarded-Encrypted: i=1; AJvYcCV5LTKdofdoIZUhUNJMd75wjuAaNC7HWJcNTBtlcfcW44IudukF5slOx9lE2GWTo+wr6kqLXhgr98OxFpNiTVXilwrG X-Gm-Message-State: AOJu0Yyy/Zkwvfo6XRSB7Tr90r6aRZ43Rvr9eeFi0aBOp7V1mQOBCmly 6dfXCXamZUR9DydNnkohfCFPPyZPYeZCfj5jQNx4IdBpS2MzFrfHogko6qCK X-Google-Smtp-Source: AGHT+IGVYwHtXvlsBSZaoFNFIv7pX4rWYN0XB7ghc+XbEUEB6cEkvGDA3+gpLr3ig6S8k9eBz+S7KQ== X-Received: by 2002:a17:907:7244:b0:a7a:83a5:4a1d with SMTP id a640c23a62f3a-a7ac53549d0mr158663466b.69.1721901062785; Thu, 25 Jul 2024 02:51:02 -0700 (PDT) Original-Received: from ?IPV6:2003:106:8f00:2c00:e17f:d551:2644:2d46? (p200301068f002c00e17fd55126442d46.dip0.t-ipconnect.de. [2003:106:8f00:2c00:e17f:d551:2644:2d46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acad4146dsm54091766b.114.2024.07.25.02.51.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jul 2024 02:51:02 -0700 (PDT) Content-Language: en-US In-Reply-To: <543f985e-eeeb-44a2-d376-af1576710070@purge.sh> Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=taylan.kammer@gmail.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22658 Archived-At: On 24.07.2024 19:10, spacecadet wrote: >> I think the guile-user list might be more appropriate. > > Noted > >>    (let-syntax ((outer (lambda (x) #'(+ 1 2)))) >>      (let-syntax ((inner (lambda (x) (outer x)))) >>        (inner))) > > That works, but I guess this isn't possible then > > (lambda* (#:key outer) >   (let-syntax ((inner outer)) >     (inner ...))) > > Since that would require evaluating run-time code at compile-time > > Is there a way to write a macro that's expanded at run-time? > > It feels like I'm asking the wrong question now, but I'm > really looking for a way to bind macros at run-time > so they can be used functionally > > I guess the right answer is to use functions instead of macros? Yeah, it's generally a good idea to reserve macros for things that regular procedures (functions) simply can't do. Many things where one thinks of using a macro can be done using a higher-order functions instead. (I.e. a procedure that takes another procedure as an argument and executes it in some special context.) For example, let's say I want a way to time (benchmark) code. I could create a macro to do it like this: ;; Example code only, may not work properly (define-syntax time (syntax-rules () ((_ body ...) (let ((start-time (current-time))) body ... (- (current-time) start-time))))) (time (do-thing) (do-other-thing) (very-complicated-thing)) Or I could just use a higher-order function: (define (time thunk) (let ((start-time (current-time))) (thunk) (- (current-time) start-time))) (time (lambda () (do-thing) (do-other-thing) (very-complicated-thing))) -- Taylan