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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:12:49+00:00 2026-05-14T20:12:49+00:00

I often find the following type of incremental definition useful: (define (foo) (display bar))

  • 0

I often find the following type of incremental definition useful:

(define (foo) (display "bar"))
(foo)
;prints bar
(define foo (let ((bar foo))
              (lambda ()
                (display "foo")
                (bar))))

(foo)
;prints foobar

How do I preform this type of incremental definition with macros?
I could not get let-syntax to provide the same functionality.

Currently I use plt scheme, but would like to see answers in different lisp implementations as well.

Edit:

Naively I would want to do the following:

(define-syntax foo
  (syntax-rules ()
    ((_) (display "bar"))))

(define-syntax foo
  (let-syntax ((old-foo (syntax-rules () ((_) (foo)))))
    (syntax-rules ()
      ((_) (begin
             (display "foo")
             (old-foo))))))

Translation of naive macros to working plt scheme macros:

(require-for-syntax scheme/base) 
(define-syntax foo
  (syntax-rules ()
    [(foo) (display "bar")]))
(define-syntax foo
  (let ([old (syntax-local-value #'foo)])
    (lambda (stx)
      #`(begin #,((syntax-rules ()
               [(_) (begin (display "foo"))]) stx)
             #,(old #'(_))))))
(foo)

If I am missing a better method let me know.

  • 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-14T20:12:49+00:00Added an answer on May 14, 2026 at 8:12 pm

    FWIW (and this is definitely not much, since this is pretty much an exercise in target practicing with your feet), here is how you would do this in PLT Scheme with only hygienic syntax-rules macros:

    (define-syntax foo
      (syntax-rules ()
        [(foo x) (list 'x '= x)]))
    (define-syntax foo
      (let ([old (syntax-local-value #'foo)])
        (compose (syntax-rules ()
                   [(_ x ...) (list 'begin x ... 'end)])
                 old)))
    (printf ">>> ~s\n" (foo (+ 1 2)))
    

    This will not work inside a module, only on the REPL — and that is a good thing. It is possible to do something similar in modules too, but if you’re going for that, you can just as well use procedural macros (aka syntax-case macros), with an identifier that is bound at the syntax level and `set!’-ing its value to extend it. Still not a great idea, and can still lead to eyes bleeding, but some people like to hurt themselves…

    (Oh, and BTW — even doing this is still completely unrelated to whether the macros in question are hygienic or not.)

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

Sidebar

Related Questions

I often find myself in the following situation. Say I was editing a file
Often I find myself doing the following: print Input text: input = gets.strip Is
I often find myself having to define two versions of a function in order
I often find myself with an Option[T] for some type T and wish to
I often* find myself in need of a data structure which has the following
I find myself often repeating the following pattern of operations. I usually go into
I often find myself in the following situation: The customer reports corrupt data in
I often find myself doing the following index-counter messiness in a foreach loop to
I often find myself doing something along the following lines in sql server 2005
I find the following scenario quite often: You have a string that you want

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.