• make-package without :use

    From Phil Roc@21:1/5 to All on Mon May 16 22:37:06 2022
    Good morning,
    If I run the following code, I get error messaging stating that
    that defun, format, ... are not declared in package BOB, ...

    ----------
    (make-package :bob)
    ;;:use '("CL"))
    (make-package :jane)
    ;;:use '("CL"))

    (in-package "BOB")
    (defun foo () (format t "In ~A's, running foo...~%" *package*))
    (foo)
    (in-package "JANE")
    (defun foo () (format t "In ~A's, running foo...~%" *package*))
    (foo)
    -----------

    This version of the code doesn't work either:

    ----------
    (make-package :bob)
    ;;:use '("CL"))
    (make-package :jane)
    ;;:use '("CL"))

    (in-package "BOB")
    (defun foo () (format t "In ~A's, running foo...~%" *package*))
    (foo)
    (in-package "JANE")
    (defun foo () (format t "In ~A's, running foo...~%" *package*))
    (foo)
    -------------

    Are there any other solutions besides uncommenting (:use '("CL")')?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Phil Roc on Tue May 17 08:13:38 2022
    On 2022-05-17, Phil Roc <phiroc@free.fr> wrote:
    Are there any other solutions besides uncommenting (:use '("CL")')?

    The "use" mechanism creates a window from one package to another;
    symbols which are exported by the used package are visible in the
    using package. They are not actually present in the using package;
    it's only a visibility trick.

    The only alternative to visibility via use is to actually make
    the desired symbols present in your package by importing them
    individually. See the functions import and shadowing-import.

    --
    n
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Eller@21:1/5 to All on Tue May 17 10:12:46 2022
    Are there any other solutions besides uncommenting (:use '("CL")')?

    You could write CL:DEFUN instead of DEFUN. If you are in package BOB
    and the Lisp system reads DEFUN, then it creates a fresh symbol in the
    BOB package, i.e., BOB::DEFUN which is different from CL:DEFUN.

    With the :USE CL argument the system first searches in the CL package
    for names before deciding to create fresh symbols.

    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Zyni=20Mo=C3=AB?=@21:1/5 to Phil Roc on Tue May 17 08:50:09 2022
    Phil Roc <phiroc@free.fr> wrote:
    Good morning,
    If I run the following code, I get error messaging stating that
    that defun, format, ... are not declared in package BOB, ...
    [...]

    Are there any other solutions besides uncommenting (:use '("CL")')?


    To be precise you may or may not get such errors since the default for :use
    is implementation-defined: your code might 'work' on some implementations
    but not on others.

    You could make it 'work' on more by:

    (make-package :foo)
    (use-package '(:cl) ':foo)

    This still leaves the package use list only partly specified (it may
    include other packages than the CL package). If you want it
    fully-specified you must specify it.

    However none of this will make your code actually work: make-package & use-package are functions so the packages you are making will not exist at compile time so your code cannot be compiled. That is why you should use defpackage.

    --
    the small snake

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)