LispCookbook / LispCookbook/cl-cookbook

Export tricks (like exporting all accessors of a class at once)

Open
#269 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.1k
Forks
158
Avg merge
6d 3h
Merged PRs (30d)
2

Description

There is a surprising among of tricks to know when it comes to exporting symbols in Common Lisp. I think they should be made more obvious in the "Package" chapter.

  • SLIME has C-c x to export the symbol at point, or even the class and all its accessors with slime-export-class. It puts the exports in the :export field of the defpackage.

  • Keeping exports in the defpackage has the drawback that they might run out of sync, for instance if the definition is rename or removed (then we export a symbol that points to nothing). This is an extra maintenance burden. A solution to this is to export at definition site:

(export 'foo)
(defun foo () ...)

This way if foo is rename or remove, the export won't be forgotten.

If typing foo twice really bugs you, you can use the cl-annot library.
Where it really shines is that it can export all class accessors for you, which is not doable automatically with (export...).
Example:

@export-accessors
(defclass foo ()
     ((bar :reader bar-of)
      (bax :writer bax-of)
      (baz :accessor baz-of)))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Package chapter and review how it currently explains exporting symbols. Incorporate the issue's examples covering SLIME, definition-site exports, and cl-annot's accessor export behavior; done means these export approaches and their maintenance trade-offs are clearly documented.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.