From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: adding namespaces to emacs-lisp (better elisp?) Date: Fri, 26 Jul 2013 16:59:58 -0400 Message-ID: References: <874nbh2z3y.fsf@ferrier.me.uk> <871u6l2ral.fsf@ferrier.me.uk> <87siz116zo.fsf@ferrier.me.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1374872406 21364 80.91.229.3 (26 Jul 2013 21:00:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Jul 2013 21:00:06 +0000 (UTC) Cc: emacs-devel@gnu.org To: Nic Ferrier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 26 23:00:08 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V2p7O-0003cw-Iu for ged-emacs-devel@m.gmane.org; Fri, 26 Jul 2013 23:00:06 +0200 Original-Received: from localhost ([::1]:50313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2p7O-0001ix-96 for ged-emacs-devel@m.gmane.org; Fri, 26 Jul 2013 17:00:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2p7J-0001dP-R5 for emacs-devel@gnu.org; Fri, 26 Jul 2013 17:00:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2p7I-0005gd-J9 for emacs-devel@gnu.org; Fri, 26 Jul 2013 17:00:01 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:17173) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2p7I-0005gR-F4 for emacs-devel@gnu.org; Fri, 26 Jul 2013 17:00:00 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EABK/CFFFpZPn/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLDiYSFBgNJIgeBsEtkQoDpHqBXoMT X-IPAS-Result: Av4EABK/CFFFpZPn/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLDiYSFBgNJIgeBsEtkQoDpHqBXoMT X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="19934745" Original-Received: from 69-165-147-231.dsl.teksavvy.com (HELO pastel.home) ([69.165.147.231]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 26 Jul 2013 16:59:53 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id E55B462D9D; Fri, 26 Jul 2013 16:59:58 -0400 (EDT) In-Reply-To: <87siz116zo.fsf@ferrier.me.uk> (Nic Ferrier's message of "Fri, 26 Jul 2013 20:00:43 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:162173 Archived-At: >> Here's a scenario: >> - namespaced packages A and B both locally define a function `toto'. >> - non-namespaced package C comes along with a symbol `toto' somewhere in >> its code, suddenly causing A and B's `toto' to be global rather >> than local. > I don't think this is a serious problem personally. But I'm also not > wedded to global-obarray-first. I think it's a very serious problem because it means packages A and B are at the mercy of some random wholly unrelated package C. >> Note that instead of "non-namespaced package C", we could have some >> package which uses symbols as "uniquified strings" and which uses the >> global obarray for it and might occasionally intern `toto' in the course >> of its normal execution. > Again, it only matters if it's a non-namespaced package that does it. No, a namespaced package can just as easily call `intern'. But even if you can hope the a namespaced package wouldn't do it, the non-namespaced packages are very numerous and do all kinds of nasty stuff and we have very little control over them (e.g. they're not bundled with Emacs). >> IOW I think we should instead first look in the local obarray (over >> which the coder does have control) and if that fails then look in the >> global obarray. > I am not wedded to the proposal of using the global obarray first. The > rules for interning are slightly more complicated in that case: > - given a string X > - lookup X in the local obarray > - if it exists return the symbol > - else > - lookup X in the global obarray > - if it exists return the symbol > - else > - add the symbol to the local obarray Exactly. In Mathematica, they have a list of obarrays to check in sequence and a "current" obarray to which things are added if the lookup fails. Sounds clean and simple to me. > The only problem I see here is the possibility of problems with > concurrency. The whole operation above would have to be atomic and it > involves lookups in two separate data structures. That sounds like a very remote problem to me. And if/when concurrency is added it doesn't seem like it should be difficult to make it work reliably. > My feeling is that an import should be like the creation of an alias. Function alias? Variable alias? I don't much like the sounds of it. I'd much rather make sure they are simply one and the same symbol (I guess "symbol alias"). > It's not that I don't like it per-se. I just want this to be easy to > implement in the first instance. If the implementation gets more > difficult later I have no problem with that. But initial low cost is a > good thing. I'm not sure why the implementation should be difficult. `intern' would "simply" need to parse the string into a list of elements (separated by "::" or whatever), then lookup the first element in the obarray, which should contain another obarray, then lookup the second element in that obarray, etc... until the last element which is handled "in the old way". Then (import 'nic as 'foo) would amount to (setq foo nic) Stefan