scribble icon indicating copy to clipboard operation
scribble copied to clipboard

Declare deprecated aliases

Open jackfirth opened this issue 6 months ago • 6 comments

This will allow Resyntax to replace uses of these legacy forms with their modern names.

jackfirth avatar Jun 28 '25 20:06 jackfirth

I think this needs to be updated for a change to define-deprecated-alias, which now requires that racketblock is defined before schemeblock is defined as an alias, for example.

mflatt avatar Jun 30 '25 19:06 mflatt

Hmm. Is there a way for define-deprecated-alias to raise an error if the target is unbound in the surrounding module or definition context and not require the target be bound before the define-deprecated-alias form? That would be the friendliest API for users.

jackfirth avatar Jul 01 '25 20:07 jackfirth

You could use syntax-local-lift-module-end-declaration when expanding within a module (i.e., when syntax-transforming-module-expression? returns true).

mflatt avatar Jul 01 '25 22:07 mflatt

Is there any way to achieve the same thing in an internal definition context?

jackfirth avatar Jul 01 '25 23:07 jackfirth

Do you mean an internal definition context that's in a module? Using syntax-local-lift-module-end-declaration should do the right thing when lifting a reference that happens to be in a definition context, as long as that definition context is also in a module as illustrated below. But maybe I don't understand what you're after.

#lang racket

(define-syntax (check-later stx)
  (syntax-case stx ()
    [(_ id)
     (when (syntax-transforming-module-expression?)
       (syntax-local-lift-module-end-declaration #'(check-now id)))
     #'(void)]))

(define-syntax (check-now stx)
  (syntax-case stx ()
    [(_ id)
     (unless (identifier-binding #'id)
       (raise-syntax-error #f "not good" #'id))
     #'(void)]))

(let ([ok "ok"])
  (check-later ok))

(let ()
  (check-later ok)
  (define ok "ok")
  (void))

(let ()
  (define something-else 0)
  (check-later ok-too))

(define ok-too 10)

mflatt avatar Jul 02 '25 19:07 mflatt

I drafted racket/racket#5289 to clarify what I'd like to work. I think syntax-local-lift-module-end-declaration will work correctly for the test cases I wrote, but I haven't tried it yet.

jackfirth avatar Jul 03 '25 02:07 jackfirth