Skip to content

pve1/capitalized-export

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Capitalized Export

This library provides a readtable that lets the user export accessible symbols by capitalizing them when loading or compiling files. Jump to definition, describe symbol etc. will still work normally in SLIME. It works by replacing the final newline in a file with an export form.

So typing

(defclass Person ()
  ((%name :initarg :name :accessor Name :initform nil)
   (%age :initarg :age :accessor Age :initform nil)))

will arrange for PERSON, NAME and AGE to be exported when the file (either source or fasl) is loaded.

A fresh readtable is required for each file, so one might want to create a suitable convenience macro for setting the current readtable. The default package from which symbols will be exported is the value of *package* at the time the readtable is created.

Example

;;;; File "capitalized-export-test.lisp"
;;;;
;;;; Testing exporting by capitalizing symbols.

(defpackage :capitalized-export-test
  (:use :cl))

(in-package :capitalized-export-test)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (setf *readtable* (capitalized-export:make-capitalized-export-readtable)))

(defclass Person ()
  ((%name :initarg :name :accessor Name :initform nil)
   (%age :initarg :age :accessor Age :initform nil)))

;; |...| is not exported, should instead be exported the normal way.
(defun |Make-person| ()
  (make-instance 'person))

'A ; Export
'b ; Don't export

;; Error:
;; (defun cl-user::Foo () 1)

(defparameter *Circular* '#1=(1 2 3 . #1#))

;; This form will be returned by CL:READ as if it had been typed at
;; the bottom of the file:
;;
;; (EXPORT '(PERSON NAME AGE A *CIRCULAR*))

Note: SBCL likes to signal a warning when a defpackage form is evaluated and the symbols exported by the package don’t match what’s specified in the defpackage form (“WARNING: … also exports the following symbols: …”).

Therefore SBCL users may want to replace the top part of the above code with something like:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (ignore-errors (make-package :capitalized-export-test :use '(:cl)))
  (in-package :capitalized-export-test)
  (setf *readtable* (capitalized-export:make-capitalized-export-readtable)))

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published