unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Richard Stallman <rms@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Help sought understanding shorthands wrt modules/packages
Date: Fri, 11 Nov 2022 10:25:45 +0100	[thread overview]
Message-ID: <m2cz9tvo4m.fsf@Mini.fritz.box> (raw)
In-Reply-To: <E1otLkh-0006ry-L2@fencepost.gnu.org> (Richard Stallman's message of "Thu, 10 Nov 2022 23:34:51 -0500")

Richard Stallman <rms@gnu.org> writes:

> [[[ To any NSA and FBI agents reading my email: please consider    ]]]
> [[[ whether defending the US Constitution against all enemies,     ]]]
> [[[ foreign or domestic, requires you to follow Snowden's example. ]]]
>
>   > What I meant was using shorthands as the basis for a general mechanism
>   > that somehow solves a "problem" that other languages use modules for.
>
> Modules in other languages work correctly because they operate on
> variable _meanings_.  For instance, on function definitions, on
> variables, on classes, on class methods.  If one name is the name of a
> function and the name of a variable, the module system handles each of
> those meanings separately.

I must admit that I don't understand what you are referring to.  Could
you please give an example of a module system doing that?  At first
glance It sounds like visibility rules, or something, but I don't
remember a language with different visibility rules for functions and
variables, ATM.

> It's not possible to do that job correctly in Lisp at read time,
> because that precludss handling each meaning of the symbol separately.
> Inevitably, CL packages are flawed compared with other languages'
> module systems.  The basic design decision to make them work at the
> level of reading made that inevitable.  We can call this the
> "polyvalency problem."

Well.  Let me start by saying that I don't think of CL packages as
modules, but, if anything but packages, as namespaces.  The term module
is somewhat open to definition, different languages use the term
differently.  Some even have both with completely different menaings,
like C++.

>
> Module systems in other languages fit together with lexical scoping.
> Lexically scoped local variables, functions, or classes don't interact
> with the module system.  There is no way for the Lisp reader to tell
> which uses of a symbol are local.  Inevitably, 
>
>   (defun my-member (elt list) ...)
>
> is going to inherit `elt' and `list' as symbols from the package
> of standard Lisp functions, rather than the current package.

I think Michael Albinus already showed that this is not inevitable in CL
(shadow, shadowing-import).  If one wants, you can have your own elt and
car.

>
> The grave problem of :USE in CL packages could be fixed by replacing
> it with a new construct that specifies a list of symbols to be
> inherited from each other package, perhaos with renaming.

I fail to understand the "grave" problem, sorry.  Could you please give
a more concrete example?

BTW, in CL, if you don't want to use-package you can also import just
the list of symbols you want.  Without renaming, but I guess that could
be added, if somone wants that.  (I mention the idea of renaming in
cl-packages.org, BTW, on the branch, but I'm still not sure it's worth
it.)

> Instead of
> (:USE "bar") meaning to inherit all the external symbols of bar, you
> would write (:INHERIT "bar" "entrypoint" ("barhack" . "hack")).
> Instead of the kludgy "get an error if you :USE two packages that
> clash", with :INHERIT you could avoid or fix conflicts one by one.

I think what you mean can be done with import, but I'm not sure.  Like I
said, import doesn't have the renaming part.

>
> We could call this system "corrected CL packages."
> It would not be compatible but it would be better.

It could be compatible, at least I don't see a reason right now why it
couldn't.

>
> This sort of inheritance could be implemented by means of shorthands,
> but it could also be implemented directly in lread.c the same way
> shorthands are implemented.
>
> The idea of CL packages is to use multiple obarrays, but that
> implementation adds unnecessary complexity and unnecessary change.  We
> can treat names with package prefixes, such as `bar:entrypoint', as
> ordinary names and put them all in one obarray.  We could implement
> all of the corrected CL packages system with just one obarray.
>
> With this approach, reading a file in package bar would transform
> every name by concatenating `bar:' at the front.

Let me just remark that this is a read-time solution like CL packages,
so all you said above applies to shorthands as well as packages.

So, that's 1:1.

>
> Normally name concatenation is messy and desirable to avoid, but
> perhaos if done in a controlled way through a package system it would
> not be messy.  At least, not any more messy than is inevitable in a
> package system that operates at read time.

Perhaps, but I find CL packages not messy at all, TBH.  Instead, I quite
strongly feel that shorthand-packages are messy.  And I still fail to
see how shorthands address the problem a name conflicts in the first
place.  One obarray = name conflicts.  But we've been there, I think.

>
> We could hide this concatenation most of the time by making print
> cut off the package prefixes that are redundant in their context.

See, that's what I meant when I wrote "there is no design".  We could,
perhaps, maybe, maybe not, hm.  Why not use what's there and works?

And it's not even difficult to implement or understand, at least to the
degree I did, before I lost impetus.  It's not even 0.01% of redisplay,
for example.

> I wish I could have written all this in a coherent way at the start of
> this discussion.  But this is an issue I dealt with 40 years ago,
> before GNU, and it had become buried in my memory.  It has come back
> to me only gradually.

No problem.

>
> Eli wrote:
>
>   > Moreover, from my POV, the jury is still out on the question of
>   > whether we at all need packages in Emacs.  "Programming in the large"
>   > doesn't sound very relevant to how Emacs Lisp is used.
>
> I share this feeling, except that I take it a bit further.  In the
> 1980s I thought about whether we should have packages in Emacs, and
> concluded that using a naming conventions is simpler, easier and more
> flexible.  So I chose that.
>
> If CL packages were unproblematical, I'd say, "Sure, why not?  We
> aren't desperate to keep Emacs small nowadays."  But they are
> problematical, and that is a reason to choose to do without them.

Please spend some effort to explain the problematic cases. 

> The only drawback of our current use of naming conventions is the need
> to write long names in your code when referring to functions and
> variables defined in other parts of Emacs.  If your code refers to
> many such entry points of a certain part of Emacs, maybe you want
> to abbreviate those.
>
> If that is what you want perhaps shorthands are enough.  You can
> define abbreviations for the entry points that your package uses
> often.
>
> That gives you total control over what abbreviations to use in your
> package, does not impinge on any other code including the code that
> defines the entry points you want to abbreviate, and it causes no
> confusions once you understand what shorthands are.
>
> The only problem we can't avoid is the inconvenience in grep, but that
> will happen with any sort of package system that permits abbreviation
> of names.  It is not a reason to prefer CL packages.
>
> You can even avoid the polyvalency problem this way.  For instance,
> you can define `foo-fun' as a shorthand for `find-outer-otter' the
> function, and `foo-var' as a shorthand for `find-outer-otter' the
> variable.
>
> In fact, either abbreviation _could_ be used for either the function
> or the variable; there is nothing to enforce the distinction between
> those two abbreviations.  But if you wish to maintain that distinction
> in your code, you can.

I think to all of this I've already said something, so I won't bore
anyone with more :-).



  reply	other threads:[~2022-11-11  9:25 UTC|newest]

Thread overview: 125+ 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  8:12       ` Michael Albinus
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: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 [this message]
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     ` A short defense of shorthands.el (but CL packages are still better) (Was: Help sought understanding shorthands wrt modules/packages) João Távora
2022-11-04  3:28       ` 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
  -- strict thread matches above, loose matches on Subject: below --
2022-11-07 21:20 Payas Relekar
2022-11-08  9:40 ` João Távora

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=m2cz9tvo4m.fsf@Mini.fritz.box \
    --to=gerd.moellmann@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=rms@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.
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).