Peder O. Klingenberg <peder@news.klingenberg.no> wrote:
+---------------
| "Leslie P. Polzer" <leslie.polzer@gmx.net> writes:
| > When a snippet of code depends on a package (optionally)
| > loaded at runtime, how can I cope with it?
|
| Do the interning of your symbol at runtime instead of at read time.
|
| (defun foo ()
| (when (find-package :optional)
| (funcall (intern "BAR" :optional))))
+---------------
Or if you might be using case-sensitive reading [e.g., setting
readtable-case to :INVERT, as some people do to deal with CamelCase],
you could even do this:
(defun foo ()
(when (find-package :optional)
(funcall (intern (symbol-name :bar) :optional))))
I use a version of this sometimes in my LHP (Lisp-Handled Pages)
web application infrastructure, when the LHP page being loaded
is big enough (or sufficiently in flux during development) to
potentially need an ASDF update each time it's accessed:
;;; Boilerplate for using ASDF from LHP page.
(let ((system :foo-web)
(package :org.rpw3.foo)
(function :foo-main))
(flet ((this-page (request)
;; Ensure up-to-date each time
(asdf:operate 'asdf:load-op system)
;; Call the request handler
(funcall (intern (symbol-name function) package) request)))
;; LHP pages must set the page-handling function while loading.
(lhp-set-page-function #'this-page)))
Yes, it's somewhat inefficient, but it's *awfully* convenient
while developing a new web app. Make an edit, hit "Reload" on
the web browser, and all the right things get recompiled/reloaded
and the page is refreshed with the output of the new code.
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607