External vs Internal Symbols in Common Lisp Package

我是研究僧i 提交于 2019-12-12 19:20:57

问题


What is the difference between them in the context of a Common Lisp package? I am reading through SLIME documentation and some commands mention that extensively.


回答1:


The author of a Common Lisp package can export a symbol for the user of the package. Then the symbol is an external symbol and you can access it with package-name:external-symbol-name.

Internal symbols are not meant for the user but can be accessed with package-name::symbol-name

More explanations are in Peter Seibel's book and Common Lisp the Language




回答2:


What is the syntax ? The symbols you export are external.

(in-package :cl-user)
(defpackage str
  (:use :cl)
  (:export
   :trim-left
   ))

(in-package :str)

;; exported: can be accessed with `str:trim-left`.
(defun trim-left (s)
  "Remove whitespaces at the beginning of s. "
  (string-left-trim *whitespaces* s))

;; forgot to export: can still access it with `str::trim-right`.
(defun trim-right (s)
  "Remove whitespaces at the end of s."
  (string-right-trim *whitespaces* s))


来源:https://stackoverflow.com/questions/47782593/external-vs-internal-symbols-in-common-lisp-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!