[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Moving kbd to subr.el

From: Lars Ingebrigtsen
Subject: Re: Moving kbd to subr.el
Date: Fri, 15 Oct 2021 12:28:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Stefan Kangas <stefankangas@gmail.com> writes:

> OK, so looking even closer at this to develop test cases for the above,
> in the original code we have this convoluted mess:
> (if (and (not need-vector)
>          (cl-loop for ch across res
>                   always (and (characterp ch)
>                               (let ((ch2 (logand ch (lognot ?\M-\^@))))
>                                 (and (>= ch2 0) (<= ch2 127))))))
>     (concat (cl-loop for ch across res
>                      collect (if (= (logand ch ?\M-\^@) 0)
>                                  ch (+ ch 128))))
>   res)

Yeah, my eyes glazed over when reading that code the first few times.

> But that is equivalent to:
>     (<= 0 ch 127)

I think...  you're totally right.  It looks like a very convoluted way
to write (<= 0 ch 127).

But perhaps there's historical reasons for the code being that way?  In
the olden days, Emacs didn't use utf-8 as the character representation,
so perhaps it made sense back then?  (I don't actually recall how
characters were represented in that Mule era.)

> BTW, you can verify the above simplification for yourself using:
> (let ((ch 0) accum)
>   (while (< ch #xFFFFFFF)
>     (when (and (characterp ch)
>              (let ((ch2 (logand ch (lognot ?\M-\^@))))
>                (and (>= ch2 0) (<= ch2 127))))
>       (push ch accum))
>     (setq ch (1+ ch)))
>   (let ((standard-output (current-buffer)))
>     (princ accum)))

I had to type it myself to convince myself:

(dotimes (ch #x3FFFFF)
  (unless (equal
           (and (characterp ch)
                (let ((ch2 (logand ch (lognot ?\M-\^@))))
                  (and (>= ch2 0) (<= ch2 127))))
           (<= 0 ch 127))
    (error "%s" ch)))

And no `error'.

(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

reply via email to

[Prev in Thread] Current Thread [Next in Thread]