Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline documentation (slot-name initform "docstring") #2

Open
aartaka opened this issue Feb 6, 2023 · 5 comments
Open

Inline documentation (slot-name initform "docstring") #2

aartaka opened this issue Feb 6, 2023 · 5 comments

Comments

@aartaka
Copy link

aartaka commented Feb 6, 2023

I've been bringing this up here and there, but here's a PR.

I believe it would be an aesthetic and useful change allowing inline documentation in our custom syntax for class definitions, like

(class-star:define-class foo ()
  ((slot-a
    5 "Some number.")
   (slot-b :unbound "Initially unbound slot.")))

This is going to cut some lines of code for short slots and make long slots slightly easier to follow when used to.

But, obviously, it causes quite some trouble for slot parsing, which is already quite complex.

If we agree that this is something we want, I'm ready to prototype this thing with all the caution left in me :P

@Ambrevar
Copy link
Member

Ambrevar commented Feb 8, 2023

Agree it's a nice thing :)

I wonder if it's possible though. Take a slot that has the :reader initform.

(malignant-slot :reader "My docstring")

Kaboom! :p

@aartaka
Copy link
Author

aartaka commented Feb 8, 2023

Yes, but for such cases one's better off using a regular :initform/:documentation syntax because it's ambiguous. We can't provide any guarantees for such use :P

Other than that extreme corner-case, the thing is relatively doable with e.g. pattern matching.

@Ambrevar
Copy link
Member

Ambrevar commented Feb 8, 2023

Let's not introduce a library for just this, it's easy enough to check if the 3rd element is a string and the second is not a keyword.

I think the following check would work:

(and
  (oddp (length DEFINITION))
  (not (keywordp (nth 1 DEFINITION)))
  (stringp (nth 2 DEFINITION))

@Ambrevar
Copy link
Member

Ambrevar commented Feb 8, 2023

Alternatively, check that the second element is not in

(append '(:accessor :initarg :initform) *allowed-slot-definition-properties*)

@aartaka
Copy link
Author

aartaka commented Feb 8, 2023

Yes, fair.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants