From: Platon Pronko <platon7pronko@gmail.com>
To: Madhu <enometh@meer.net>, help-gnu-emacs@gnu.org
Subject: Re: the (declare special) declaration with lexical scope.
Date: Sun, 23 Apr 2023 17:47:40 +0800 [thread overview]
Message-ID: <d4e72287-61c4-129c-9886-c0881237b9da@gmail.com> (raw)
In-Reply-To: <m31qkbnq3r.fsf@leonis4.robolove.meer.net>
I'm not qualified to answer the question about lexical scope.
However I'm interested why you didn't consider to make the entire mustache function
into a macro that expands to concat call with variables already interpolated?
This way it will work regardless of lexical or dynamic binding.
I suppose this might break if template is dynamically generated somewhere,
however templates are usually static and thus can be embedded at compile time
(it will be the fastest-performing option, aside from other benefits).
Here's an example of what I mean:
(defun mustache-build (template)
(let ((pattern-start (string-match "{{\\(.*?\\)}}" template)))
(if (not pattern-start)
template
`(,(substring template 0 pattern-start)
(prin1-to-string ,(intern (match-string 1 template)))
,@(if (>= (match-end 0) (length template)) nil (mustache-build (substring template (match-end 0))))))))
(defmacro mustache (template)
`(concat ,@(mustache-build template)))
(macroexpand '(mustache "a={{a}} b={{b}}"))
; (concat "a=" (prin1-to-string a) " b=" (prin1-to-string b))
(let ((a 42) (b '(+ 2 3)))
(mustache "a={{a}} b={{b}}"))
; "a=42 b=(+ 2 3)"
--
Best regards,
Platon Pronko
PGP 2A62D77A7A2CB94E
next prev parent reply other threads:[~2023-04-23 9:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-23 5:07 the (declare special) declaration with lexical scope Madhu
2023-04-23 9:47 ` Platon Pronko [this message]
2023-04-24 2:16 ` Madhu
2023-04-23 14:22 ` Emanuel Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d4e72287-61c4-129c-9886-c0881237b9da@gmail.com \
--to=platon7pronko@gmail.com \
--cc=enometh@meer.net \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).