Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's hard to say much without knowing more about your intent and requirements, but in many situations it would be better to have one or more hash tables (or similar) which contain your dynamically generated objects, and then export symbol(s) for your hash table(s).</p> <p>Here's a hand-wavy example of how this can work. If you can edit and add some more information about your requirements and constraints I'll see if I can be more help.</p> <pre><code>(in-package :cl) (defpackage :package-a (:use :cl) (:export *objects* put get) (:shadow get)) (in-package :package-a) (defvar *objects* (make-hash-table) "Container for dynamically generated objects we want to expose to the package's user.") (defun put (name obj) (setf (gethash name *objects*) obj)) (defun get (name &amp;optional default) (gethash name *objects* default)) ;; Your code can put arbitrary objects into the hash table (put :foo (lambda () :a-thunk)) (put :bar (lambda () :another)) ;; And your users can retrieve them (in-package :cl-user) (use-package :package-a) (funcall (get :foo)) ;; =&gt; :a-thunk </code></pre> <p>I used keywords for the names rather than symbols because keywords aren't local to packages (or, more specifically, they're all local to the <code>keyword</code> package. If you were to instead use <code>'foo</code> and <code>'bar</code> you'd be back to needing to export those symbols, or your user would need to use the package designator when refer to them (e.g. <code>(get 'package-a::foo)</code>).</p> <p>You can also use strings as keys, though in that case you would want to create the table with <code>(make-hash-table :test 'equal)</code>. The default hash table test is <code>#'eql</code>, which doesn't compare strings appropriately. Comparing keywords with <code>#'eql</code> is faster than comparing strings with <code>#'equal</code> (because keywords are a simple pointer comparison, as opposed to the character-by-character comparison necessary for strings) but the difference is likely insignificant unless you have specific reason to think otherwise.</p> <p>This approach provides a better interface for your users, because now your have defined entry points, the opportunity for docstrings, defaults, and easier exploration at the REPL.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload