Three ways to make-package

16 views
Skip to first unread message

Phil Roc

unread,
May 16, 2022, 8:28:00 AMMay 16
to
Hello,
the (make-package ...) form tolerates three syntaxes:

(make-package "bob")
(make-package 'bob)
(make-package :bob)

but not
(make-package bob)

[although (defpackage bob) works]

Why is that?

Thanks.

Madhu

unread,
May 16, 2022, 8:54:21 AMMay 16
to

* Phil Roc <7b5490b3-f133-416c...@googlegroups.com> :
Wrote on Mon, 16 May 2022 05:27:51 -0700 (PDT):

>
> (make-package "bob")
> (make-package 'bob)
> (make-package :bob)
>
> but not
> (make-package bob)
>
> [although (defpackage bob) works]
>
> Why is that?

make-package is a function. functions always evaluate their arguments.
in the form (make-package bob) BOB is a symbol, and lisp tries to
evaluate it. the symbol BOB probably does not have a binding (either
lexically or globally) and so it fails

this would have worked:
(make-package 'bob)

or this:
(defparameter *bob* "BOB") ; don't use 'bob as it will become global
(make-package *bob*)

defpackage is a macro, and macros do not evaluate their args. the
argument is a string designator for a package name. the parameter BOB is
a strin designator for the string "BOB" so with (defpackage bob ...) you
are really reaching for (defpackage "BOB"). You should macroexpand the
defpackage form to see what it expands to.
Luckily Since neither defpackage[1] or make-package[2] are special
forms[3] your question has avoided a third complication.


[1] defpackage http://www.lispworks.com/documentation/lw71/CLHS/Body/m_defpkg.htm
[2] make-package http://www.lispworks.com/documentation/lw71/CLHS/Body/f_mk_pkg.htm
[3] special forms
http://www.lispworks.com/documentation/lw71/CLHS/Body/03_ababa.htm#clspecialops

Kaz Kylheku

unread,
May 16, 2022, 11:30:42 AMMay 16
to
On 2022-05-16, Phil Roc <phi...@free.fr> wrote:
> Hello,
> the (make-package ...) form tolerates three syntaxes:
>
> (make-package "bob")
> (make-package 'bob)
> (make-package :bob)
>
> but not
> (make-package bob)

Both defpackage and make-package take the package name in the
same format, as a "string designator" that can be a string or symbol.

Hint: this will work:

(let ((bob "bob"))
(make-package bob))

defpackage is a macro; make-package is a function.

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

Stefan Monnier

unread,
May 16, 2022, 11:54:53 AMMay 16
to
> make-package is a function. functions always evaluate their arguments.

I'd insist here that it's actually not the functions that evaluate their
arguments, but the general language semantics. By the time the function
is involved, the arguments have already been evaluated.


Stefan

Zyni Moë

unread,
May 16, 2022, 2:46:48 PMMay 16
to
Stefan Monnier <mon...@iro.umontreal.ca> wrote:

>
> I'd insist here that it's actually not the functions that evaluate their
> arguments, but the general language semantics. By the time the function
> is involved, the arguments have already been evaluated.
>

Is important point yes. In either normal order language or language with
horrible curse of FEXPRs this would not be true.


--
the small snake

Kaz Kylheku

unread,
May 16, 2022, 4:48:22 PMMay 16
to
In normal order it is still true, because it's still the evaluation
strategy which supplies the argument evaluation, not the function *per
se*; the function only refers to arguments, and somehow obtains the
values by doing so.

Zyni Moë

unread,
May 16, 2022, 7:35:01 PMMay 16
to
Kaz Kylheku <480-99...@kylheku.com> wrote:

>
> In normal order it is still true, because it's still the evaluation
> strategy which supplies the argument evaluation, not the function *per
> se*; the function only refers to arguments, and somehow obtains the
> values by doing so.

Yes you are right. Was thinking of normal order as like some explicit
force/delay thing but that is wrong: is really fexprs not normal order.

--
the small snake

Madhu

unread,
May 16, 2022, 9:19:49 PMMay 16
to

* Stefan Monnier <jwv4k1plbia.fsf-monnier+comp.lang.lisp @gnu.org> :
Wrote on Mon, 16 May 2022 11:54:43 -0400:
I'm not inclined to disagree. However there is scope for complicated
defaulting behaviour specified by way of &optional &key &aux - which can
be considered part of the function, and evaluation of these, in order
(heh heh) can be seen as part of evauation of the function.

(on that note there are corner cases with emacs' interactive that i
haven't wrapped my mind around yet)



Reply all
Reply to author
Forward
0 new messages