Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions default-recommendations/hash-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
resyntax/default-recommendations/private/lambda-by-any-name
resyntax/default-recommendations/private/literal-constant
resyntax/default-recommendations/private/pure-expression
resyntax/default-recommendations/private/self-quoting-literal
resyntax/default-recommendations/private/syntax-equivalence
resyntax/default-recommendations/private/syntax-identifier-sets
resyntax/private/syntax-neighbors
Expand Down Expand Up @@ -143,10 +144,6 @@
#:original-splice (orig-definition orig-hash-set!)))))


(define-syntax-class self-quoting-literal
(pattern (~or _:boolean _:character _:number _:regexp _:byte-regexp _:string _:bytes)))


;; A datum within a quasiquoted expression that can be lifted directly into expression position,
;; either because it's self-quoting or because it's a symbol that can be wrapped in a quote. Quoted
;; datums like (quote x) are excluded because quasiquote treats them as plain data: the quasiquoted
Expand Down
21 changes: 21 additions & 0 deletions default-recommendations/list-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ no-change-test: "quasiquotation with only constants not refactorable to list"
- `(1 2 3)


no-change-test: "quasiquotation with quoted datums not refactorable to list"
------------------------------
(define (f y)
`(1 ,y 'x))
------------------------------


no-change-test: "quasiquotation with symbols not refactorable to list"
------------------------------
(define (f y)
`(1 ,y x))
------------------------------


no-change-test: "quasiquotation with nested lists not refactorable to list"
------------------------------
(define (f y)
`(1 ,y (2 3)))
------------------------------


test: "unnecessary splicing quasiquotation refactorable to append"
------------------------------
(define (f xs ys zs)
Expand Down
11 changes: 7 additions & 4 deletions default-recommendations/list-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
resyntax/base
resyntax/default-recommendations/analyzers/ignored-result-values
resyntax/default-recommendations/private/lambda-by-any-name
resyntax/default-recommendations/private/literal-constant
resyntax/default-recommendations/private/self-quoting-literal
resyntax/default-recommendations/private/syntax-identifier-sets
syntax/parse)

Expand Down Expand Up @@ -106,15 +106,18 @@
(sort lst less-than #:key f1))


;; Elements that aren't unquoted must be self-quoting to lift them out of the quasiquote unchanged.
;; Quoted datums like (quote x) are quasiquoted as plain data, so `(1 'x) is the list (1 (quote x)),
;; not the list (1 x) that a lifted 'x expression would produce.
(define-syntax-class unquoted
#:attributes (expr literal?)
#:literals (unquote)
(pattern expr:literal-constant #:attr literal? #true)
(pattern expr:self-quoting-literal #:attr literal? #true)
(pattern (unquote expr) #:attr literal? #false))


(define-refactoring-rule quasiquote-to-list
#:description "This quasiquotation is equialent to a simple `list` call."
#:description "This quasiquotation is equivalent to a simple `list` call."
#:literals (quasiquote)
(quasiquote (arg:unquoted ...))
#:when (for/or ([literal? (in-list (attribute arg.literal?))])
Expand All @@ -123,7 +126,7 @@


(define-refactoring-rule quasiquote-to-append
#:description "This quasiquotation is equialent to calling `append`."
#:description "This quasiquotation is equivalent to calling `append`."
#:literals (quasiquote unquote-splicing)
(quasiquote ((unquote-splicing arg) ...))
(append arg ...))
Expand Down
18 changes: 18 additions & 0 deletions default-recommendations/private/self-quoting-literal.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#lang racket/base


(provide self-quoting-literal)


(require syntax/parse)


;@----------------------------------------------------------------------------------------------------


;; A datum that evaluates to itself, so it means the same thing in expression position as it does
;; within quoted or quasiquoted data. Symbols and quoted datums like (quote x) are notably not
;; self-quoting: a symbol in expression position is a variable reference, and within quasiquoted
;; data (quote x) is a two-element list rather than the value x.
(define-syntax-class self-quoting-literal
(pattern (~or _:boolean _:character _:number _:regexp _:byte-regexp _:string _:bytes)))
Loading