[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emulating namespaces
From: |
Pascal J. Bourguignon |
Subject: |
Re: Emulating namespaces |
Date: |
Wed, 08 Dec 2010 15:11:29 -0000 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/23.1 (gnu/linux) |
LanX <lanx.perl@googlemail.com> 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))
#<PACKAGE "NAMESPACE">
COMMON-LISP-USER> (in-package :namespace)
#<PACKAGE "NAMESPACE">
NAMESPACE> (defvar *var* 888)
*VAR*
NAMESPACE> (defun test () (print *var*))
TEST
NAMESPACE> (defpackage :outerspace (:use :cl))
#<PACKAGE "OUTERSPACE">
NAMESPACE> (in-package :outerspace)
#<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)
(#<PACKAGE "OUTERSPACE"> #<PACKAGE "NAMESPACE"> #<PACKAGE "COMMON-LISP-USER">
#<PACKAGE "COMMON-LISP"> #<PACKAGE "EMACS-COMMON-LISP-MOP"> #<PACKAGE
"EMACS-COMMON-LISP"> #<PACKAGE "EMACS-LISP"> #<PACKAGE "KEYWORD">)
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/
- Re: About Emacs Modernisation Project, (continued)
- Message not available
- Re: About Emacs Modernisation Project, Stefan Monnier, 2010/12/08
- Re: About Emacs Modernisation Project, LanX, 2010/12/08
- Re: About Emacs Modernisation Project, Maarten Bergvelt, 2010/12/08
- Re: About Emacs Modernisation Project, Pascal J. Bourguignon, 2010/12/08
- Message not available
- Re: Emulating namespaces, Pascal J. Bourguignon, 2010/12/08
- Re: Emulating namespaces, LanX, 2010/12/08
- Re: Emulating namespaces,
Pascal J. Bourguignon <=
- Re: About Emacs Modernisation Project, Evans Winner, 2010/12/09
- Re: About Emacs Modernisation Project, Pascal J. Bourguignon, 2010/12/08
- Re: About Emacs Modernisation Project, Evans Winner, 2010/12/09
Re: About Emacs Modernisation Project, Joseph Brenner, 2010/12/08
Re: About Emacs Modernisation Project, Jean-Baptiste Bourgoin, 2010/12/09