From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eduardo Ochs Newsgroups: gmane.emacs.help Subject: Re: [External] : Re: How do I pass a variable defined in a wrapping let, to a lambda? Date: Sat, 12 Mar 2022 19:33:45 -0300 Message-ID: References: <871qz85bwh.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28327"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs , Stefan Monnier To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 12 23:34:47 2022 Return-path: Envelope-to: geh-help-gnu-emacs@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 1nTAJz-00077m-QN for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 12 Mar 2022 23:34:47 +0100 Original-Received: from localhost ([::1]:45988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nTAJy-0003uF-EV for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 12 Mar 2022 17:34:46 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTAJF-0003tv-9J for help-gnu-emacs@gnu.org; Sat, 12 Mar 2022 17:34:01 -0500 Original-Received: from [2a00:1450:4864:20::232] (port=33737 helo=mail-lj1-x232.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nTAJD-0001P6-N4 for help-gnu-emacs@gnu.org; Sat, 12 Mar 2022 17:34:00 -0500 Original-Received: by mail-lj1-x232.google.com with SMTP id u3so16922516ljd.0 for ; Sat, 12 Mar 2022 14:33:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hrdDu8TOyN9mbTUT8iPtMJ+ltThICILoVYw8FuFRI6g=; b=XZKFyZRNlh3FzH+W/G1jiNDEXW0J1mR1Yi04lbpewUuuJDSjon7Bnc1Cj2tBhUtSt8 cnCugqTZoYwVZDZJE7mbYTO2+uuXEOrweGFNR9nc6Yaq38gPb7AaV+E4moM/TJ6EYCjZ KYiEjVfpbKYNFtEw2M9fWg5gxfJa5X5F7kCDuO4L8BA2XbaVsPTQ/fK0FrvwXpatFTuE tn9xS5/6vfQ/WDEtbuz4qqkQe/TkqZ2cMJBTAQfhQKBuownXkFTcHvgcqonTfWsICVFS 7gj610Am+SaT77nWk/7GPjrLiBtxQ7tdD4NaijjqHVGub9S/0hLuWFKG1/TsBLe9LwJb NSEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hrdDu8TOyN9mbTUT8iPtMJ+ltThICILoVYw8FuFRI6g=; b=ups2M1CyvL8Hcbp1d/moNZTJ1uAcr5dPC+Toa5aLgLTgjh+MvjKOMzHmzRVArrCA8T 0Zxsuv+uxXPQnkMT5r0B1iByqCehhUr72BjmX4205VQVT01y9GQsX5921/tqHQfkNlts B9fokrJ4SAKI1O5oTsnb2Mel3HnqURkpJOfDxOg0nnr8H12RfvQPzJcwsFUkjlaivetX IOVbgMIL4a58CytPlu68vvkGkE0jpB/fjv0zFdsqtposAu5r0thfjVFCyqnKTcrhD+IN ZrA6Y6KdlOwWc9OyOG8lx6h+WTwkn6pYTQZXsb+75U6YX8ra25HXQ5n7UGbpcLxvhKCN EFIQ== X-Gm-Message-State: AOAM530V97r/y673qDFJ3BoXgHdcW7Mk9yIjXST8xWm4peZzowCobtnC wU0pjiZpBhQFblJc9mp0VSiDmsa9Nhd7tLFtQfA= X-Google-Smtp-Source: ABdhPJz9vJ7KdTFrTEWfKY40WTm+5iz4+5ck5JWktu600MLtfk4OUfxJEnE7Yg8oU44PpJUCD6nxVvQVOJPc4UpokaI= X-Received: by 2002:a05:651c:160b:b0:247:f955:1b18 with SMTP id f11-20020a05651c160b00b00247f9551b18mr10080599ljq.427.1647124437413; Sat, 12 Mar 2022 14:33:57 -0800 (PST) In-Reply-To: X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::232 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=eduardoochs@gmail.com; helo=mail-lj1-x232.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:136506 Archived-At: On Sat, 12 Mar 2022 at 17:32, Drew Adams wrote: > > > > `-*- lexical-binding:t -*-` doesn't prevent the use of > > > dynamic scoping. > > > > How do I define a function that uses dynamic binding in a > > file that has `-*- lexical-binding:t -*-`? > > A _function_ that uses it? Just what do you mean by that? > > Function names are (typically) bound dynamically, with defun. > ___ > > For a variable, you use a vacuous defvar: > > (defvar foo) ; "special" var, i.e. dynamically bound Hi Drew, Here is something that I don't know how to port to lexical binding. My functions that call `ee-template00' are all defined in files with "-*- lexical-binding: nil; -*-" - they don't work if I put them in files with "-*- lexical-binding: t; -*-". Cheers, E. (defvar ee-template00-re "{\\([^{}]+\\)}") ;; Tests: ;; (ee-template00 "a{(+ 2 3)}b") ;; (let ((hi "Here: ") (a 22) (b 33)) (ee-template00 "{hi}{a}+{b}={(+ a b)}")) ;; (defun ee-template00 (str) "Replace substrings enclosed by `{}'s in STR by the result of evaluating them. Examples:\n (ee-template00 \"a{(+ 2 3)}b\") --> \"a5b\"\n (let ((hi \"Here:\") (a 22) (b 33)) (ee-template00 \"{hi} {a} + {b} = {(+ a b)}\")) --> \"22 + 33 = 55\"" (save-match-data (replace-regexp-in-string ee-template00-re (lambda (_code_) (format "%s" (eval (read (substring _code_ 1 -1))))) str 'fixedcase 'literal))) ;; Test: ;; (ee-dynlex-test "Aa" "Bb") ;; The sexp above returns this with dynamic binding, ;; "" ;; and yields this error in lexical binding: ;; "format: Symbol's value as variable is void: a" ;; (defun ee-dynlex-test (a b) (let* ((aa (concat a a)) (bb (concat b b))) (ee-template00 "<{a} {aa} {b} {bb}>")))