Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:28:06+00:00 2026-06-17T06:28:06+00:00

I’d like to inject special variables into a macro for compile time binding. So,

  • 0

I’d like to inject special variables into a macro for compile time binding.

So, for example, the following form:

(define-route (my/route)
  (some-proc @@request)
  (some-other-proc @@request))

should expand to:

(some-code)
...
(lambda (request)
  ...
  (some-proc request)
  (some-other-proc request))

where request is bound to the request in the generated code, at all the places specified by the caller.

I’m not sure how to best go about it. Is this a more common pattern that racket macros provide the ability to do, or do I have to do it manually?

If so, should I recursively loop through the body pattern, looking for any symbols matching ‘@@request and then replace them? I notice that syntax->list isn’t recursive in this way, ie

(syntax->list #'(printf "first: ~a\" (get-var (other-proc)))

is 3 syntax objects not 4, and the third syntax-obj is 2 more. So I assume I need to manually recur here, but maybe there is a better way to do this?

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:28:07+00:00Added an answer on June 17, 2026 at 6:28 am

    Perhaps using syntax-parameterize (and its variant, splicing-syntax-parameterize) should do the trick? It’s a standard tool when you want to have keyword-like things, and where the macro needs to rewire the keyword’s meaning based on the context.

    Here’s what it looks like:

    #lang racket/base
    
    (require racket/stxparam
             racket/splicing
             (for-syntax syntax/parse racket/base))
    
    (define-syntax-parameter @@request
      (lambda (stx)
        (raise-syntax-error #f "Use outside of a define-route" stx)))
    
    (define-syntax (define-route stx)
      (syntax-parse stx 
        [(_ (name:id) body:expr ...)
         (syntax/loc stx
           (begin
             (printf "blah blah blah\n")
    
             (define name
               (lambda (request)
                 (splicing-syntax-parameterize ([@@request
                                                 (make-rename-transformer #'request)])
                   body ...)))))]))
    
    ;; example
    (define (f r)
      (printf "f sees: ~s\n" r))
    
    (define-route (my/route)
      (f @@request))
    
    (my/route 42)
    

    The syntax-parameterization rewires uses of @@request in the lexical context of a define-route so that it refers back to the request that’s being bound by the lambda. If used outside the context of a define-route, it’ll try to raise a sensible error message.

    (You could do this the way you initially planned, to recursively walk though the structure of the syntax object and pick out the @@request elements. It’s just more work than you need to do, unless the requirements are really unusual.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.