Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

packages,namespaces,...

7 views
Skip to first unread message

nospam....@netvisao.pt

unread,
Sep 28, 2002, 10:42:56 AM9/28/02
to
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

raf...@mediaone.net

unread,
Sep 28, 2002, 11:07:28 AM9/28/02
to

nospam....@netvisao.pt

unread,
Sep 28, 2002, 11:39:56 AM9/28/02
to
On Sat, 28 Sep 2002 raf...@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

raf...@mediaone.net

unread,
Sep 28, 2002, 6:40:07 PM9/28/02
to

> 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>

Tim Bradshaw

unread,
Sep 29, 2002, 2:04:25 PM9/29/02
to
* 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

0 new messages