<div dir="ltr"><div><div>I'm having trouble creating identifiers that are unique with respect to free-identifier=? and that survive marshaling to compiled code. The normal source of fresh identifiers, generate-temporaries, only guarantees they are unique with respect to bound-identifier=?. The obvious alternative, gensym, does not properly survive marshaling -- copies saved in different .zo files load as distinct identifiers. I've tried a few alternative methods, none more successful than either of these.<br>
<br>Below, there are a few short files that show the difficulties and can be used to test other methods. The first, fresh.rkt, contains the procedure used to create fresh identifiers. The file original.rkt creates a fresh identifier at compile time. The file identical.rkt copies the identifier from original.rkt using quote-syntax. The file different.rkt creates another fresh identifier at compile time. The file check.rkt checks that the identifiers from original.rkt and identical.rkt are free-identifier=? to each other, and that the identifiers from original.rkt and different.rkt are not free-identifier=? to each other. To run a test, first update fresh.rkt to use the appropriate method for creating identifiers, then run "raco make check.rkt". Some of the methods work when simply running "racket check.rkt", but "raco make" marshals the identifiers to .zo files and exposes more problems.<br>
<br></div><div>Can anyone suggest an implementation that would work here?<br></div><br></div>;;;;; fresh.rkt<br><div>#lang racket<br>(begin-for-syntax<br> (require racket/syntax)<br> (define (fresh)<br></div><div> ;; does not guarantee free-identifier=?<br>
</div><div> #;(generate-temporary)<br></div><div> ;; does not survive marshaling<br></div><div> #;(gensym)<br></div><div> ;; also does not survive marshaling<br></div><div> (begin<br> (define id0 (datum->syntax #false 'fresh))<br>
(define ctx (syntax-local-make-definition-context))<br> (syntax-local-bind-syntaxes (list id0) #false ctx)<br> (internal-definition-context-seal ctx)<br> (internal-definition-context-apply ctx id0)))<br>
(provide fresh))<br><br></div><div>;;;;; original.rkt<br>#lang racket<br>(require "fresh.rkt")<br>(define-syntax (macro stx)<br> (with-syntax {[name (fresh)]}<br> #'(begin-for-syntax<br> (define original (quote-syntax name))<br>
(provide original))))<br>(macro)<br><br></div><div>;;;;; identical.rkt<br>#lang racket<br>(require "original.rkt")<br>(define-syntax (macro stx)<br> (with-syntax {[orig original]}<br> #'(begin-for-syntax<br>
(define identical (quote-syntax orig))<br> (provide identical))))<br>(macro)<br><br></div><div>;;;;; different.rkt<br>#lang racket<br>(require "fresh.rkt")<br>(define-syntax (macro stx)<br> (with-syntax {[name (fresh)]}<br>
#'(begin-for-syntax<br> (define different (quote-syntax name))<br> (provide different))))<br>(macro)<br><br></div><div>;;;;; check.rkt<br>#lang racket<br>(require "fresh.rkt" "original.rkt" "identical.rkt" "different.rkt")<br>
(begin-for-syntax<br> (unless (free-identifier=? original identical)<br> (error 'fresh "~v != ~v\n" original identical))<br> (when (free-identifier=? original different)<br> (error 'fresh "~v == ~v\n" original different)))<br>
<br>--<br clear="all"><div>Carl Eastlund</div>
</div></div>