From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Emulating namespaces Date: Thu, 03 Jun 2010 19:41:01 +0200 Organization: Informatimago Message-ID: <87bpbsrp3m.fsf@kuiper.lan.informatimago.com> References: <143c6d28-4423-4e43-9fc5-c0fb3340043b@c11g2000vbe.googlegroups.com> <87ljazofkn.fsf@rapttech.com.au> <04eff456-349f-4840-b0f7-d1784f6b7058@d12g2000vbr.googlegroups.com> <87r5krh3e0.fsf@unm.edu> <66c5242b-d254-4646-9537-6c669c6616bb@d12g2000vbr.googlegroups.com> <87typksc0h.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291837455 9243 80.91.229.12 (8 Dec 2010 19:44:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2010 19:44:15 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 08 20:44:09 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQPvs-000340-Cl for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 20:44:08 +0100 Original-Received: from localhost ([127.0.0.1]:51484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQPvr-0000cf-IZ for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 14:44:07 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 77 Original-X-Trace: individual.net BndIwwVkLwkfYvrseSGT+QR70fxBJ1llRZZGtEO1ZKewce+k76 Cancel-Lock: sha1:NzkxOWNkY2YyOTYxZTAwZjc1N2VkNmI5YjY0ZWYyYzJkY2I2NDUwYg== sha1:vYlfkHnDeYsFKaO4KJBXn3XiOmE= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.1 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:178595 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:75913 Archived-At: LanX writes: > do I get it right switching the package means that will bind variables > in the following code to different symbol tables? > >> Also, we could just use emacs-cl... > > ehm do you wanna tell me that (require 'cl) already provides support > for namespaces? No, it doesn't. emacs-cl is an implementation of Common Lisp written in emacs lisp, like ejacs is an implementation of JavaScript written in emacs lisp. > So why bother? > > Could you plz show me some code that reflects the behavior of the perl > snippet I posted? > > > --------------- > { > package Namespace; > our $var=666; > > sub tst {print $var } > > } > > package Outerspace; > > $var=42; > Namespace::tst(); # prints 666 > --------------- > > I'd like to run some tests... http://www.lisp.se/emacs-cl/ M-x load-library RET load-cl RET M-x emacs-cl RET and then in the *Emacs Common Lisp* buffer: COMMON-LISP-USER> (defpackage :namespace (:use :cl)) # COMMON-LISP-USER> (in-package :namespace) # NAMESPACE> (defvar *var* 888) *VAR* NAMESPACE> (defun test () (print *var*)) TEST NAMESPACE> (defpackage :outerspace (:use :cl)) # NAMESPACE> (in-package :outerspace) # OUTERSPACE> (defvar *var* 42) *VAR* OUTERSPACE> (namespace::test) 888 888 OUTERSPACE> (remove-if-not (lambda (b) (string-match ".*\.lisp" (buffer-name b))) (buffer-list)) OUTERSPACE> (list-all-packages) (# # # # # # # #) OUTERSPACE> (remove-if-not (lambda (n) (let ((len (length n))) (when (< 3 len) (string= ".el" (subseq n (- len 3)))))) (mapcar (function emacs-lisp:|buffer-name|) (emacs-lisp:|buffer-list|))) ("cl-macs.el") OUTERSPACE> -- __Pascal Bourguignon__ http://www.informatimago.com/