[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

:use can't be found in a new created package

james

7/21/2015 2:03:00 AM

Hi experters,
I meet a problem when I try to created a new package in the packae TEST.
I don't know why i could use :use in packate cl-user but can't in TEST.
Aslo, Is there any method to know which package a symbol belong?

TEST> (make-package :ja.r (:use :cl))

The function :USE is undefined.
[Condition of type UNDEFINED-FUNCTION]

Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [REMOVE-FD-HANDLER] Remove #<SB-IMPL::HANDLER INPUT on descriptor 21: #<CLOSURE (LABELS SWANK/SBCL::RUN :IN SWANK/BACKEND:ADD-FD-HANDLER) {1276AC2D}>>
3: [ABORT] Exit debugger, returning to top level.

Backtrace:
0: (SYMBOL-FUNCTION :USE)
1: (SB-INT:SIMPLE-EVAL-IN-LEXENV (:USE :CL) #<NULL-LEXENV>)
2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (MAKE-PACKAGE :JA.R (:USE :CL)) #<NULL-LEXENV>)
3: (EVAL (MAKE-PACKAGE :JA.R (:USE :CL)))
--more--

Thanks
9 Answers

Matthew Carter

7/21/2015 2:56:00 AM

0

james <dinglei2008@gmail.com> writes:

> Hi experters,
> I meet a problem when I try to created a new package in the packae TEST.
> I don't know why i could use :use in packate cl-user but can't in TEST.
> Aslo, Is there any method to know which package a symbol belong?
>
> TEST> (make-package :ja.r (:use :cl))
>
> The function :USE is undefined.
> [Condition of type UNDEFINED-FUNCTION]
>
> Restarts:
> 0: [RETRY] Retry SLIME REPL evaluation request.
> 1: [*ABORT] Return to SLIME's top level.
> 2: [REMOVE-FD-HANDLER] Remove #<SB-IMPL::HANDLER INPUT on > descriptor 21: #<CLOSURE (LABELS SWANK/SBCL::RUN :IN > SWANK/BACKEND:ADD-FD-HANDLER) {1276AC2D}>>
> 3: [ABORT] Exit debugger, returning to top level.
>
> Backtrace:
> 0: (SYMBOL-FUNCTION :USE)
> 1: (SB-INT:SIMPLE-EVAL-IN-LEXENV (:USE :CL) #<NULL-LEXENV>)
> 2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (MAKE-PACKAGE :JA.R (:USE :CL)) > #<NULL-LEXENV>)
> 3: (EVAL (MAKE-PACKAGE :JA.R (:USE :CL)))
> --more--
>
> Thanks

(make-package :ja.r :use (list :cl :cl-user))

The :use is referring to the &key slot you want to use (which can then
take a list of what you want to use).

There may be a better way, but I think you may want to just use:

(inspect #'something)

To see detailed info about what something is and/or belongs to.

For example:

(inspect #'print)

--
Matthew Carter (m@ahungry.com)
http://a...

Pascal J. Bourguignon

7/21/2015 3:05:00 AM

0

james <dinglei2008@gmail.com> writes:

> Hi experters,
> I meet a problem when I try to created a new package in the packae TEST.
> I don't know why i could use :use in packate cl-user but can't in TEST.
> Aslo, Is there any method to know which package a symbol belong?
>
> TEST> (make-package :ja.r (:use :cl))

At the REPL, it's ok to create packages with MAKE-PACKAGE,
but in general you would use the macro DEFPACKAGE to create package,
since it would allow you to specify in addition to the use list,
exported symbols, imported symbols, shadowed symbols, etc.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

james

7/21/2015 3:42:00 AM

0

On Tuesday, July 21, 2015 at 11:05:24 AM UTC+8, informatimago wrote:
> james <dinglei2008@gmail.com> writes:
>
> > Hi experters,
> > I meet a problem when I try to created a new package in the packae TEST.
> > I don't know why i could use :use in packate cl-user but can't in TEST.
> > Aslo, Is there any method to know which package a symbol belong?
> >
> > TEST> (make-package :ja.r (:use :cl))
>
> At the REPL, it's ok to create packages with MAKE-PACKAGE,
> but in general you would use the macro DEFPACKAGE to create package,
> since it would allow you to specify in addition to the use list,
> exported symbols, imported symbols, shadowed symbols, etc.
>
> --
> __Pascal Bourguignon__ http://www.informat...
> "The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment." -- Carl Bass CEO Autodesk

Thanks for share this.
In fact, I am trying to using (define-package :jar.r (:use :cl)) which should works here. But i am wrong by using make-package. Any way, I learned a new function here. Thanks again :)

Pascal J. Bourguignon

7/21/2015 6:10:00 AM

0

james <dinglei2008@gmail.com> writes:

> On Tuesday, July 21, 2015 at 11:05:24 AM UTC+8, informatimago wrote:
>> james <dinglei2008@gmail.com> writes:
>>
>> > Hi experters,
>> > I meet a problem when I try to created a new package in the packae TEST.
>> > I don't know why i could use :use in packate cl-user but can't in TEST.
>> > Aslo, Is there any method to know which package a symbol belong?
>> >
>> > TEST> (make-package :ja.r (:use :cl))
>>
>> At the REPL, it's ok to create packages with MAKE-PACKAGE,
>> but in general you would use the macro DEFPACKAGE to create package,
>> since it would allow you to specify in addition to the use list,
>> exported symbols, imported symbols, shadowed symbols, etc.
>
> Thanks for share this.
> In fact, I am trying to using (define-package :jar.r (:use :cl)) which
> should works here. But i am wrong by using make-package. Any way, I
> learned a new function here. Thanks again :)

Be careful.

defpackage is macro.
make-package is a function.

This is why, given that the arguments to macros are passed to the macro
without being evaluated, we can write:

(defpackage "P"
(:use "CL"))

For lisp, "P" and (:use "CL") are just a string and a list to be given
as parameter to the macro DEFPACKAGE, and it's up to the macro to see
what it will use to build an expression to be compiled and evaluated at
run-time.


But we cannot write:

(make-package "P" (:use "CL"))

because MAKE-PACKAGE being a function, lisp will evaluate at run-time
the arguments "P" and (:use "CL") to obtain values to be passed as
parameter to the function MAKE-PACKAGE.

"P" is a literal string, so it will evaluate to itself, no problem. But
in (:use "CL"), :USE is not a macro or a function, therefore it's an
invalid function call. The compiler will warn, and you will get a
run-time error for undefined function :USE. Furthermore, now the
parameters of the function MAKE-PACKAGE are valid, since MAKE-PACKAGE
takes there &key parameters, and it expected a value for the given
(invalid) key.

This is why you got your original error: you didn't consider that
MAKE-PACKAGE was a function and that you needed to pass it the correct
expressions to be evaluated as arguments.


http://www.lispworks.com/documentation/lw50/CLHS/Body/m_...
http://www.lispworks.com/documentation/lw50/CLHS/Body/f_...
http://www.lispworks.com/documentation/lw50/CLHS/Body/...

DEFPACKAGE and MAKE-PACKAGE are operators.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

james

7/21/2015 6:12:00 AM

0

On Tuesday, July 21, 2015 at 11:05:24 AM UTC+8, informatimago wrote:
> james <dinglei2008@gmail.com> writes:
>
> > Hi experters,
> > I meet a problem when I try to created a new package in the packae TEST.
> > I don't know why i could use :use in packate cl-user but can't in TEST.
> > Aslo, Is there any method to know which package a symbol belong?
> >
> > TEST> (make-package :ja.r (:use :cl))
>
> At the REPL, it's ok to create packages with MAKE-PACKAGE,
> but in general you would use the macro DEFPACKAGE to create package,
> since it would allow you to specify in addition to the use list,
> exported symbols, imported symbols, shadowed symbols, etc.
>
> --
> __Pascal Bourguignon__ http://www.informat...
> "The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment." -- Carl Bass CEO Autodesk

Agree. Just curious why cl still provide make-package since defpackage could finish all the jobs.

james

7/21/2015 6:15:00 AM

0

On Tuesday, July 21, 2015 at 2:10:23 PM UTC+8, informatimago wrote:
> james <dinglei2008@gmail.com> writes:
>
> > On Tuesday, July 21, 2015 at 11:05:24 AM UTC+8, informatimago wrote:
> >> james <dinglei2008@gmail.com> writes:
> >>
> >> > Hi experters,
> >> > I meet a problem when I try to created a new package in the packae TEST.
> >> > I don't know why i could use :use in packate cl-user but can't in TEST.
> >> > Aslo, Is there any method to know which package a symbol belong?
> >> >
> >> > TEST> (make-package :ja.r (:use :cl))
> >>
> >> At the REPL, it's ok to create packages with MAKE-PACKAGE,
> >> but in general you would use the macro DEFPACKAGE to create package,
> >> since it would allow you to specify in addition to the use list,
> >> exported symbols, imported symbols, shadowed symbols, etc.
> >
> > Thanks for share this.
> > In fact, I am trying to using (define-package :jar.r (:use :cl)) which
> > should works here. But i am wrong by using make-package. Any way, I
> > learned a new function here. Thanks again :)
>
> Be careful.
>
> defpackage is macro.
> make-package is a function.
>
> This is why, given that the arguments to macros are passed to the macro
> without being evaluated, we can write:
>
> (defpackage "P"
> (:use "CL"))
>
> For lisp, "P" and (:use "CL") are just a string and a list to be given
> as parameter to the macro DEFPACKAGE, and it's up to the macro to see
> what it will use to build an expression to be compiled and evaluated at
> run-time.
>
>
> But we cannot write:
>
> (make-package "P" (:use "CL"))
>
> because MAKE-PACKAGE being a function, lisp will evaluate at run-time
> the arguments "P" and (:use "CL") to obtain values to be passed as
> parameter to the function MAKE-PACKAGE.
>
> "P" is a literal string, so it will evaluate to itself, no problem. But
> in (:use "CL"), :USE is not a macro or a function, therefore it's an
> invalid function call. The compiler will warn, and you will get a
> run-time error for undefined function :USE. Furthermore, now the
> parameters of the function MAKE-PACKAGE are valid, since MAKE-PACKAGE
> takes there &key parameters, and it expected a value for the given
> (invalid) key.
>
> This is why you got your original error: you didn't consider that
> MAKE-PACKAGE was a function and that you needed to pass it the correct
> expressions to be evaluated as arguments.
>
>
> http://www.lispworks.com/documentation/lw50/CLHS/Body/m_...
> http://www.lispworks.com/documentation/lw50/CLHS/Body/f_...
> http://www.lispworks.com/documentation/lw50/CLHS/Body/...
>
> DEFPACKAGE and MAKE-PACKAGE are operators.
>
> --
> __Pascal Bourguignon__ http://www.informat...
> "The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment." -- Carl Bass CEO Autodesk

Clear now. Very appreciate.

Pascal J. Bourguignon

7/21/2015 7:08:00 AM

0

james <dinglei2008@gmail.com> writes:

> Agree. Just curious why cl still provide make-package since defpackage
> could finish all the jobs.

DEFPACKAGE is implemented using MAKE-PACKAGE (and other package
functions).

Also, if you want to create packages at run-time, it will be easier to
do so with a function than with a macro.

Remember: the arguments to a macro are not evaluated, therefore they are
fixed at compilation time.


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

james

7/21/2015 8:32:00 AM

0

On Tuesday, July 21, 2015 at 3:07:59 PM UTC+8, informatimago wrote:
> james <dinglei2008@gmail.com> writes:
>
> > Agree. Just curious why cl still provide make-package since defpackage
> > could finish all the jobs.
>
> DEFPACKAGE is implemented using MAKE-PACKAGE (and other package
> functions).
>
> Also, if you want to create packages at run-time, it will be easier to
> do so with a function than with a macro.
>
> Remember: the arguments to a macro are not evaluated, therefore they are
> fixed at compilation time.
>
>
> --
> __Pascal Bourguignon__ http://www.informat...
> "The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment." -- Carl Bass CEO Autodesk

Make sense, got deeper understand the diff between function and macro for a new lisper.

Kaz Kylheku

7/21/2015 1:46:00 PM

0

On 2015-07-21, james <dinglei2008@gmail.com> wrote:
> Hi experters,
> I meet a problem when I try to created a new package in the packae TEST.
> I don't know why i could use :use in packate cl-user but can't in TEST.
> Aslo, Is there any method to know which package a symbol belong?
>
> TEST> (make-package :ja.r (:use :cl))
>
> The function :USE is undefined.

Note that make-package is a function, not a macro. This means that
its arguments are treated as forms (expressions which are evaluated).

The form (:use :cl) is therefore also a function call.

The message is telling us that the :use keyword symbol has no function binding.

(In fact, keyword symbols *may* have function bindings!)

The fix is to study how to use make-package, instead of expecting it to
understand defpackage macro syntax.

Hint: a call to make-package cannot do everything that defpackage can;
defpackage is a syntactic interface to Lisp's broader package API which
includes functions like make-package, use-package, and intern.
make-package does, however, have a :use keyword argument to specify other
packages to be used, as a list of designators.

Hint: try (macroexpand '(defpackage :ja.r (:use :cl))) to see what your
Lisp implementation actually does under the hood.