From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: Proper namespaces in Elisp Date: Thu, 7 May 2020 22:46:05 +0100 Message-ID: References: <87ftcee7td.fsf@tromey.com> <87pnbgzdmx.fsf@tromey.com> <1225997b-648a-068d-7f6b-e1575477a0d0@dancol.org> <131ebfb4-4e90-1871-6f3e-de6b0030a78c@dancol.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000007e06cf05a515cf62" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="124507"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Tom Tromey , Stefan Monnier , emacs-devel To: Daniel Colascione Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu May 07 23:47:13 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jWoML-000WDS-7E for ged-emacs-devel@m.gmane-mx.org; Thu, 07 May 2020 23:47:13 +0200 Original-Received: from localhost ([::1]:39632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWoMK-0003g4-56 for ged-emacs-devel@m.gmane-mx.org; Thu, 07 May 2020 17:47:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWoLT-0003EF-Sg for emacs-devel@gnu.org; Thu, 07 May 2020 17:46:19 -0400 Original-Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]:34587) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jWoLS-0005mX-Nb for emacs-devel@gnu.org; Thu, 07 May 2020 17:46:19 -0400 Original-Received: by mail-il1-x134.google.com with SMTP id w6so2396719ilg.1 for ; Thu, 07 May 2020 14:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=p2/sZff8MhXBW9P7wF3Qv/9bp+Q8cntiWpPMo25hq4U=; b=tVzZMzx1oGwsb+NnqVnE9znxEc/8Vxbc6YtygDORnxvPTzZMZUWb8+HlxNv8pmG4TK T3OjWCIEJPf6gM+EYdqkPAX4m5+rJYqADD4hLr8lls/cl6d7t9MN0iEidnFA2bumeXUn yv2T3Sh4yk8MwHT/6cBBOM89PSWnEfvq+pSZJqPgC59VIKQ3KNaTIKBn/qK85z7eH4fI 2t9TcYRbqFHEvkjSR770Yt1rNsOiGbLSTxUalEyr+cQ6t6Z3pDrMbzE/iCCdQKolnoDO uxX+HeAoBb8PWpwrzMswD4Xw8dcYMCqXwKEByQo/pGNIhrVKYZm9zFygZCRqmdzbOeET CHQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=p2/sZff8MhXBW9P7wF3Qv/9bp+Q8cntiWpPMo25hq4U=; b=CmumUB1QtLwqsV2cris9G4nlfWDXOpv+VUt4vkYVpayX/Ovrb++7zrpWjkoMDSB/NP VsE1SYQQ5AWBmKnGUpY8JnMpprcimDVVWZh5kiM/4vCbKMjOFUtPJsp2aVrRQb75asE+ S1574LeHCY+SJOaFgi+wVEJq1SUFAunMVBoCIU8Ngcd+n8RZ/wd3inKn302DRujyRMxa usBE0ty9xTbHEjpC24O6/s09Ld/yuQG9DdiUz6dYRzOdpDodMJs3cxk+bxZTA1faA6AJ /uuWFy9F6lUCmRuZluMdQQgY5Fs8fPZtE3SjH5I8l/kr2nqGjH77jjil5sATPQZMrIzh 1eVQ== X-Gm-Message-State: AGi0Puby/eQbHp+Y0M+6Gi8YSr08JQxhbwtVLg3c5anoNEtSeNedqre7 ZAF7a9J0CWGdpGc5lPjCDSLeFELSxfMFOsZPl84= X-Google-Smtp-Source: APiQypK+tui0MG0jwNWWAyFWzwOxmox9HOQdo1o6kAtH438F3/R6Ng6NjND+lPxR043a+ksAkdu0lnBUywOL8proASM= X-Received: by 2002:a92:4a11:: with SMTP id m17mr16329212ilf.125.1588887977590; Thu, 07 May 2020 14:46:17 -0700 (PDT) In-Reply-To: <131ebfb4-4e90-1871-6f3e-de6b0030a78c@dancol.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::134; envelope-from=joaotavora@gmail.com; helo=mail-il1-x134.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FROM_EXCESS_BASE64=0.979, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:249225 Archived-At: --0000000000007e06cf05a515cf62 Content-Type: text/plain; charset="UTF-8" On Thu, May 7, 2020 at 10:10 PM Daniel Colascione 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 ) --0000000000007e06cf05a515cf62 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, May 7, 2020 at 10:10 PM Daniel Colascione <dancol@dancol.org> wrote:
On 5/7/20 2:06 PM, Stefan Monnier w= rote:

> I thought your previous message was saying you don't like this app= roach
> (when you said "I don't like reader magic").=C2=A0 Is it= that I misunderstood
> or that you don't much like the solution but think that from a pra= gmatic
> 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 <= br> 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!


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

(require 'cl-lib)

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

(defun shorthand-expand (form)=C2=A0 (cond ((consp form)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setcar fo= rm (shorthand-expand (car form)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(set= cdr form (shorthand-expand (cdr form))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((a= rrayp form)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cl-loop for i from 0 for = e across form
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 do (aset form i (shorthand-expand e))))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 ((symbolp form)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((name (symbo= l-name form)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cl-loop for (sh= ort-pat . long-pat) in shorthand-shorthands
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 do (setq name
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(replace-regexp-in-string short-pat long-pat
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name))
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 finally (setq form (intern name)= )))))
=C2=A0 form)


(defun read-aware-of-shorthands (oldread &= amp;rest stuff)
=C2=A0 (let ((form (let ((obarray (obarray-make)))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (apply oldread stuf= f))))
=C2=A0 =C2=A0 (shorthand-expand form)))

(defun vlp-foo () 4= 2) ;; =3D> very-long-prefix-foo
(vlp-foo) ;; =3D> 42

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

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



--0000000000007e06cf05a515cf62--