Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

Suggests replacing make-immutable-hash with quasiquoted pairs with the simpler hash constructor when all keys are statically known.

Changes

  • Added make-immutable-hash-with-quasiquote-to-hash rule to hash-shortcuts.rkt
  • Matches pattern (make-immutable-hash ((key . ,value) ...))` where keys are literal identifiers
  • Transforms to (hash 'key value ...) for improved readability
  • Added 6 test cases covering positive and negative scenarios

Example

;; Before
(make-immutable-hash
 `((body . ,body)
   (event . ,event)
   (comments . ,(map github-review-comment-jsexpr comments))))

;; After
(hash 'body body 'event event 'comments (map github-review-comment-jsexpr comments))

The rule only applies when keys are quoted symbols. Variable keys like (,k . ,v) are correctly excluded.

Original prompt

This section details on the original issue you should resolve

<issue_title>Suggest using hash instead of make-immutable-hash with quasiquoting</issue_title>
<issue_description>Example:

(make-immutable-hash
 `((body . ,body)
   (event . ,event)
   (comments . ,(map github-review-comment-jsexpr comments))))

If the keys are statically known, hash is simpler.

The same goes for quasiquoted #hash() literals, but those are trickier.</issue_description>

Comments on the Issue (you are @copilot in this section)

@jackfirth I'd rather read the `(hash 'body body 'event event 'comments (map ...))` expression. Fewer parens, fewer special characters, it's shorter, and it doesn't invite confusion about why this doesn't work:
(define x 42)
#hash([foo x]) ;; why am I not getting `(hash 'foo 42)`???

People ask questions in the racket discord about that kind of quotation issue all the time. I'd rather just avoid it entirely.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Suggest using hash instead of make-immutable-hash Add refactoring rule to suggest hash over make-immutable-hash with quasiquoting Dec 12, 2025
Copilot AI requested a review from jackfirth December 12, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest using hash instead of make-immutable-hash with quasiquoting

2 participants