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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:18:10+00:00 2026-05-13T23:18:10+00:00

I have written a few nearly identical functions, except for their names. For example:

  • 0

I have written a few nearly identical functions, except for their names. For example:

; x is name, such as function/paragraph/line/etc.
(defun my-x-function
 (interactive)
 (mark-x) (do-more-stuff) (modify-x))

Is there a way to automatically generate such functions? I have a feeling this is what macros do, but I am not sure how to use them. Any help, maybe including a small example would be great.

Thanks!

  • 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-13T23:18:10+00:00Added an answer on May 13, 2026 at 11:18 pm

    Yep, that’s exactly what macros do. Here’s a straightforward macro that builds functions according to the pattern you specified:

    (defmacro make-my-function (name)
      (list 'defun (intern (format "my-%s-function" name)) ()
            (list 'interactive)
            (list (intern (format "mark-%s" name)))
            (list 'do-more-stuff)
            (list (intern (format "modify-%s" name)))))
    

    You can copy this macro to a *scratch* buffer in Emacs and evaluate it, and then check that it works like this:

    (make-my-function x) ; type control-J here
    my-x-function ; <-- Emacs's output
    (symbol-function 'my-x-function) ; type control-J here
    (lambda nil (interactive) (mark-x) (do-more-stuff) (modify-x)) ; <-- Emacs's output
    

    More commonly one would use the backquote facility to write macros more concisely, but all macros essentially work in the same manner as the above example.

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

Sidebar

Related Questions

I have written a C library which consists in a few .h files and
I'm using NetBeans and GlassFish 3.0.1 to create an EJB3 application. I have written
I have written some javascript whereas if you click on some divs those expand
I have written a web service that returns some data as json. To display
I have written the following script below - I am not quite happy with
I have written a Perl XS wrapper for a C library consisting of about
Forgive me if this is in the wrong place, but I figured a few
I have an application where many unit tests use a real connection to an
I'm coming to the end of my first year of CS and I thought
I've got a rather tricky problem that I've been trying to solve for the

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.