Edit
Attach
Printable
topic end
<!-- * Set TOPICTITLE = #define private public - A package riddle, part IV (28 Aug 2009) --> <style type="text/css"> pre {background-color:#ffeecc;} </style> %STARTINCLUDE% <a name="28"></a> ---+++ [[DefinePrivatePublic20090828PackageRiddle4][A package riddle, part IV]] (28 Aug 2009) <summary> I'll bore you just one more time with this: When executing <tt>(test)</tt> as defined in the following code, Lisp claimed that <i>the function #:TEST_DIALOG is undefined</i>. </summary> <pre> (defun test() (test_dialog)) (in-package :clausbrod.de) (use-package :oli) (sd-defdialog 'test_dialog :ok-action '(display "test_dialog")) </pre> In [[DefinePrivatePublic20090822PackageRiddlePart3][part 3]] of this mini-series, we figured out that the <tt>#:</tt> prefix indicates an _uninterned symbol_ - and now we can solve the puzzle! Earlier, I had indicated that =sd-defdialog= automatically exports dialog names into the default package. To perform this trick, somewhere in the bowels of the =sd-defdialog= macro, the following code is generated and executed: <pre> (shadowing-import ',name :cl-user) ;; import dialog name into cl-user package (export ',name) ;; export dialog name in current package (import ',name :oli) ;; import dialog name into oli package (export ',name :oli) ;; export dialog name from the oli package </pre> As a consequence, the dialog's name is now visible in three packages: * The default package (=cl-user=) * Our Lisp API package (=oli=) * The package in which the dialog was defined (here: =clausbrod.de=) This is quite convenient for <nop>CoCreate Modeling users - typically mechanical engineers, not Lisp programmers. They don't want to deal with the intricacies of Lisp's package handling, but instead simply assume that the command (dialog) will be at their disposal whenever they need it. Let's look up what the Common Lisp standard has to say on [[http://l1sp.org/cl/shadowing-import][shadowing-import]]: <blockquote><i>shadowing-import inserts each of symbols into package as an internal symbol, regardless of whether another symbol of the same name is shadowed by this action. If a different symbol of the same name is already present in package, that symbol is first <b>uninterned</b> from package.</i></blockquote> That's our answer! With this newly-acquired knowledge, let's go through our code example one more and final time: <pre> (defun test() (test_dialog)) </pre> Upon loading this code, the Lisp reader will intern a symbol called =test_dialog= into the current (default) package. As =test_dialog= has not been defined yet, the symbol =test_dialog= does not have a value; it's just a placeholder for things to come. <pre> (in-package :clausbrod.de) (use-package :oli) </pre> We're no longer in the default package, and can freely use =oli:sd-defdialog= without a package prefix. <pre> (sd-defdialog 'test_dialog :ok-action '(display "test_dialog")) </pre> =sd-defdialog= performs <tt>(shadowing-import 'test_dialog :cl-user)</tt>, thereby shadowing (hiding) _and_ uninterning the previously interned =test_dialog= symbol. Until we re-evaluate the definition for =(test)=, it will still refer to the old definition of the symbol =test_dialog=, which - by now - is a) still without a value and b) uninterned, i.e. homeless. Lessons learned: * Pay attention to the exact wording of Lisp error messages. * The Common Lisp standard is your friend. * Those Lisp package problems can be pesky critters. The good news: If you follow a few rules of thumb, you'll probably never run into complex package problems like this. One such simple rule is to define your functions first before referring to them. So in our code example, defining the dialog first before loading/defining the =(test)= function would have saved us all that hassle. Phew. --- %STOPINCLUDE% %COMMENT{type="below" nonotify="on"}% ---
to top
End of topic
Skip to action links
|
Back to top
Edit
|
Attach image or document
|
Printable version
|
Raw text
|
Refresh
|
More topic actions
Revisions: | r1.1
|
Total page history
|
Backlinks
You are here:
Blog
>
DefinePrivatePublic20090828PackageRiddle4
r1.1 - 28 Aug 2009 - 14:05 -
ClausBrod
to top
Blog
This site
2017
:
12
-
11
-
10
2016
:
10
-
7
-
3
2015
:
11
-
10
-
9
-
4
-
1
2014
:
5
2013
:
9
-
8
-
7
-
6
-
5
2012
:
2
-
10
2011
:
1
-
8
-
9
-
10
-
12
2010
:
11
-
10
-
9
-
4
2009
:
11
-
9
-
8
-
7
-
6
-
5
-
4
-
3
2008
:
5
-
4
-
3
-
1
2007:
12
-
8
-
7
-
6
-
5
-
4
-
3
-
1
2006:
4
-
3
-
2
-
1
2005:
12
-
6
-
5
-
4
2004:
12
-
11
-
10
C++
CoCreate Modeling
COM & .NET
Java
Mac
Lisp
OpenSource
Scripting
Windows
Stuff
Changes
Index
Search
Maintenance
Impressum
Datenschutzerklärung
Home
Webs
Atari
Blog
Claus
CoCreateModeling
Klassentreffen
Main
Sandbox
Sommelier
TWiki
Xplm
Jump:
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback