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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:23:12+00:00 2026-06-05T00:23:12+00:00

A new syntax object can be constructed by both syntax/loc and syntax (also written

  • 0

A new syntax object can be constructed by both syntax/loc and syntax (also written #').

When should I use syntax/loc?

  • 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-05T00:23:13+00:00Added an answer on June 5, 2026 at 12:23 am

    Use #' (i.e. syntax) when you are not constructing a new syntax object, as when you’re just referencing a pattern variable bound with syntax-case or with-syntax.

    Use #' for temporary syntax objects as in (syntax->list #'(id ...)).

    Use #' for syntax objects representing forms that you know won’t have syntax errors in them, or where syntax errors in them are the fault of your macro implementation, not the use of your macro.

    Use syntax/loc when you construct expressions that potentially can contain syntax-errors due to an incorrect usage of your macro.

    Let’s consider a concrete example:

    The form display-let should work exactly like normal let, except that it displays the values of the bindings before it evaluates the body.

    Here is a first implementation:

    (define-syntax (display-let-1 stx)
      (syntax-case stx ()
        [(_ ([id expr] ...) body ...)
         #'((lambda (id ...) 
              (displayln (format "~a is bound to ~a" 'id id)) ...
              body ...)
            expr ...)]))
    

    Here is an example of a correct use of the macro:

    > (display-let-1 ([x 1] [y 2]) (+ x y))
    x is bound to 1
    y is bound to 2
    3
    

    Now let us see what happens when the macro is used incorrectly:

    > (display-let-1 ())
    lambda: bad syntax in: (lambda ())
    

    This usage is incorrect, since a use of let must always have a non-empty body. Besides printing the error message, DrRacket colors this code red:

    (lambda (id ...) 
      (displayln (format "~a is bound to ~a" 'id id)) ...
      body ...)
    

    Although it is correct that the lambda expression constructed by the macro is incorrect, (lambda ()) is not legal, it is not due to an error in the macro, but due to an incorrect use of the macro.

    To redirect the blame surround the constructed lambda expression with syntax/loc and use the first argument of syntax/loc as place to color red.

    (define-syntax (display-let-2 stx)
      (syntax-case stx ()
        [(display-let ([id expr] ...) body ...)
         #`(#,(syntax/loc stx (lambda (id ...) body ...)) expr ...)]))
    
    > (display-let-2 ())
    display-let-2: bad syntax in: (display-let-2 ())
    

    This time around the (display-let-2 ()) entered in the repl is colored red, and the error message mentioned display-let-2 instead of lambda.

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

Sidebar

Related Questions

I use the rails 3.0.0.beta Is there any new syntax to write RJS, here
I'm brand new to Coffeescript and struggling on the syntax. Can anyone help me
When creating a new type using the object initialiser syntax, Visual Studio automatically moves
In C#, I can initialize a list using the following syntax. List<int> intList= new
There is a weird issue with Ruby 1.9.2's new hash syntax. How can I
I have a question regarding placement new syntax in C++. Are the following two
Ruby 1.9 has a few new syntax elements, such as the {key: value} hash
In C++11, we have that new syntax for initializing classes which gives us a
I'm using the new AAA syntax and wanted to know the syntax to do
New to LINQ.. I am curious as to the syntax to do the following

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.