<commit_before>* Local Package Aliases
  Allows to define inside of a package aliases to refer other packages.
  Provides a reader macro =$= to use aliases.
  Portable.
  
#+BEGIN_SRC lisp
  (defpackage com.my-company.some-library
    (:use cl)
    (:export :func))

  (in-package :com.my-company.some-library)

  (defun func () "hello")



  (defpackage some-application (:use cl))
  (in-package :some-application)
  (local-package-aliases:set :com.my-company.some-library :lib :some.other.library :olib)

  (read-from-string "$lib:func")
  ;; => COM.MY-COMPANY.SOME-LIBRARY:FUNC

  ($lib:func)
  ;; => "hello"

  ;; The aliases are not global, they are scoped only to the package
  ;; where they are defined:

  (in-package :cl-user)
  (read-from-string "$lib:func")
  ;; => ERROR There is no package named "$LIB" .

  ;; The $ reader macro is non-terminating,
  ;; therefore it is only activated when $
  ;; is on the beginning of a token.
  ;; $ in the middle of a token has no special
  ;; effect.
  (in-package :some-application)

  (read-from-string "just-a-$-symbol")
  ;; => JUST-A-$-SYMBOL

  ;; The $ designates alias reference only if the
  ;; current package has aliases defined. If there
  ;; is no aliases in the current package, then
  ;; $ is interpreted as usually:

  (local-package-aliases:set) ;; installs empty aliases table
  (read-from-string "$-a-sybmol")
  ;; => $-A-SYMBOL

  (in-package :cl-user)
  (read-from-string "$-a-sybmol")
  ;; => $-A-SYMBOL

  ;; Therefore it is safe to enable $ macro
  ;; globally, for example from Lisp init file,
  ;; without affecting the code using $ for other
  ;; purposes.
#+END_SRC

To enable the $ macro in your lisp session (may be put into
the lisp initialization file):
#+BEGIN_SRC common-lisp
  (local-package-aliases:set-aliasing-reader *readtable*)
#+END_SRC

Another macro character than =$= may be used. 
See the docstring for =local-package-aliases:set-aliasing-reader=
for parameters description.

To return to the standard syntax:
#+BEGIN_SRC common-lisp
  (set-syntax-from-char #\$ #\$ *readtable* (copy-readtable nil))
#+END_SRC

To make the $ macro enabled when your ASDF system
is compiled, use the =:acound-compile= argument:

#+BEGIN_SRC common-lisp
;; (asdf:defsystem #:some-application
;;   :depends-on (#:local-package-aliases
;;                #:com.my-company.some-library)
;;   :around-compile "local-package-aliases:call-with-aliasing-readtable"
;;   :components ((:file "some-application")))
#+END_SRC


* Other Package Aliasing Approaches
  Here is some information, solutions and ideas I encountered recently
  related to package aliases.
  
  The solutions vary in:
  - whether the aliases only honored by reader, or they also
    affect functions like =cl:find-package=, =cl:find-symbol=
  - is the solution portable common lisp or it relies on patches
    or language extensions<commit_msg>Some work on local-package-aliases<commit_after>* Local Package Aliases
  Allows to define inside of a package aliases to refer other packages.
  Provides a reader macro =$= to use aliases.
  Portable.
  
#+BEGIN_SRC lisp
  (defpackage com.my-company.some-library
    (:use cl)
    (:export :func))

  (in-package :com.my-company.some-library)

  (defun func () "hello")



  (defpackage some-application (:use cl))
  (in-package :some-application)
  (local-package-aliases:set :com.my-company.some-library :lib :some.other.library :olib)

  (read-from-string "$lib:func")
  ;; => COM.MY-COMPANY.SOME-LIBRARY:FUNC

  ($lib:func)
  ;; => "hello"

  ;; The aliases are not global, they are scoped only to the package
  ;; where they are defined:

  (in-package :cl-user)
  (read-from-string "$lib:func")
  ;; => ERROR There is no package named "$LIB" .

  ;; The $ reader macro is non-terminating,
  ;; therefore it is only activated when $
  ;; is on the beginning of a token.
  ;; $ in the middle of a token has no special
  ;; effect.
  (in-package :some-application)

  (read-from-string "just-a-$-symbol")
  ;; => JUST-A-$-SYMBOL

  ;; The $ designates alias reference only if the
  ;; current package has aliases defined. If there
  ;; is no aliases in the current package, then
  ;; $ is interpreted as usually:

  (local-package-aliases:set) ;; installs empty aliases table
  (read-from-string "$-a-sybmol")
  ;; => $-A-SYMBOL

  (in-package :cl-user)
  (read-from-string "$-a-sybmol")
  ;; => $-A-SYMBOL

  ;; Therefore it is safe to enable $ macro
  ;; globally, for example from Lisp init file,
  ;; without affecting the code using $ for other
  ;; purposes.
#+END_SRC

To enable the $ macro in your lisp session (may be put into
the lisp initialization file):
#+BEGIN_SRC common-lisp
  (local-package-aliases:set-aliasing-reader *readtable*)
#+END_SRC

Another macro character than =$= may be used. 
See the docstring for =local-package-aliases:set-aliasing-reader=
for parameters description.

To return to the standard syntax:
#+BEGIN_SRC common-lisp
  (set-syntax-from-char #\$ #\$ *readtable* (copy-readtable nil))
#+END_SRC

To make the $ macro enabled when your ASDF system
is compiled, use the =:acound-compile= argument:

#+BEGIN_SRC common-lisp
;    (asdf:defsystem #:some-application
;      :depends-on (#:local-package-aliases
;                   #:com.my-company.some-library)
;      :around-compile "local-package-aliases:call-with-aliasing-readtable"
;      :components ((:file "some-application")))
#+END_SRC


* Other Package Aliasing Approaches
  Here is some information, solutions and ideas I encountered recently
  related to package aliases.
  
  The solutions vary in:
  - whether the aliases only honored by reader, or they also
    affect functions like =cl:find-package=, =cl:find-symbol=
  - is the solution portable common lisp or it relies on patches
    or language extensions
{'fraction_non_alphanumeric': 0.12359937941734184, 'fraction_numerical': 0.0, 'mean_word_length': 3.615751789976134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2341470', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1825, 'n_words': 608}