Bir paketteki bir işlev nasıl "tanımlanır"?

Aug 19 2020

Üzgünüm, bu çok yeni bir Common Lisp sorusu.

Yaygın lisp ve paket sistemi öğreniyorum.

"The Complete Idiot's Guide to Common Lisp Packages" ile başladım. http://cl-cookbook.sourceforge.net/packages.html

Bölüm 1'de yazar foopakette bir işlev tanımladı:bob

? (make-package :bob)
#<Package "BOB">
? (make-package :jane)
#<Package "JANE">
? (in-package bob)
#<Package "BOB">
? (defun foo () "This is Bob's foo")
FOO

Bu kodu REPL'imde satır satır test ettim, ancak başarısız oldum:

; SLIME 2.26
CL-USER> (make-package :bob)
#<PACKAGE "BOB">
CL-USER> (make-package :jane)
#<PACKAGE "JANE">
CL-USER> (in-package bob)
#<COMMON-LISP:PACKAGE "BOB">
BOB> (defun foo () "This is Bob's foo")
; in: DEFUN FOO
;     (BOB::DEFUN BOB::FOO NIL "This is Bob's foo")
; 
; caught COMMON-LISP:STYLE-WARNING:
;   undefined function: BOB::DEFUN
; 
; caught COMMON-LISP:WARNING:
;   undefined variable: BOB::FOO
; 
; compilation unit finished
;   Undefined function:
;     DEFUN
;   Undefined variable:
;     FOO
;   caught 1 WARNING condition
;   caught 1 STYLE-WARNING condition

Ve bana şunu söyledi:

The variable FOO is unbound.
   [Condition of type COMMON-LISP:UNBOUND-VARIABLE]

Sorun ne?

Bu problem nasıl çözülür ve çalıştırılır?

Çok teşekkürler.

Not: Ortamım SBCL + quicklisp + slime.

Yanıtlar

5 RainerJoswig Aug 19 2020 at 03:04

Lisp'e hangi paketi kullanacağını söylemelisin . Standart Common Lisp'de hangi paketlerin kullanılacağı belirtilmemiştir . SBCL hiçbirini kullanmaz . CL paketinin sembollerinin mevcut olmasını istiyorsanız, bu paketi açıkça kullanmanız gerekir .

Paket JANE

* (make-package :jane)
#<PACKAGE "JANE">
* (describe *)
#<PACKAGE "JANE">
  [package]


0 internal symbols.

BOB paketi için CL paketini kullanıyoruz:

* (make-package "BOB" :use '("CL"))
#<PACKAGE "BOB">
* (describe *)
#<PACKAGE "BOB">
  [package]


Use-list: COMMON-LISP
0 internal symbols.


* (find-symbol "DEFUN" "BOB")
DEFUN
:INHERITED

Sembol DEFUN, BOB paketinde mevcuttur.

* (find-symbol "DEFUN" "JANE")
NIL
NIL

Sembol DEFUNolduğunu DEĞİL paket JANE mevcuttur.