all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Daniel Colascione <dancol@dancol.org>
Cc: Tom Tromey <tom@tromey.com>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: Proper namespaces in Elisp
Date: Thu, 7 May 2020 22:46:05 +0100	[thread overview]
Message-ID: <CALDnm536U=djt4sgzdW7nqJWOQV7wYg2E4=Pw_ykg=oSCyhn0Q@mail.gmail.com> (raw)
In-Reply-To: <131ebfb4-4e90-1871-6f3e-de6b0030a78c@dancol.org>

[-- Attachment #1: Type: text/plain, Size: 2371 bytes --]

On Thu, May 7, 2020 at 10:10 PM Daniel Colascione <dancol@dancol.org> wrote:

> On 5/7/20 2:06 PM, Stefan Monnier wrote:
>
> > I thought your previous message was saying you don't like this approach
> > (when you said "I don't like reader magic").  Is it that I misunderstood
> > or that you don't much like the solution but think that from a pragmatic
> > point of view it's still the better option?
>
> I don't like reader magic in general, but I don't think of the CL
> approach as being all that magical: it has uniform rules and a long
> history. CL namespaces *are* reader magic all right, but it's reader
> magic with which a lot of people are familiar
>

Not only that, but CL the reader itself is programmable. So it's really
_not_ "magic", it's all (hyper)spec'ed!

http://www.lispworks.com/documentation/HyperSpec/Body/23_a.htm

However, Daniel, my proposal doesn't have much magic.  Is is really
dumb ;-).  Here's the gist of it (a pure elisp solution using advice,
very lightly tested)

(require 'cl-lib)

(eval-when-compile
  (advice-add 'read :around #'read-aware-of-shorthands)
  (defvar shorthand-shorthands '(("^vlp-" . "very-long-prefix-"))))

(defun shorthand-expand (form)
  (cond ((consp form)
         (setcar form (shorthand-expand (car form)))
         (setcdr form (shorthand-expand (cdr form))))
        ((arrayp form)
         (cl-loop for i from 0 for e across form
                  do (aset form i (shorthand-expand e))))
        ((symbolp form)
         (let ((name (symbol-name form)))
           (cl-loop for (short-pat . long-pat) in shorthand-shorthands
                    do (setq name
                             (replace-regexp-in-string short-pat long-pat
                                                       name))
                    finally (setq form (intern name))))))
  form)


(defun read-aware-of-shorthands (oldread &rest stuff)
  (let ((form (let ((obarray (obarray-make)))
                (apply oldread stuff))))
    (shorthand-expand form)))

(defun vlp-foo () 42) ;; => very-long-prefix-foo
(vlp-foo) ;; => 42

(defun vlp-aref1 (array) (aref array 1))
(vlp-aref1 [2 vlp-shiiz 4]) ;; => very-long-prefix-shiiz

(let ((shorthand-shorthands nil))
  ;; pretend this was some other file
  (eval (car (read-from-string "(vlp-foo)"))) ;; => errors
  (eval (car (read-from-string "(very-long-prefix-foo)"))) ;; => 42
  )

[-- Attachment #2: Type: text/html, Size: 3319 bytes --]

  reply	other threads:[~2020-05-07 21:46 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 10:52 Proper namespaces in Elisp João Távora
2020-05-04 15:11 ` Adam Porter
2020-05-04 15:38   ` Clément Pit-Claudel
2020-05-04 15:49     ` João Távora
2020-05-04 16:39       ` Adam Porter
2020-05-04 16:49         ` João Távora
2020-05-04 18:00       ` Clément Pit-Claudel
2020-05-04 20:19       ` Vladimir Sedach
2020-05-05  2:51     ` Richard Stallman
2020-05-04 15:29 ` Clément Pit-Claudel
2020-05-04 16:04   ` João Távora
2020-05-04 18:29     ` Helmut Eller
2020-05-04 18:39     ` Stefan Monnier
2020-05-04 19:02       ` João Távora
2020-05-04 19:20         ` Stefan Monnier
2020-05-04 19:49           ` João Távora
2020-05-04 21:59         ` Andrea Corallo
2020-05-04 22:34           ` João Távora
2020-05-05 10:33             ` Andrea Corallo
2020-05-05 10:54               ` Andrea Corallo
2020-05-05 12:50               ` João Távora
2020-05-05 13:34                 ` Andrea Corallo
2020-05-05 14:03                   ` João Távora
2020-05-05 14:26                     ` Andrea Corallo
2020-05-05 21:20                       ` João Távora
2020-05-05 23:37                         ` Andrea Corallo
2020-05-06  0:15                           ` João Távora
2020-05-06  7:07                             ` Andrea Corallo
2020-05-06 19:48                               ` João Távora
2020-05-07  6:13                                 ` Andrea Corallo
2020-05-05 13:45               ` Stefan Monnier
2020-05-05 14:07                 ` João Távora
2020-05-05  4:55           ` Helmut Eller
2020-05-04 21:40     ` Vladimir Sedach
2020-05-04 22:09       ` João Távora
2020-05-05  1:09         ` Vladimir Sedach
2020-05-05  9:38           ` João Távora
2020-05-05 16:41             ` Vladimir Sedach
2020-05-05 21:29               ` João Távora
2020-05-06  3:25                 ` Vladimir Sedach
2020-05-06 19:38                   ` João Távora
2020-05-06 22:47                     ` Vladimir Sedach
2020-05-07 10:00                       ` João Távora
2020-05-07 18:30                         ` Vladimir Sedach
2020-05-07 19:32                           ` João Távora
2020-05-04 22:40       ` João Távora
2020-05-05  1:24         ` Vladimir Sedach
2020-05-04 15:43 ` Stefan Monnier
2020-05-05 15:10 ` Tom Tromey
2020-05-05 21:30   ` João Távora
2020-05-07  2:23     ` Tom Tromey
2020-05-07  3:12       ` Stefan Monnier
2020-05-07 13:02         ` Tom Tromey
2020-05-07 13:48           ` João Távora
2020-05-07 18:17             ` Stefan Monnier
2020-05-07 18:48               ` Vladimir Sedach
2020-05-07 20:33                 ` João Távora
2020-05-08  2:56                   ` Vladimir Sedach
2020-05-08 15:56                     ` João Távora
2020-05-08 17:59                       ` Vladimir Sedach
2020-05-08 18:38                         ` João Távora
2020-05-07 19:37         ` Daniel Colascione
2020-05-07 20:28           ` Stefan Monnier
2020-05-07 20:42             ` Daniel Colascione
2020-05-07 21:06               ` Stefan Monnier
2020-05-07 21:10                 ` Daniel Colascione
2020-05-07 21:46                   ` João Távora [this message]
2020-05-07 21:56                     ` Daniel Colascione
2020-05-07 22:12                       ` João Távora
2020-05-08 18:59               ` Vladimir Sedach
2020-05-08 19:34                 ` Daniel Colascione
2020-05-09  0:00                   ` Vladimir Sedach
2020-05-09  0:32                     ` Daniel Colascione
2020-05-09  8:37                       ` Andrea Corallo
2020-05-09 16:11                         ` Daniel Colascione
2020-05-09 17:25                           ` Andrea Corallo
2020-05-09 17:45                             ` Daniel Colascione
2020-05-09 18:23                               ` João Távora
2020-05-09 18:32                                 ` Daniel Colascione
2020-05-09 18:35                                   ` João Távora
2020-05-09 18:39                                     ` Daniel Colascione
2020-05-09 19:11                                       ` João Távora
2020-05-09 18:30                               ` Andrea Corallo
2020-05-09 18:33                                 ` Daniel Colascione
2020-05-09 18:48                                   ` Andrea Corallo
2020-05-09 20:34                                     ` Why :USE sucks in the Common Lisp package system Michał "phoe" Herda
2020-05-09 21:47                                       ` João Távora
2020-05-09 21:55                                         ` Michał "phoe" Herda
2020-05-09 22:01                                           ` Daniel Colascione
2020-05-09 22:07                                             ` Michał "phoe" Herda
2020-05-09 22:12                                           ` João Távora
2020-05-10 10:10                                             ` Michał "phoe" Herda
2020-05-09 23:23                                       ` Andrea Corallo
2020-05-10  6:46                                         ` Andreas Schwab
2020-05-10  8:53                                           ` Helmut Eller
2020-05-10  9:59                                             ` Michał "phoe" Herda
2020-05-10  1:19                       ` Proper namespaces in Elisp Vladimir Sedach
2020-05-08 23:07                 ` Andrea Corallo
2020-05-08 23:23                   ` Stefan Monnier
2020-05-09  8:12                     ` Andrea Corallo
2020-05-09 12:06             ` Tuấn-Anh Nguyễn

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALDnm536U=djt4sgzdW7nqJWOQV7wYg2E4=Pw_ykg=oSCyhn0Q@mail.gmail.com' \
    --to=joaotavora@gmail.com \
    --cc=dancol@dancol.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=tom@tromey.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.