From: "João Távora" <joaotavora@gmail.com>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: A short defense of shorthands.el (but CL packages are still better) (Was: Help sought understanding shorthands wrt modules/packages)
Date: Thu, 3 Nov 2022 20:04:18 +0000 [thread overview]
Message-ID: <CALDnm53bxvKKXkW5Y0qQORNzCvA1Yc892LbbFtiddK=EYHTR3Q@mail.gmail.com> (raw)
In-Reply-To: <m2leoswri1.fsf@Mini.fritz.box>
[-- Attachment #1: Type: text/plain, Size: 4443 bytes --]
On Thu, Nov 3, 2022 at 5:12 AM Gerd Möllmann <gerd.moellmann@gmail.com>
wrote:
João Távora <joaotavora@gmail.com> writes:
> Hi Gerd, I'm there one who implemented shorthands in Emacs, and i sure
> don't think they are a substitute for CL packages.
Thanks for letting me know, Joao.
No problem. Allow me to mount a short defense of shorthands. In doing
so, I don't mean to imply -- by any measure -- that CL packages are a
much welcomed addition to Emacs. They are, absolutely.
* shorthands are designed to perform namespacing operations with minimal
or even no changes to the Lisp forms of an Elisp file. The
hypothetical file x.el:
(defvar x--bar 42)
(defun x-foo () x--bar)
(provide 'x)
;; x.el ends here
;; Local Variables:
;; read-symbol-shorthands: (("x-" . "xenomorph-"))
;; End:
which will pollute the global namespace when loaded into Emacs 27,
will, when loaded into Emacs >28, intern xenomorph--bar and
xenomorph-foo instead of x--bar and x-foo.
Its user file yummy.el
(require 'x)
(defun yummy () (x-foo))
;; yummy.el ends here
;; Local Variables:
;; read-symbol-shorthands: (("x-" . "xenomorph-"))
;; End:
can also be loaded into Emacs 27 and Emacs 28. The interaction
between the two packages works in both cases, but in Emacs 28 the
global namespace won't be polluted.
* The above use case was motivated by the s.el, dash.el and f.el
libraries which incur in this namespace pollution. To be clear, all
packages pollute the namespace but these short prefixed ones were
especially heavy polluters, since short names naturally appear more
frequently in completion lists.
* If CL packages had been used instead, this "double duty" wouldn't have
been possible, because x.el and y.el would have to be changed
considerably (admittedly in a rather straightforward fashion)
* When shorthands were presented, much criticism was leveled at it, some
stemming from a misunderstanding of the specific problem this attempts
to solve.
* But one of the criticisms is pretty reasonable: this "breaks grep"
because the same symbol can now be referenced by two different
character strings from two different contexts. Also two different
symbols are designated by the same character string, again in two
different contexts.
However, the same is true for every namespacing facility by
definition. This is what namespacing systems do.
* Anyway, the problem is that
grep xenomorph-foo x.el yummy.el
doesn't return anything, even though xenomorph-foo is really
the name of the symbol in obarray. Obviously, grep doesn't
understand ELisp.
* In my opinion, the part that is missing from shorthands is a tool that
replaces grep (for Lisp symbolic uses, of course) and understands and
can be used as a backend for xref-find-references. One can think
of different approaches for realizing this tool
* The most promising approach, IMO, to fix this is to create a new
binary program, call it 'sexgrep' (for "Symbolic Expression Grep")
which can be run separately from Emacs but which uses Emacs's reader
syntax. It could reuse lread.c maybe, or reimplement relevant parts
of it. The program's input is a full symbol name and a number of
Elisp files. By using a source-tracking reader and understanding the
relatively simple syntax of shorthand definitions, it'll make
sexpgrep xenomorph-foo yummy.el x.el
find matches for the search pattern in those two files (on line 2)
respectively.
* Taking the approach with CL packages would be more difficult, because
the program would need to have a Lisp evaluator that understands
CL:DEFPACKAGE and CL:IN-PACKAGE, not just a reader. This is why, in
the Common Lisp implementations that I've used, a global in-memory
database of symbols is used instead. The database is kept up-to-date
whenever the code is read and loaded (which may occur in two different
moments in time, if compiled files are used).
This also works nicely (SLIME and SLY use it to great effect). But it
fails to search code that isn't loaded and is subject to some annoying
but resolvable problems (like when loading CL fasls that were compiled
on a different machine, for example. Maybe Helmut Eller, SLIME
author, has some good input in this regard)
[-- Attachment #2: Type: text/html, Size: 5007 bytes --]
next prev parent reply other threads:[~2022-11-03 20:04 UTC|newest]
Thread overview: 123+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-30 6:45 Help sought understanding shorthands wrt modules/packages Gerd Möllmann
2022-10-30 8:38 ` tomas
2022-10-30 8:54 ` Eli Zaretskii
2022-10-30 9:14 ` tomas
2022-10-30 10:26 ` Gerd Möllmann
2022-10-30 10:52 ` Eli Zaretskii
2022-10-30 11:24 ` Is there a need for a module system Gerd Möllmann
2022-10-30 11:38 ` Eli Zaretskii
2022-10-30 14:03 ` Gerd Möllmann
2022-10-30 10:40 ` Help sought understanding shorthands wrt modules/packages Eli Zaretskii
2022-10-30 11:06 ` tomas
2022-10-30 11:19 ` Eli Zaretskii
2022-10-30 12:50 ` Stefan Monnier
2022-10-30 13:48 ` Gerd Möllmann
2022-10-30 14:25 ` Stefan Monnier
2022-10-31 6:31 ` Gerd Möllmann
2022-10-30 20:16 ` Helmut Eller
2022-10-31 6:27 ` Gerd Möllmann
2022-10-31 12:13 ` Juanma Barranquero
2022-10-31 12:57 ` Gerd Möllmann
2022-10-31 13:38 ` Juanma Barranquero
2022-10-31 19:53 ` Stefan Monnier
2022-11-11 4:35 ` Richard Stallman
2022-11-11 9:33 ` Gerd Möllmann
2022-11-13 4:17 ` Richard Stallman
2022-11-13 6:41 ` Gerd Möllmann
2022-11-03 3:17 ` Richard Stallman
2022-11-03 5:33 ` Gerd Möllmann
2022-11-03 3:17 ` Richard Stallman
2022-11-03 8:12 ` Michael Albinus
2022-11-03 3:17 ` Richard Stallman
2022-11-03 8:46 ` Eli Zaretskii
2022-11-05 16:49 ` Richard Stallman
2022-11-05 17:04 ` Eli Zaretskii
2022-11-07 7:47 ` Richard Stallman
2022-11-07 12:52 ` Eli Zaretskii
2022-11-08 6:19 ` Gerd Möllmann
2022-11-08 9:54 ` João Távora
2022-11-08 10:35 ` Gerd Möllmann
2022-11-08 15:40 ` João Távora
2022-11-08 15:47 ` Stefan Kangas
2022-11-08 22:43 ` João Távora
2022-11-09 6:57 ` Gerd Möllmann
2022-11-09 7:23 ` Gerd Möllmann
2022-11-11 4:34 ` Richard Stallman
2022-11-11 9:25 ` Gerd Möllmann
2022-11-12 3:35 ` Richard Stallman
2022-11-19 22:51 ` [External] : " Drew Adams
2022-11-20 7:18 ` Eli Zaretskii
2022-11-20 18:55 ` [External] : " Drew Adams
2022-11-20 19:02 ` Eli Zaretskii
2022-11-22 12:14 ` [External] : " Richard Stallman
2022-11-22 14:22 ` Eli Zaretskii
2022-11-20 8:08 ` Gerd Möllmann
2022-11-12 3:35 ` Richard Stallman
2022-11-22 19:37 ` Matt Armstrong
2022-11-23 7:33 ` Juanma Barranquero
2022-11-26 23:32 ` Richard Stallman
2022-11-27 9:05 ` Juanma Barranquero
2022-11-30 23:55 ` Richard Stallman
2022-11-23 7:42 ` Gerd Möllmann
2022-12-14 22:21 ` Richard Stallman
2022-12-15 6:47 ` Eli Zaretskii
2022-12-17 14:53 ` Richard Stallman
2022-11-22 18:01 ` Matt Armstrong
2022-11-22 18:44 ` Eli Zaretskii
2022-11-23 0:55 ` Matt Armstrong
2022-11-23 7:49 ` Gerd Möllmann
2022-11-23 12:18 ` Eli Zaretskii
2022-11-11 4:35 ` Richard Stallman
2022-11-11 9:35 ` Gerd Möllmann
2022-11-11 12:09 ` João Távora
2022-11-11 13:01 ` Gerd Möllmann
2022-11-11 14:23 ` João Távora
2022-11-11 15:12 ` Gerd Möllmann
2022-11-12 9:17 ` João Távora
2022-11-12 13:00 ` Gerd Möllmann
2022-11-12 3:35 ` Richard Stallman
2022-11-05 21:47 ` Eduardo Ochs
2022-11-06 9:05 ` Michael Albinus
2022-11-06 11:19 ` João Távora
2022-11-11 4:35 ` Richard Stallman
2022-11-11 10:09 ` João Távora
2022-11-12 3:35 ` Richard Stallman
2022-11-12 10:11 ` João Távora
2022-11-12 14:36 ` Dmitry Gutov
2022-11-12 15:20 ` João Távora
2022-11-12 17:32 ` Dmitry Gutov
2022-11-12 18:45 ` João Távora
2022-11-14 1:03 ` Dmitry Gutov
2022-11-14 6:33 ` João Távora
2022-11-14 11:41 ` Dmitry Gutov
2022-11-14 13:41 ` João Távora
2022-11-14 3:13 ` Richard Stallman
2022-11-11 4:35 ` Richard Stallman
2022-11-11 8:53 ` Michael Albinus
2022-11-11 4:35 ` Richard Stallman
2022-11-11 7:10 ` Helmut Eller
2022-11-01 3:11 ` Ag Ibragimov
2022-11-02 20:11 ` João Távora
2022-11-03 5:12 ` Gerd Möllmann
2022-11-03 20:04 ` João Távora [this message]
2022-11-04 3:28 ` A short defense of shorthands.el (but CL packages are still better) (Was: Help sought understanding shorthands wrt modules/packages) Richard Stallman
2022-11-05 1:09 ` A short defense of shorthands.el (but CL packages are still better) João Távora
2022-11-07 7:44 ` Richard Stallman
2022-11-07 10:18 ` João Távora
2022-11-08 5:02 ` Richard Stallman
2022-11-08 5:18 ` João Távora
2022-11-05 3:13 ` Help sought understanding shorthands wrt modules/packages Richard Stallman
2022-11-06 11:31 ` João Távora
2022-11-08 0:27 ` Matt Armstrong
2022-11-08 4:52 ` João Távora
2022-11-08 5:34 ` Gerd Möllmann
2022-11-09 4:03 ` Richard Stallman
2022-11-09 5:42 ` Yuri Khan
2022-11-09 5:48 ` tomas
2022-11-09 6:02 ` Matt Armstrong
2022-11-09 7:15 ` Juanma Barranquero
2022-11-09 8:34 ` Gerd Möllmann
2022-11-09 10:07 ` Helmut Eller
2022-11-09 18:22 ` Matt Armstrong
2022-11-09 4:03 ` Richard Stallman
2022-11-09 5:13 ` Matt Armstrong
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='CALDnm53bxvKKXkW5Y0qQORNzCvA1Yc892LbbFtiddK=EYHTR3Q@mail.gmail.com' \
--to=joaotavora@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=gerd.moellmann@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).