Permalink
Browse files

Working on compiled code too.

  • Loading branch information...
1 parent 63f2281 commit 09e40434fbc629d3527606e9e9a24a7c66288038 @skeeto committed May 26, 2011
Showing with 22 additions and 24 deletions.
  1. +10 −6 example.el
  2. +12 −18 fakespace.el
View
@@ -1,19 +1,20 @@
(require 'fakespace)
;; Start be declaring a package. `defpackage' currently supports :use
-;; and :export. Anything listed in :use will be `require'd. You can
-;; make your own calls to require, but they should occur before
-;; `defpackage'. Otherwise the functions and variables defined in the
+;; and :export. Any libraries listed in :use will be `require'd. You
+;; can make your own calls to require, but they should generally occur
+;; *before* your `defpackage'. Otherwise the symbols defined in the
;; require will become part of your package and won't get exported.
(defpackage example
(:use cl ido)
- (:export example-main example-var))
+ (:export example-main example-var eq-hello hello))
;; Caveat: any functions or variables you declare *will* be defined in
;; the main namespace (we're faking namespaces here), but the
-;; non-exported ones will be removed later. They can be redefined
-;; elsewhere without interfering with the definitions here.
+;; non-exported symbols will be removed afterward. The same functions
+;; and variables can be redefined elsewhere without interfering with
+;; the definitions here.
(defvar my-var 100
"A hidden variable.")
@@ -32,6 +33,9 @@ variables and functions from here."
(list (list (my-func) my-var) example-var
(ido-completing-read "New value: " (list "foo" "bar"))))
+(defun eq-hello (sym)
+ (eq sym 'hello))
+
;; Unlike Common Lisp, rather than declaring your namespace with
;; `in-package' you must end your package definition with
;; `end-package'. This will hide all of your internal functions away
View
@@ -3,6 +3,11 @@
;;; Code:
+(require 'cl)
+
+;; Dummy call to force autoload.
+(remove-if-not 'identity ())
+
(defun atom-list (&optional ob)
"Return given obarray OB as a list. Defaults to obarray."
(let ((lst ()))
@@ -21,31 +26,20 @@ specially formed lists. Returns items that are in B and not A."
(setq b (cdr b)))
diff))
-(defun package-hide-p (s)
- "Return t if this symbol should be uninterned."
- (or (functionp s)
- (documentation-property s 'variable-documentation)))
-
(defvar old-obarray ()
"List of all the items from obarray at some previous time.")
(defmacro defpackage (name &rest args)
- (let ((code (list 'progn)))
- (dolist (arg args)
- (let ((type (car arg)))
- (cond ((eq type :exports) t) ; interning the symbols is enough
- ((eq type :use)
- (setq code (append code (mapcar
- (lambda (s)
- `(require (quote ,s)))
- (cdr arg))))))))
- (setq old-obarray (atom-list))
- (append code (list `(provide (quote ,name))))))
+ (dolist (arg args)
+ (let ((type (car arg)))
+ (cond ((eq type :exports) t) ; interning the symbols is enough
+ ((eq type :use) (mapcar (lambda (s) (require s)) (cdr arg))))))
+ (setq old-obarray (atom-list))
+ `(provide (quote ,name)))
(defmacro end-package ()
(cons 'progn
(mapcar (lambda (s) `(unintern (quote ,s)))
- (remove-if-not 'package-hide-p
- (atom-difference old-obarray (atom-list))))))
+ (atom-difference old-obarray (atom-list)))))
(provide 'fakespace)

0 comments on commit 09e4043

Please sign in to comment.