Hello.
How could i make something like having a package 'assembler' (for
example), that uses some functions from other packages (x86, sparc,
whatever), but only uses one of the packages at any time? In one instant
it uses functions from x86, then i want to use sparc package and change
it at runtime.
Does anyone can help ?
thanks in advance.
Rui
In article
<·······································@pu-217-129-13-4.netvisao.pt>,
···············@netvisao.pt wrote:
> Hello.
>
> How could i make something like having a package 'assembler' (for
> example), that uses some functions from other packages (x86, sparc,
> whatever), but only uses one of the packages at any time? In one instant
> it uses functions from x86, then i want to use sparc package and change
> it at runtime.
> Does anyone can help ?
>
> thanks in advance.
>
> Rui
>
http://www.lispworks.com/reference/HyperSpec/Body/m_in_pkg.htm#in-package
On Sat, 28 Sep 2002 ·······@mediaone.net wrote:
> http://www.lispworks.com/reference/HyperSpec/Body/m_in_pkg.htm#in-package
if i have a function 'asm' in package 'assembler' that uses function
'make-instruction' from package x86 or sparc, etc, how can i change that
function (make-instruction)? The objective is to change a set of functions
defined in one package, by the functions in another package...
I don't understand how 'in-package' can help me. Can you explain it a
little further?
Rui
In article
<·······································@pu-217-129-13-4.netvisao.pt>,
···············@netvisao.pt wrote:
> The objective is to change a set of functions
> defined in one package, by the functions in another package...
If you want to change the functions in package spark using a function
named asm from package assembler, you need to export the function(s) you
need from asm, and import them into the package spark, or, export the
function(s) you need from asm, and simply use the whole asm package
inside the package spark. The latter option would only work if there are
no name conflicts between any of symbols exported from package assembler
with the symbols in package spark.
for example:
[Raffael-Cavallaros-Computer:~] raffaelc% openmcl
Welcome to OpenMCL Version (Beta: Darwin) 0.13!
? *package*
#<Package "COMMON-LISP-USER">
? (make-package 'assembler)
#<Package "ASSEMBLER">
? (make-package 'spark)
#<Package "SPARK">
? *package*
#<Package "COMMON-LISP-USER">
? (in-package assembler)
#<Package "ASSEMBLER">
? *package*
#<Package "ASSEMBLER">
? (defun asm () (print "this is a function from the package assembler"))
ASM
? (asm)
"this is a function from the package assembler"
"this is a function from the package assembler"
? (export 'assembler::asm 'assembler)
T
? (in-package spark)
#<Package "SPARK">
? *package*
#<Package "SPARK">
? (import 'assembler::asm 'spark)
T
? (defun sparky() (print "this bit is from package spark")
(asm))
SPARKY
? (sparky)
"this bit is from package spark"
"this is a function from the package assembler"
"this is a function from the package assembler"
N.B. The above has an extra newline interpolated between each
interaction for readability.
If all of this is a bit unclear to you, you should read the intro to
packages and package concepts in the HyperSpec.
<http://www.lispworks.com/reference/HyperSpec/Body/11_aa.htm>
* nospam sentriun wrote:
> if i have a function 'asm' in package 'assembler' that uses function
> 'make-instruction' from package x86 or sparc, etc, how can i change that
> function (make-instruction)? The objective is to change a set of functions
> defined in one package, by the functions in another package...
> I don't understand how 'in-package' can help me. Can you explain it a
> little further?
This is not a good use of the package system. Instead do something
like this:
(defgeneric make-instruction-for (target ...)
;; EQL methods on this do the work
(:method ((target t) ...)
;; signal an error for unknown target
(error "I don't know what target ~S is")))
(defmethod make-instruction-for ((target (eql ':SPARC)) ...)
... emit SPARC instruction ...)
(defvar *processor* ':sparc)
(defun make-instruction (...)
(make-instruction-for *processor* ...))
--tim