Fixed define-pvars (was not defining the unique-at-runtime variables)

This commit is contained in:
Georges Dupéron 2017-01-27 22:04:37 +01:00
parent 81a05e6ff3
commit 0029c1acbf
2 changed files with 10 additions and 7 deletions

View File

@ -88,7 +88,7 @@
(λ (lower upper) (λ (lower upper)
(if (= (- upper lower) 1) (if (= (- upper lower) 1)
(if (try-nth-current-pvars upper) (if (try-nth-current-pvars upper)
upper upper ;; Technically not possible, still included for safety.
lower) lower)
(let ([mid (/ (+ upper lower) 2)]) (let ([mid (/ (+ upper lower) 2)])
(if (try-nth-current-pvars mid) (if (try-nth-current-pvars mid)
@ -186,6 +186,9 @@
(nth-current-pvars-id (+ old-pvars-index 1)))]) (nth-current-pvars-id (+ old-pvars-index 1)))])
(datum->syntax (datum->syntax
(quote-syntax here) (quote-syntax here)
`(define-syntaxes (,binding) `(begin
(define-values (,@unique-at-runtime)
(values ,@(map (λ (pvar) `(gensym (quote ,pvar))) pvars)))
(define-syntaxes (,binding)
(list* ,@stxquoted-pvars+unique (list* ,@stxquoted-pvars+unique
(try-nth-current-pvars ,old-pvars-index)))))))) (try-nth-current-pvars ,old-pvars-index)))))))))

View File

@ -26,10 +26,10 @@ and the @racket[syntax-case] family. These patched versions track which syntax
pattern variables are bound. This allows some libraries to change the way pattern variables are bound. This allows some libraries to change the way
syntax pattern variables work. syntax pattern variables work.
For example, @racketmodname[subtemplate] automatically derives temporary For example, @tt{subtemplate} automatically derives temporary
identifiers when a template contains @racket[yᵢ …], and @racket[xᵢ] is a identifiers when a template contains @racket[yᵢ …], and @racket[xᵢ] is a
pattern variable. To know from which @racket[varᵢ] the @racket[yᵢ …] pattern variable. To know from which @racket[varᵢ] the @racket[yᵢ …]
identifiers must be derived, @racketmodname[subtemplate] needs to know which identifiers must be derived, @tt{subtemplate} needs to know which
syntax pattern variables are within scope. syntax pattern variables are within scope.
@section{Tracking currently-bound pattern variables with @racket[syntax-parse]} @section{Tracking currently-bound pattern variables with @racket[syntax-parse]}
@ -86,7 +86,7 @@ track which syntax or datum pattern variables are bound.
This can be used to associate run-time data with each syntax pattern This can be used to associate run-time data with each syntax pattern
variable, via a weak hash table created with @racket[make-weak-hasheq]. For variable, via a weak hash table created with @racket[make-weak-hasheq]. For
example, the @racketmodname[subtemplate] library implicitly derives example, the @tt{subtemplate} library implicitly derives
identifiers (similarly to @racket[generate-temporaries]) for uses of identifiers (similarly to @racket[generate-temporaries]) for uses of
@racket[yᵢ ...] from a @racket[xᵢ] pattern variable bearing the same @racket[yᵢ ...] from a @racket[xᵢ] pattern variable bearing the same
subscript. The generated identifiers are associated with @racket[xᵢ] via this subscript. The generated identifiers are associated with @racket[xᵢ] via this