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 9132291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:17:18+00:00 2026-06-17T08:17:18+00:00

Given: (define-syntax (test stx) (syntax-case stx () [(_ body …) (with-syntax ([body0 (process-body #'(body

  • 0

Given:

(define-syntax (test stx)
  (syntax-case stx ()
    [(_ body ...)
     (with-syntax ([body0 (process-body #'(body ...))])
       #'body0)]))

How should I receive the pattern and the ellipses in the helper? I’m not even sure if wrapping the body … inside () is correct, but I’ve seen it around and it’s the only thing that doesn’t crash.

The process-body procedure ends up with syntax that has extra () wrapping it. I can try and break this apart, but I’m just wondering what the correct way to do this is.

process-body wraps the body pattern with some code before AND after. And, similar to define, I want to be able to provide the macro with multiple forms rather than all forms in one list. So, if given (form1) (form2), where form2 is the ellipses, process-body should (do-something) (form1) (form2) (do-something-else).

ie,

(define-for-syntax (process-body body-syntax)
  (with-syntax ([stx body-syntax])
    (syntax/loc body-syntax
      (λ (request)
         stx))))

Of course I have this working when I define the template in-line, and I suppose I could do that here, but sometimes the template becomes unwieldy and it’s nice to call a helper.

Thanks a lot.

As an edit to try dyoo’s first example, I’m providing the following:

#lang racket

(define-syntax (test2 stx)
  (syntax-case stx ()
    [(_ body ...)
     (with-syntax ([(body0 ...) (process-body2 #'(body ...))])
       #'(begin body0 ...))]))

(define-for-syntax (process-body2 bodies)
  (with-syntax ([(body ...) bodies])
    (syntax/loc bodies
      (λ (request)
         body ...))))

(test2 (print "hi"))

λ: bad syntax

  • 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-17T08:17:19+00:00Added an answer on June 17, 2026 at 8:17 am

    The left hand side of a with-syntax pattern can also have ellipses, so that the following is possible:

    (define-syntax (test stx)
      (syntax-case stx ()
        [(_ body ...)
         (with-syntax ([(body0 ...) (process-body #'(body ...))])
           #'(begin body0 ...))]))
    

    The basic idea is that if process-body returns the transformed body elements, we can then introduce them all together with a begin.


    Your process-body definition can also use with-syntax with ellipses too. So you can do something like this:

    (define-for-syntax (process-body bodies)
      (with-syntax ([(body ...) bodies])
        (syntax/loc bodies
          (λ (request)
             body ...))))
    

    If that’s the definition of process-body, we should amend test since the shape of the result from process-body is now a complete lambda expression, so we can just return its result directly:

    (define-syntax (test stx)
      (syntax-case stx ()
        [(_ body ...)
         (process-body (syntax/loc stx (body ...)))]))
    

    As a self-contained example:

    #lang racket
    
    (define-syntax (test stx)
      (syntax-case stx ()
        [(_ body ...)
         (process-body 
          (syntax/loc stx (body ...)))]))
    
    (define-for-syntax (process-body bodies)
      (with-syntax ([(body ...) bodies])
        (syntax/loc bodies
          (λ (request)
            (printf "before the body\n")
            body ...
            (printf "after the body\n")))))
    
    
    ;; Let's try it:    
    (define p 
      (test (displayln "hello") (displayln "world")))
    
    (p 'should-be-a-request)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been given the question: Define a predicate ordered/1, which checks if a list
Given that users must be able to define their own fields on an object,
Let's say I'm given a string, and I want to define a function with
Standardese: [class.ctor] 12.1/1 says A special declarator syntax is used to declare or define
Can a macro be written in Scheme (with define-syntax , for example) which will
Given EF entities defined as follows class Person { int PersonID; string Name; string
Possible Duplicate: How to access this attribute using jquery, given a div defined by
Given the following two defined routes: routes.MapRoute(name: CityCategoryPage, url: {city}-{state}/{categoryName}/__c/, defaults: new { controller
Can anyone tell or define more what is ancestor and give an example on
Given a function, I'd like to know whether it's a developer-defined function or a

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.