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

rename () pattern to (nil) in syntax-case #169

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

gelisam
Copy link
Owner

@gelisam gelisam commented Oct 9, 2022

Renames the () pattern to (nil) in syntax-case, in order to be consistent with the (cons hd tl) pattern.

Before:

(syntax-case args
  [() ...]
  [(cons first-arg more-args))

After:

(syntax-case args
  [(nil) ...]
  [(cons first-arg more-args))

@gelisam
Copy link
Owner Author

gelisam commented Oct 9, 2022

This PR builds on top of #161, and therefore the diff will be needlessly large until #161 is merged. If you want to review before that happens, please start at d6e411d.

@gelisam gelisam mentioned this pull request Oct 9, 2022
@gelisam
Copy link
Owner Author

gelisam commented Oct 9, 2022

One slightly confusing consequence is that nil in a pattern position can mean the syntax object '() or the empty list (nil), which have different types in Klister. See e.g. this function which converts a syntax object to a list:

[(nil) (nil)]

There is no clash because technically, it is only the nil of type (List A) which is in scope, the nil of type Syntax is not a pattern-macro. Instead, syntax-case checks whether the pattern is an identifier named "nil". This means that it is possible to rename the nil of type (List A) to empty-list, but it is not possible to rename the nil of type Syntax to empty-syntax.

The issue will either disappear or become problematic in #101. It might disappear because syntax-case will no longer be a builtin, it will be a regular macro, and so it will be much easier for that syntax-case implementation to do the right thing and make nil a renameable pattern macro. It might become problematic because at that point, it will not be possible for prelude.kl to export both nil definitions with the same name.

In order to avoid this problem, maybe this PR should pick a different name, like empty or nil-syntax? While we're at it, should we also rename cons to cons-syntax? cons doesn't conflict with the (List A) constructor, because the (List A) constructor is called ::. But as a reminder, the purpose of this PR is to make the syntax-case patterns more consistent, by using nil and cons instead of () and cons. So using nil-syntax and cons would again make the pattern names inconsistent.

@gelisam gelisam closed this Oct 9, 2022
@gelisam
Copy link
Owner Author

gelisam commented Oct 9, 2022

We already have empty-list-syntax and cons-list-syntax, so I guess it should be empty.

@gelisam
Copy link
Owner Author

gelisam commented Oct 9, 2022

Looks like I accidentally pressed the close button. Reopening.

@gelisam gelisam reopened this Oct 9, 2022
@gelisam
Copy link
Owner Author

gelisam commented Oct 9, 2022

Thinking about this more, I think empty-list-syntax and syntax-case should be deprecated in favor of (close-syntax (list-contents (nil)) stx) and

(match (open-syntax args)
  [(list-contents (nil)) ...]
  [(list-contents (:: first-arg more-args)) ...])

This would be more consistent, but also more verbose, than (empty-list-syntax stx) and

(syntax-case args
  [() ...]
  [(cons first-arg more-args) ...])

The extra verbosity should be addressed separately, via the existing quasiquote.kl and #81. These provide much better syntax than the current empty-list-syntax and syntax-case builtins, whose syntax was chosen to be convenient to the implementation rather than convenient to the user.

@david-christiansen
Copy link
Collaborator

This seems like a reasonable minor cosmetic change.

@gelisam gelisam added the CodeRabbit summons the AI reviewing bot label Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CodeRabbit summons the AI reviewing bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants