🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.lisp
Article #32

Re: GNU Emacs native compiled functions

#32
From: Lawrence D’Oliveiro
Date: Thu, 15 Oct 2026 21:33
90 lines
6556 bytes
On Tue, 6 Oct 2026 20:51:02 -0000 (UTC), I wrote:

> On Tue, 06 Oct 2026 08:34:15 -0400, Stefan Monnier wrote:
>
>> The move to lexical scoping eliminated that problem and brought the
>> joy of closures with it (the lack of closures was mostly not
>> perceived as a problem: the coding style just "naturally" avoided
>> them, and for those rare cases where they were really handy you
>> could use hacks like backquoted lambdas or `lexical-let`).
>
> I can’t imagine how you could have functions as first-class objects
> without closures. At the very least, you would end up writing a lot
> more repetitive code, which I hate.

Well, the discussion got derailed by some irrelevancies that somehow
crept in to responses over the first example I posted -- which wasn’t
really a good illustration of closures anyway; I realized it would
probably work just as well with dynamic binding.

So, to start again, here’s a much more elaborate example, which you
can see in all its horrible glory at
<https://gitlab.com/ldo/emacs-prefs/-/blob/master/alt-alphanumerics.el>.
The idea is to create a function factory that defines a set of
functions for converting ordinary letters and numbers in selected text
into the various sets of those weird alternative alphanumerics
available in Unicode. Instead of writing out each function in full,
with lots of repetitive code, I define a set of translation tables,
and use a closure to construct the appropriate mapping command for
each one.

Having defined a generic “to-alt-alphanumerics” function that, given
the name of one of these alternate ranges of alphanumerics, converts
the text to those characters, the following code generates a
customized version for each range name:

    (dolist
        ; define the commands for converting regular text to each alternate alphanumeric range
        (convdef
            '( ; funcname rangename
                ; "double-struck italic" -- only partial
                (to-circled-alt-alpha "circled")
                (to-parenthesized-alt-alpha "parenthesized")
                (to-full-stop-alt-alpha "full stop")
                (to-comma-alt-alpha "comma")
                (to-double-circled-alt-alpha "double circled")
                (to-negative-circled-alt-alpha "negative circled")
                (to-dingbat-circled-sans-serif-alt-alpha "dingbat circled sans-serif")
                (to-dingbat-negative-circled-sans-serif-alt-alpha "dingbat negative circled sans-serif")
                (to-fullwidth-alt-alpha "fullwidth")
                (to-squared-alt-alpha "squared")
                (to-negative-squared-alt-alpha "negative squared")
                (to-double-struck-alt-alpha "double-struck")
                (to-mathematical-bold-alt-alpha "mathematical bold")
                (to-mathematical-italic-alt-alpha "mathematical italic")
                (to-mathematical-bold-italic-alt-alpha "mathematical bold italic")
                (to-mathematical-script-alt-alpha "mathematical script")
                (to-mathematical-bold-script-alt-alpha "mathematical bold script")
                (to-mathematical-bold-fraktur-alt-alpha "mathematical bold fraktur")
                (to-mathematical-sans-serif-alt-alpha "mathematical sans-serif")
                (to-mathematical-sans-serif-bold-alt-alpha "mathematical sans-serif bold")
                (to-mathematical-sans-serif-italic-alt-alpha "mathematical sans-serif italic")
                (to-mathematical-sans-serif-bold-italic-alt-alpha "mathematical sans-serif bold italic")
                (to-mathematical-monospace-alt-alpha "mathematical monospace")
                (to-turned "turned")
            )
        )
        (let
            (
                (funcname (car convdef))
                (rangename (cadr convdef))
            )
            (setf (symbol-function funcname)
                (lambda (beg end)
                    (interactive "*r")
                    (to-alt-alphanumerics beg end rangename)
                ) ; lambda
            )
        ) ; let
    ) ; dolist

I still find some quirks in the way Emacs does lexical binding; do you
need a “;;; -*- lexical-binding: t; -*-” header comment line, or can
it be done with regular lisp code as “(setq lexical-binding t)”? Also,
the above code is followed by this line

    (setq lexical-binding nil)

because otherwise I found that subsequent use of “(deactivate-mark)”
was liable to misbehave otherwise. (This might be fixed in newer Emacs
versions.)
Technical Details
Message-ID: <11argqv$2p8h1$3@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <113ovuj$23t9c$1@dont-email.me> <114ge0v$24ndu$2@dont-email.me> <114h1v7$2b0po$2@dont-email.me> <114h24r$9nm$1@reader1.panix.com> <114h26m$2b0po$3@dont-email.me> <114kain$3erqe$1@dont-email.me> <114oc02$qbqp$1@dont-email.me> <114odai$qp0b$1@dont-email.me> <114piou$14lmv$2@dont-email.me> <114pno3$16g53$1@dont-email.me> <114pqg5$17lne$1@dont-email.me> <5T_bS.71191$4Fu9.56234@fx05.ams4> <27248.58134.739884.512819@parhasard.net> <87v78mz15a.fsf_-_@debian> <m3h5k5n2au.fsf@pison.robolove.meer.net> <87wlsmo83m.fsf@debian> <m3tsno4bob.fsf@pison.robolove.meer.net> <jwveceqwtg2.fsf-monnier+comp.lang.lisp@gnu.org> <118kcc1$1mri1$2@dont-email.me> <87wlrvendh.fsf@gmail.com> <20261005164228.546@kylheku.com> <jwvo6d7hv2g.fsf-monnier+comp.lang.lisp@gnu.org> <11a3mvl$29qvc$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Lawrence D’Oliveiro <ldo@nz.invalid>
Newsgroups: comp.lang.lisp
Subject: Re: GNU Emacs native compiled functions
Date: Thu, 15 Oct 2026 21:33:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 90
Message-ID: <11argqv$2p8h1$3@dont-email.me>
References: <113ovuj$23t9c$1@dont-email.me> <114ge0v$24ndu$2@dont-email.me>
	<114h1v7$2b0po$2@dont-email.me> <114h24r$9nm$1@reader1.panix.com>
	<114h26m$2b0po$3@dont-email.me> <114kain$3erqe$1@dont-email.me>
	<114oc02$qbqp$1@dont-email.me> <114odai$qp0b$1@dont-email.me>
	<114piou$14lmv$2@dont-email.me> <114pno3$16g53$1@dont-email.me>
	<114pqg5$17lne$1@dont-email.me> <5T_bS.71191$4Fu9.56234@fx05.ams4>
	<27248.58134.739884.512819@parhasard.net> <87v78mz15a.fsf_-_@debian>
	<m3h5k5n2au.fsf@pison.robolove.meer.net> <87wlsmo83m.fsf@debian>
	<m3tsno4bob.fsf@pison.robolove.meer.net>
	<jwveceqwtg2.fsf-monnier+comp.lang.lisp@gnu.org>
	<118kcc1$1mri1$2@dont-email.me> <87wlrvendh.fsf@gmail.com>
	<20261005164228.546@kylheku.com>
	<jwvo6d7hv2g.fsf-monnier+comp.lang.lisp@gnu.org>
	<11a3mvl$29qvc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 15 Oct 2026 21:33:20 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2925089"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+MjQ2cAu6e6VcGOYwl+PB/"; posting-host="9e9d07bb7cf82d8413472acd2badee74"
User-Agent: Pan/0.165 (Kostiantynivka)
Cancel-Lock: sha1:o7Z9bENUl78WsGmjeLwop9Y6CPw= sha256:IhAsMiI/lXZpDuBBwE/0JBUAfzymaEyf84rvdp9Rfmo=
	sha1:HIYEaVjXweK4H5JU7MFv4SAJH/E= sha256:icYHHugvhJz/liKh+BAbstsL+EI1WyRWDe/3YXlQ4k0=