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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:56:12+00:00 2026-05-20T07:56:12+00:00

about the define-match-expansion, there are rare materials and example codes to illustrate the concepts.

  • 0

about the define-match-expansion, there are rare materials and example codes to illustrate the concepts. I am having a hard time to “decode” what the documentation says:

(define-match-expander id proc-expr)
(define-match-expander id proc-expr proc-expr)

Binds id to a match expander.

The first proc-expr subexpression must
evaluate to a transformer that
produces a pat for match. Whenever id
appears as the beginning of a pattern,
this transformer is given, at
expansion time, a syntax object
corresponding to the entire pattern
(including id). The pattern is the
replaced with the result of the
transformer.

A transformer produced by a second
proc-expr subexpression is used when
id is used in an expression context.
Using the second proc-expr, id can be
given meaning both inside and outside
patterns.

Can anyone give some example codes to illustrate the two usages of the define-match-expander here?

  • 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-05-20T07:56:13+00:00Added an answer on May 20, 2026 at 7:56 am

    The idea behind match-expander is that you can extend the ‘match’ form to handle new pattern forms of your own design.

    So, here’s a (somewhat pointless) example that defines an "aba" match form that matches patterns of one thing followed by another thing followed by the first thing again (hence, "aba"):

    #lang racket
    
    (define-match-expander aba
      (lambda (stx)
        (syntax-case stx ()
          [(_ a b) #'(list a b a)])))
    
    (match '(3 4 3)
      [(aba x y) (printf "x = ~a, y = ~a" x y)])
    

    The second form allows you to add a separate expansion to be used outside of match patterns, like this:

    #lang racket
    
    (define-match-expander aba
      (lambda (stx)
        (syntax-case stx ()
          [(_ a b) #'(list a b a)]))
      (lambda (stx)
        #'(error "please don't use aba outside of patterns.")))
    
    (match '(3 4 3)
      [(aba x y) (printf "x = ~a, y = ~a\n" x y)])
    
    (aba x y)
    

    Caveat: whuffo the extra pair of parens around the pattern? Not sure, sorry.

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

Sidebar

Related Questions

I am about to define an interface in my application that plug-in writers can
With StatSVN it's possible to define information about user(s) in a configuration file. An
I'm wondering about instances when it makes sent to use #define and #if statements.
John Nunemaker recently blogged about the various ways to define class methods in Ruby,
First of all, let's define a few tables: Users table will store information about
I have a class called Path for which there are defined about 10 methods,
While there is plenty of documentation about XML document structure, there are very few
How can I go about storing a vb.net user defined object in a sql
I asked a question earlier about why left joins in Linq can't use defined
This is related to this question I asked earlier about syntax highlighting user-defined blocks

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.